Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
Ravada-Mirror
Commits
19453c2e
Unverified
Commit
19453c2e
authored
Apr 08, 2020
by
Fernando Verdugo
Committed by
GitHub
Apr 08, 2020
Browse files
feat(settings): Shutdown all clones from settings (#1288)
feat(settings): Shutdown all clones from settings Issue #1287
parent
9a06b599
Changes
5
Hide whitespace changes
Inline
Side-by-side
lib/Ravada.pm
View file @
19453c2e
...
...
@@ -2981,6 +2981,39 @@ sub _cmd_start_clones {
}
}
sub
_cmd_shutdown_clones
{
my
$self
=
shift
;
my
$request
=
shift
;
my
$id_domain
=
$request
->
defined_arg
('
id_domain
');
my
$domain
=
$self
->
search_domain_by_id
(
$id_domain
);
die
"
Unknown domain '
$id_domain
'
\n
"
if
!
$domain
;
my
$uid
=
$request
->
args
('
uid
');
my
$user
=
Ravada::Auth::
SQL
->
search_by_id
(
$uid
);
my
$sth
=
$CONNECTOR
->
dbh
->
prepare
(
"
SELECT id, name, is_base FROM domains WHERE id_base = ?
"
);
$sth
->
execute
(
$id_domain
);
while
(
my
(
$id
,
$name
,
$is_base
)
=
$sth
->
fetchrow
)
{
if
(
$is_base
==
0
)
{
my
$domain2
;
my
$is_active
;
eval
{
$domain2
=
$self
->
search_domain_by_id
(
$id
);
$is_active
=
$domain2
->
is_active
;
};
warn
$@
if
$@
;
if
(
$is_active
)
{
my
$req
=
Ravada::
Request
->
shutdown_domain
(
uid
=>
$uid
,
name
=>
$name
);
}
}
}
}
sub
_cmd_prepare_base
{
my
$self
=
shift
;
my
$request
=
shift
;
...
...
@@ -3616,6 +3649,7 @@ sub _req_method {
clone
=>
\
&_cmd_clone
,
start
=>
\
&_cmd_start
,
start_clones
=>
\
&_cmd_start_clones
,
shutdown_clones
=>
\
&_cmd_shutdown_clones
,
pause
=>
\
&_cmd_pause
,
create
=>
\
&_cmd_create
,
remove
=>
\
&_cmd_remove
...
...
lib/Ravada/Request.pm
View file @
19453c2e
...
...
@@ -71,6 +71,7 @@ our %VALID_ARG = (
,
copy_screenshot
=>
{
id_domain
=>
1
}
,
start_domain
=>
{
%$args_manage
,
remote_ip
=>
2
,
name
=>
2
,
id_domain
=>
2
}
,
start_clones
=>
{
id_domain
=>
1
,
uid
=>
1
,
remote_ip
=>
1
}
,
shutdown_clones
=>
{
id_domain
=>
1
,
uid
=>
1
,
timeout
=>
2
}
,
rename_domain
=>
{
uid
=>
1
,
name
=>
1
,
id_domain
=>
1
}
,
dettach
=>
{
uid
=>
1
,
id_domain
=>
1
}
,
set_driver
=>
{
uid
=>
1
,
id_domain
=>
1
,
id_option
=>
1
}
...
...
@@ -165,7 +166,7 @@ our %COMMAND = (
,
important
=>
{
limit
=>
20
,
priority
=>
1
,
commands
=>
['
clone
','
start
','
start_clones
','
create
','
open_iptables
','
list_network_interfaces
','
list_isos
']
,
commands
=>
['
clone
','
start
','
start_clones
','
shutdown_clones
','
create
','
open_iptables
','
list_network_interfaces
','
list_isos
']
}
,
secondary
=>
{
limit
=>
50
...
...
lib/Ravada/VM.pm
View file @
19453c2e
...
...
@@ -710,7 +710,7 @@ sub _check_require_base {
if
keys
%args
;
my
$base
=
Ravada::
Domain
->
open
(
$id_base
);
my
%ignore_requests
=
map
{
$_
=>
1
}
qw(clone refresh_machine set_base_vm start_clones)
;
my
%ignore_requests
=
map
{
$_
=>
1
}
qw(clone refresh_machine set_base_vm start_clones
shutdown_clones
)
;
my
@requests
;
for
my
$req
(
$base
->
list_requests
)
{
push
@requests
,(
$req
)
if
!
$ignore_requests
{
$req
->
command
};
...
...
t/vm/10_domain.t
View file @
19453c2e
...
...
@@ -82,6 +82,53 @@ sub test_start_clones {
$domain
->
remove
(
user_admin
);
}
sub
test_shutdown_clones
{
my
$vm_name
=
shift
;
my
$ravada
=
Ravada
->
new
(
@ARG_RVD
);
my
$vm
=
$ravada
->
search_vm
(
$vm_name
);
ok
(
$vm
,"
I can't find VM
$vm_name
")
or
return
;
diag
("
Testing shutdown clones
");
my
$name
=
new_domain_name
();
my
$user_name
=
$USER
->
id
;
my
$domain
=
$vm
->
create_domain
(
name
=>
$name
,
id_owner
=>
$user_name
,
arg_create_dom
(
$vm_name
));
my
$clone1
=
$domain
->
clone
(
user
=>
$USER
,
name
=>
new_domain_name
()
);
my
$clone2
=
$domain
->
clone
(
user
=>
$USER
,
name
=>
new_domain_name
()
);
my
$clone3
=
$domain
->
clone
(
user
=>
$USER
,
name
=>
new_domain_name
()
);
is
(
$clone1
->
is_active
,
0
);
is
(
$clone2
->
is_active
,
0
);
is
(
$clone3
->
is_active
,
0
);
my
$req
=
Ravada::
Request
->
start_clones
(
uid
=>
$USER
->
id
,
id_domain
=>
$domain
->
id
,
remote_ip
=>
'
127.0.0.1
'
);
rvd_back
->
_process_all_requests_dont_fork
();
#we make sure that the sql has updated.
is
(
$req
->
status
,'
done
');
is
(
$req
->
error
,'');
# The first requests creates 3 more requests, process them
rvd_back
->
_process_all_requests_dont_fork
();
is
(
$clone1
->
is_active
,
1
);
is
(
$clone2
->
is_active
,
1
);
is
(
$clone3
->
is_active
,
1
);
$req
=
Ravada::
Request
->
shutdown_clones
(
uid
=>
$USER
->
id
,
id_domain
=>
$domain
->
id
);
rvd_back
->
_process_all_requests_dont_fork
();
#we make sure that the sql has updated.
is
(
$req
->
status
,'
done
');
is
(
$req
->
error
,'');
# The first requests creates 3 more requests, process them
rvd_back
->
_process_all_requests_dont_fork
();
is
(
$clone1
->
is_active
,
0
);
is
(
$clone2
->
is_active
,
0
);
is
(
$clone3
->
is_active
,
0
);
$clone1
->
remove
(
user_admin
);
$clone2
->
remove
(
user_admin
);
$clone3
->
remove
(
user_admin
);
$domain
->
remove
(
user_admin
);
}
sub
test_vm_connect
{
my
$vm_name
=
shift
;
my
$host
=
(
shift
or
'
localhost
');
...
...
@@ -605,6 +652,7 @@ for my $vm_name ( vm_names() ) {
test_shutdown_suspended_domain
(
$vm_name
,
$domain
);
test_pause_domain
(
$vm_name
,
$domain
);
test_shutdown_paused_domain
(
$vm_name
,
$domain
);
test_shutdown_clones
(
$vm_name
);
test_remove_domain
(
$vm_name
,
$domain
);
...
...
templates/main/vm_clones.html.ep
View file @
19453c2e
<div class="panel-body">
<div class="card-body">
<div class="row">
<label><%=l 'These actions affect all the clones on the machine' %></label>
</div>
<div class="row">
<button class="btn btn-primary" id="start-clones" name="start-clones"
<button class="btn btn-primary
mr-2
" id="start-clones" name="start-clones"
ng-click="request('start_clones',{ 'id_domain': showmachine.id })"
>
<%=l 'Start all clones' %>
</button>
<button class="btn btn-danger" id="shutdown-clones" name="shutdown-clones"
ng-click="shutdown_clones=1"
>
<%=l 'Close all clones' %>
</button>
</div>
<div ng-show="shutdown_clones">
<b><%=l 'Danger'%></b>!<br/>
<b><%=l 'Keep in mind that there may be users using a clone' %>.</b>
<%=l 'Are you sure ?'%><br/>
<a type="button" class="btn btn-primary text-white"
ng-click="shutdown_clones=0"
><%=l 'No' %></a>
<a type="button" class="btn btn-danger text-white" ng-click="request('shutdown_clones',{ 'id_domain': showmachine.id });"
><%=l 'Yes, shutwdown all the clones' %></a>
</div>
<div class="row" ng-show="pending_request">
%= include "/main/pending_request"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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