Commit 4688da99 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

request shutdown a domain

parent 1e93163e
......@@ -306,14 +306,33 @@ sub _cmd_start {
}
sub _cmd_shutdown {
my $self = shift;
my $request = shift;
$request->status('working');
my $name = $request->args('name');
eval {
my $domain = $self->search_domain($name);
die "Unknown domain '$name'\n" if !$domain;
$domain->shutdown();
};
$request->status('done');
$request->error($@);
}
sub _req_method {
my $self = shift;
my $cmd = shift;
my %methods = (
start => \&_cmd_start
,create => \&_cmd_create
,remove => \&_cmd_remove
,shutdown => \&_cmd_shutdown
);
return $methods{$cmd};
}
......
......@@ -124,6 +124,30 @@ sub start_domain {
}
=head2 shutdown_domain
Requests to stop a domain
my $req = Ravada::Request->shutdown_domain( name => 'name' );
=cut
sub shutdown_domain {
my $proto = shift;
my $class=ref($proto) || $proto;
my $name = shift;
$name = $name->name if ref($name) =~ /Domain/;
my %args = ( name => $name ) or confess "Missing domain name";
my $self = {};
bless($self,$class);
return $self->_new_request(command => 'shutdown' , args => encode_json({ name => $name }));
}
sub _new_request {
my $self = shift;
my %args = @_;
......
......@@ -72,6 +72,10 @@ sub test_start {
.($req->error or '<NULL>'));
$req = undef;
#####################################################################3
#
# start
my $req2 = Ravada::Request->start_domain($name);
$ravada->process_requests();
......@@ -82,6 +86,21 @@ sub test_start {
my $domain2 = $ravada->search_domain($name);
ok($domain2->is_active);
$req2 = undef;
#####################################################################3
#
# stop
my $req3 = Ravada::Request->shutdown_domain($name);
$ravada->process_requests();
ok($req3->status eq 'done');
ok(!$domain->is_active);
my $domain3 = $ravada->search_domain($name);
ok(!$domain3->is_active);
}
###############################################################
......
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