Commit 1e93163e authored by Francesc Guasch's avatar Francesc Guasch
Browse files

request commands in a hash

parent c064f3bc
......@@ -259,33 +259,66 @@ sub _execute {
my $self = shift;
my $request = shift;
if ($request->command() eq 'create' ) {
$request->status('working');
eval { $self->create_domain(%{$request->args}) };
$request->status('done');
$request->error($@);
} elsif ($request->command eq 'remove') {
$request->status('working');
eval { $self->remove_domain($request->args('name')) };
$request->status('done');
$request->error($@);
} elsif ($request->command eq 'start') {
$request->status('working');
my $name = $request->args('name');
eval {
my $domain = $self->search_domain($name);
die "Unknown domain '$name'\n" if !$domain;
$domain->start();
};
$request->status('done');
$request->error($@);
my $sub = $self->_req_method($request->command);
die "Unknown command ".$request->command
if !$sub;
return $sub->($self,$request);
}
sub _cmd_create {
my $self = shift;
my $request = shift;
$request->status('working');
eval { $self->create_domain(%{$request->args}) };
$request->status('done');
$request->error($@);
}
sub _cmd_remove {
my $self = shift;
my $request = shift;
$request->status('working');
eval { $self->remove_domain($request->args('name')) };
$request->status('done');
$request->error($@);
} else {
die "Unknown command ".$request->command;
}
}
sub _cmd_start {
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->start();
};
$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
);
return $methods{$cmd};
}
=head1 AUTHOR
Francesc Guasch-Ortiz , frankie@telecos.upc.edu
......
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