Commit 65f31d7f authored by Francesc Guasch's avatar Francesc Guasch
Browse files

[#50] remove domain after shutdown

This is done in the Domain role code, so it will
work for all the domains. Notice only the domains
that are shut down from ravada get removed. Any
domain that is shut down by the user will remain.
We still need some kind of garbage collector.
parent a57fff59
......@@ -887,7 +887,8 @@ sub _cmd_shutdown {
my $user = Ravada::Auth::SQL->search_by_id( $uid);
$domain->shutdown(timeout => $timeout, name => $name, user => $user);
$domain->shutdown(timeout => $timeout, name => $name, user => $user
, request => $request);
}
......
......@@ -86,14 +86,14 @@ sub add_user {
if keys %args;
my $sth = $$CON->dbh->prepare(
"INSERT INTO users (name,password,is_admin) VALUES(?,?,?)");
"INSERT INTO users (name,password,is_admin,is_temporary) VALUES(?,?,?,?)");
if ($password) {
$password = sha1_hex($password);
} else {
$password = '*LK* no pss';
}
$sth->execute($name,$password,$is_admin);
$sth->execute($name,$password,$is_admin,$is_temporary);
$sth->finish;
}
......@@ -227,6 +227,21 @@ sub is_admin {
return $self->{_data}->{is_admin};
}
=head2 is_temporary
Returns true if the user is admin.
my $is = $user->is_temporary;
=cut
sub is_temporary{
my $self = shift;
return $self->{_data}->{is_temporary};
}
=head2 id
Returns the user id
......
......@@ -103,6 +103,7 @@ before 'start' => \&_start_preconditions;
before 'pause' => \&_allow_manage;
before 'resume' => \&_allow_manage;
before 'shutdown' => \&_allow_manage_args;
after 'shutdown' => \&_post_shutdown;
before 'remove_base' => \&_can_remove_base;
after 'remove_base' => \&_remove_base_db;
......@@ -616,4 +617,21 @@ sub clone {
);
}
sub _post_shutdown {
my $self = shift;
my %args = @_;
my $user = Ravada::Auth::SQL->search_by_id($self->id_owner);
warn Dumper($user);
if ($user->is_temporary) {
$self->remove($user);
my $req= $args{request};
$req->status(
"removing"
,"Removing domain ".$self->name." after shutdown"
." because user "
.$user->name." is temporary")
if $req;
}
}
1;
......@@ -93,6 +93,7 @@ get '/anonymous/*.html' => sub {
my $c = shift;
$c->stash(_anonymous => 1 , _logged_in => 0);
_init_error($c);
my ($base_id) = $c->req->url->to_abs =~ m{/anonymous/(.*).html};
my $base = $RAVADA->search_domain_by_id($base_id);
......@@ -544,9 +545,7 @@ sub _show_request {
my $request;
if (!ref $id_request) {
warn "opening request $id_request";
eval { $request = Ravada::Request->open($id_request) };
warn $@ if $@;
return $c->render(data => "Request $id_request unknown") if !$request;
} else {
$request = $id_request;
......@@ -582,7 +581,7 @@ sub access_denied {
my $c = shift;
my $msg = 'Access denied to '.$c->req->url->to_abs->path;
$msg .= ' for user '.$USER->name if $USER;
$msg .= ' for user '.$USER->name if $USER && !$USER->is_temporary;
return $c->render(text => $msg);
}
......@@ -605,8 +604,6 @@ sub provision {
my $domain = $RAVADA->search_domain(name => $name);
return $domain if $domain;
warn "requesting the creation of $name for ".$USER->id;
my $req = Ravada::Request->create_domain(
name => $name
, id_base => $id_base
......@@ -709,8 +706,6 @@ sub make_admin {
my ($id) = $c->req->url->to_abs->path =~ m{/(\d+).json};
warn "id usuari $id";
Ravada::Auth::SQL::make_admin($id);
}
......@@ -721,8 +716,6 @@ sub remove_admin {
my ($id) = $c->req->url->to_abs->path =~ m{/(\d+).json};
warn "id usuari $id";
Ravada::Auth::SQL::remove_admin($id);
}
......@@ -756,11 +749,9 @@ sub manage_machine {
sub _enable_buttons {
my $c = shift;
my $domain = shift;
warn "is_paused=".$domain->is_paused;
if (($c->param('pause') && !$domain->is_paused)
||($c->param('resume') && $domain->is_paused)) {
sleep 2;
warn " -> is_paused=".$domain->is_paused;
}
$c->stash(_shutdown_disabled => '');
$c->stash(_shutdown_disabled => 'disabled') if !$domain->is_active;
......@@ -793,6 +784,7 @@ sub view_machine {
sub clone_machine {
my $c = shift;
return login($c) if !_logged_in($c);
_init_error($c);
my $base = _search_requested_machine($c);
if (!$base ) {
......@@ -839,8 +831,6 @@ sub remove_machine {
return $c->render( text => "Domain not found") if !$domain;
$c->stash(domain => $domain );
warn "found domain ".$domain->name;
return $c->render( template => 'bootstrap/remove_machine' );
}
......@@ -862,8 +852,6 @@ sub screenshot_machine {
my $c = shift;
return login($c) if !_logged_in($c);
warn ref($c);
my $domain = _search_requested_machine($c);
my $file_screenshot = "$DOCUMENT_ROOT/img/screenshots/".$domain->id.".png";
......@@ -1014,7 +1002,6 @@ sub _new_anonymous_user {
};
last if !$user;
}
warn "\n*** creating temporary user $name";
Ravada::Auth::SQL::add_user(name => $name, is_temporary => 1);
return $name;
......
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