Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
Ravada-Mirror
Commits
27c3c5ec
Commit
27c3c5ec
authored
Feb 08, 2021
by
Roberto P. Rubio
Browse files
Confirms machine start if running machines limit reached (on actions tab)
parent
754c07bc
Changes
3
Hide whitespace changes
Inline
Side-by-side
public/js/ravada.js
View file @
27c3c5ec
...
@@ -96,6 +96,7 @@
...
@@ -96,6 +96,7 @@
})
})
);
);
};
};
$scope
.
action
=
function
(
machine
,
action
)
{
$scope
.
action
=
function
(
machine
,
action
)
{
machine
.
action
=
false
;
machine
.
action
=
false
;
if
(
action
==
'
restore
'
)
{
if
(
action
==
'
restore
'
)
{
...
@@ -220,15 +221,49 @@
...
@@ -220,15 +221,49 @@
return
string
;
return
string
;
};
};
$scope
.
action
=
function
(
target
,
action
,
machineId
,
params
){
$scope
.
confirmingMachineStopOnNewMachineStartData
=
null
;
$http
.
get
(
'
/
'
+
target
+
'
/
'
+
action
+
'
/
'
+
machineId
+
'
.json
'
+
'
?
'
+
this
.
getQueryStringFromObject
(
params
))
.
then
(
function
()
{
$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
)
{
},
function
(
data
,
status
)
{
console
.
error
(
'
Repos error
'
,
status
,
data
);
console
.
error
(
'
Repos error
'
,
status
,
data
);
window
.
location
.
reload
();
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
)
{
subscribe_requests
=
function
(
url
)
{
var
ws
=
new
WebSocket
(
url
);
var
ws
=
new
WebSocket
(
url
);
ws
.
onopen
=
function
(
event
)
{
ws
.
send
(
'
list_requests
'
)
};
ws
.
onopen
=
function
(
event
)
{
ws
.
send
(
'
list_requests
'
)
};
...
...
script/rvd_front
View file @
27c3c5ec
...
@@ -891,6 +891,12 @@ get '/machine/compact/(#id_domain)' => sub($c) {
...
@@ -891,6 +891,12 @@ get '/machine/compact/(#id_domain)' => sub($c) {
return $c->render(json => { request => $req->id });
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 {
get '/node/exists/#name' => sub {
my $c = shift;
my $c = shift;
my $name = $c->stash('name');
my $name = $c->stash('name');
...
@@ -2703,7 +2709,22 @@ sub resume_machine {
...
@@ -2703,7 +2709,22 @@ sub resume_machine {
return $c->render(json => { req => $req->id });
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 {
sub list_requests {
my $c = shift;
my $c = shift;
...
...
templates/main/vm_actions.html.ep
View file @
27c3c5ec
...
@@ -10,16 +10,39 @@
...
@@ -10,16 +10,39 @@
<br><br>
<br><br>
</div>
</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">
<div ng-show="showmachine.can_view">
<
a
type="button" class="btn btn-primary btn-sm"
<
button
type="button" class="btn btn-primary btn-sm"
ng-
href="/
machine
/
view
/{{
showmachine.id
}}.html
"
ng-
click="action('
machine
','
view
',
showmachine.id
)
"
title="<%=l 'View' %>">
title="<%=l 'View' %>">
<i class="fa fa-desktop"></i>
<i class="fa fa-desktop"></i>
</
a
>
</
button
>
<span><%=l 'View' %></span>
<span><%=l 'View' %></span>
<br><br>
<br><br>
</div>
</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">
<div ng-show="showmachine.can_hibernate">
<button type="button" class="btn btn-warning btn-sm"
<button type="button" class="btn btn-warning btn-sm"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment