Commit 27c3c5ec authored by Roberto P. Rubio's avatar Roberto P. Rubio
Browse files

Confirms machine start if running machines limit reached (on actions tab)

parent 754c07bc
......@@ -96,6 +96,7 @@
})
);
};
$scope.action = function(machine, action) {
machine.action = false;
if ( action == 'restore' ) {
......@@ -220,13 +221,47 @@
return string;
};
$scope.action = function(target,action,machineId,params){
$scope.confirmingMachineStopOnNewMachineStartData = null;
$scope.confirmingMachineStopOnNewMachineStartDataCancelled = function() {
$scope.confirmingMachineStopOnNewMachineStartData = null;
};
$scope.confirmingMachineStopOnNewMachineStartDataDone = function() {
$scope.action($scope.confirmingMachineStopOnNewMachineStartData.target, $scope.confirmingMachineStopOnNewMachineStartData.action, $scope.confirmingMachineStopOnNewMachineStartData.machine, $scope.confirmingMachineStopOnNewMachineStartData.params, true);
$scope.confirmingMachineStopOnNewMachineStartData = null;
};
$scope.checkExecutionMachineLimits = function(target,action,machineId,params) {
$http.get('/execution_machines_limit')
.then(function(data) {
if ((data.data.cant_start_many) || (data.data.running_domains.indexOf(machineId) >= 0) || (data.data.start_limit > data.data.running_domains.length)) {
$scope.action(target, action, machineId, params, true);
}
else {
$scope.confirmingMachineStopOnNewMachineStartData = { target: target, action: action, machine: machineId, params: params };
}
}, function(data,status) {
console.error('Repos error', status, data);
window.location.reload();
});
};
$scope.action = function(target,action,machineId,params,confirmed){
if (((action === 'start') || (action === 'view')) && (! confirmed)) {
$scope.checkExecutionMachineLimits(target, action, machineId, params);
}
else if (action === 'view') {
window.location.assign('/machine/view/' + machineId + '.html');
}
else {
$http.get('/'+target+'/'+action+'/'+machineId+'.json'+'?'+this.getQueryStringFromObject(params))
.then(function() {
}, function(data,status) {
console.error('Repos error', status, data);
window.location.reload();
});
}
};
subscribe_requests = function(url) {
......
......@@ -891,6 +891,12 @@ get '/machine/compact/(#id_domain)' => sub($c) {
return $c->render(json => { request => $req->id });
};
get '/execution_machines_limit' => sub {
my $c = shift;
return get_execution_machines_limit_per_current_user($c);
};
get '/node/exists/#name' => sub {
my $c = shift;
my $name = $c->stash('name');
......@@ -2703,7 +2709,22 @@ sub resume_machine {
return $c->render(json => { req => $req->id });
}
sub get_execution_machines_limit_per_current_user {
my $c = shift;
return login($c) if !_logged_in($c);
my $settings = $RAVADA->settings_global();
my $start_limit = $settings->{'backend'}->{'start_limit'}->{'value'};
my $can_start_many = $USER->can_start_many;
my @running_domains;
foreach my $domain (@{$RAVADA->list_domains( id_owner => $USER->id )})
{
push(@running_domains, $domain->{'id'}) if ($domain->{'is_active'});
}
return $c->render(json => { can_start_many => $can_start_many, start_limit => $start_limit, running_domains => \@running_domains });
}
sub list_requests {
my $c = shift;
......
......@@ -10,16 +10,39 @@
<br><br>
</div>
<div ng-show="(confirmingMachineStopOnNewMachineStartData) && (confirmingMachineStopOnNewMachineStartData.action === 'start')" class="alert alert-warning" role="alert">
<span><%=l 'One of the machines that are currently running will be shutdown.' %></span>
<br>
<span><%=l 'Continue?' %></span>
<br>
<div class="pull-right">
<input type="button" class="btn btn-danger btn-xs" value="<%=l 'Yes' %>" ng-click="confirmingMachineStopOnNewMachineStartDataDone()">
<input type="button" class="btn btn-primary btn-xs" value="<%=l 'No' %>" ng-click="confirmingMachineStopOnNewMachineStartDataCancelled()">
</div>
<br>
</div>
<div ng-show="showmachine.can_view">
<a type="button" class="btn btn-primary btn-sm"
ng-href="/machine/view/{{showmachine.id}}.html"
<button type="button" class="btn btn-primary btn-sm"
ng-click="action('machine','view',showmachine.id)"
title="<%=l 'View' %>">
<i class="fa fa-desktop"></i>
</a>
</button>
<span><%=l 'View' %></span>
<br><br>
</div>
<div type="warning" ng-show="(confirmingMachineStopOnNewMachineStartData) && (confirmingMachineStopOnNewMachineStartData.action === 'view')" class="alert alert-warning" role="alert">
<span><%=l 'One of the machines that are currently running will be shutdown.' %></span>
<br>
<span><%=l 'Continue?' %></span>
<br>
<div class="pull-right">
<input type="button" class="btn btn-primary btn-xs" value="<%=l 'Yes' %>" ng-click="confirmingMachineStopOnNewMachineStartDataDone()">
<input type="button" class="btn btn-primary btn-xs" value="<%=l 'No' %>" ng-click="confirmingMachineStopOnNewMachineStartDataCancelled()">
</div>
<br>
</div>
<div ng-show="showmachine.can_hibernate">
<button type="button" class="btn btn-warning btn-sm"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment