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