Commit 67ea8882 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

[#589] fixed autostart for readonly frontend domains

parent bdafeafe
...@@ -816,6 +816,7 @@ sub _upgrade_tables { ...@@ -816,6 +816,7 @@ sub _upgrade_tables {
$self->_upgrade_table('domains','run_timeout','int DEFAULT NULL'); $self->_upgrade_table('domains','run_timeout','int DEFAULT NULL');
$self->_upgrade_table('domains','start_time','int DEFAULT 0'); $self->_upgrade_table('domains','start_time','int DEFAULT 0');
$self->_upgrade_table('domains','is_volatile','int NOT NULL DEFAULT 0'); $self->_upgrade_table('domains','is_volatile','int NOT NULL DEFAULT 0');
$self->_upgrade_table('domains','autostart','int NOT NULL DEFAULT 0');
$self->_upgrade_table('domains','status','varchar(32) DEFAULT "shutdown"'); $self->_upgrade_table('domains','status','varchar(32) DEFAULT "shutdown"');
$self->_upgrade_table('domains','display','varchar(128) DEFAULT NULL'); $self->_upgrade_table('domains','display','varchar(128) DEFAULT NULL');
......
...@@ -176,7 +176,7 @@ after '_select_domain_db' => \&_post_select_domain_db; ...@@ -176,7 +176,7 @@ after '_select_domain_db' => \&_post_select_domain_db;
around 'get_info' => \&_around_get_info; around 'get_info' => \&_around_get_info;
before 'autostart' => \&_pre_autostart; around 'autostart' => \&_around_autostart;
################################################## ##################################################
# #
...@@ -351,12 +351,25 @@ sub _post_prepare_base { ...@@ -351,12 +351,25 @@ sub _post_prepare_base {
} }
$self->_remove_id_base(); $self->_remove_id_base();
$self->autostart(0); $self->autostart(0,$user);
}; };
sub _pre_autostart($self, $value=undef) { sub _around_autostart($orig, $self, @arg) {
confess "ERROR: Autostart can't be activated on bases" my ($value, $user) = @arg;
$self->_allowed($user) if defined $value;
confess "ERROR: Autostart can't be activated on base ".$self->name
if $value && $self->is_base; if $value && $self->is_base;
confess "ERROR: You can't set autostart on readonly domains"
if defined $value && $self->readonly;
my $autostart = 0;
my @orig_args = ();
push @orig_args, ( $value) if defined $value;
if ( $self->$orig(@orig_args) ) {
$autostart = 1;
}
$self->_data(autostart => $autostart) if defined $value;
return $autostart;
} }
sub _check_has_clones { sub _check_has_clones {
...@@ -461,7 +474,7 @@ sub _around_display($orig,$self,$user) { ...@@ -461,7 +474,7 @@ sub _around_display($orig,$self,$user) {
sub _around_get_info($orig, $self) { sub _around_get_info($orig, $self) {
my $info = $self->$orig(); my $info = $self->$orig();
if (ref($self) =~ /^Ravada::Domain/) { if (ref($self) =~ /^Ravada::Domain/ && $self->is_known()) {
$self->_data(info => encode_json($info)); $self->_data(info => encode_json($info));
} }
return $info; return $info;
......
...@@ -1618,7 +1618,7 @@ sub internal_id($self) { ...@@ -1618,7 +1618,7 @@ sub internal_id($self) {
return $self->domain->get_id(); return $self->domain->get_id();
} }
sub autostart($self, $value=undef) { sub autostart($self, $value=undef, $user=undef) {
$self->domain->set_autostart($value) if defined $value; $self->domain->set_autostart($value) if defined $value;
return $self->domain->get_autostart(); return $self->domain->get_autostart();
} }
......
...@@ -39,18 +39,21 @@ sub BUILD { ...@@ -39,18 +39,21 @@ sub BUILD {
mkdir $DIR_TMP or die "$! when mkdir $DIR_TMP" mkdir $DIR_TMP or die "$! when mkdir $DIR_TMP"
if ! -e $DIR_TMP; if ! -e $DIR_TMP;
my $drivers = {};
if ($args->{id_base}) { if ($args->{id_base}) {
my $base = Ravada::Domain->open($args->{id_base}); my $base = Ravada::Domain->open($args->{id_base});
confess "ERROR: Wrong base ".ref($base)." ".$base->type confess "ERROR: Wrong base ".ref($base)." ".$base->type
."for domain in vm ".$self->_vm->type ."for domain in vm ".$self->_vm->type
if $base->type ne $self->_vm->type; if $base->type ne $self->_vm->type;
my $drivers = $base->_value('drivers'); $drivers = $base->_value('drivers');
$self->_store(drivers => $drivers ); }
if ( ! -e $self->_config_file ) {
$self->_set_default_info();
$self->_store( autostart => 0 );
$self->_store( drivers => $drivers );
} }
$self->_set_default_info();
$self->set_memory($args->{memory}) if $args->{memory}; $self->set_memory($args->{memory}) if $args->{memory};
$self->_store( autostart => 0);
} }
sub name { sub name {
...@@ -84,6 +87,7 @@ sub remove { ...@@ -84,6 +87,7 @@ sub remove {
my $self = shift; my $self = shift;
$self->remove_disks(); $self->remove_disks();
unlink $self->_config_file();
} }
sub is_hibernated { sub is_hibernated {
......
...@@ -38,6 +38,7 @@ sub BUILD($self, $arg) { ...@@ -38,6 +38,7 @@ sub BUILD($self, $arg) {
if $self->is_volatile && ! $self->is_active; if $self->is_volatile && ! $self->is_active;
} }
sub autostart($self ) { return $self->_data('autostart') }
sub _do_force_shutdown { confess "TODO" } sub _do_force_shutdown { confess "TODO" }
sub add_volume { confess "TODO" } sub add_volume { confess "TODO" }
sub clean_swap_volumes { confess "TODO" } sub clean_swap_volumes { confess "TODO" }
......
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