Unverified Commit 9772d32f authored by Francesc Guasch's avatar Francesc Guasch Committed by GitHub
Browse files

refactor(CLI): shutdown disconnect skip autostarts (#1740)

refactor(CLI): shutdown disconnect skip autostarts

closes #1450
parent b3531e9f
......@@ -5424,10 +5424,9 @@ sub _remove_unnecessary_request($self, $domain, $command = ['set_time', 'open_ex
sub _remove_unnecessary_downs($self, $domain) {
my @requests = $domain->list_requests(1);
my $uid_daemon = Ravada::Utils::user_daemon->id();
for my $req (@requests) {
$req->status('done') if $req->command =~ /shutdown/
&& (!$req->at_time || $req->defined_arg('uid') == $uid_daemon );
$req->status('done')
if $req->command =~ /shutdown/ && (!$req->at_time || $req->at_time <= time+180);
$req->_remove_messages();
}
}
......
......@@ -707,7 +707,7 @@ sub shutdown_domain {
print $domain->name." status = ".($client_status or '<UNDEF>')."\n" if $DISCONNECTED && $VERBOSE && $is_active;
if ((defined $domain_name && $domain->name eq $domain_name)
|| ($hibernated && $domain->is_hibernated)
|| ($DISCONNECTED && $client_status eq 'disconnected' )
|| ($DISCONNECTED && $is_active && ( $client_status eq 'disconnected' || !$client_status) )
|| $all ){
$found++;
if (!$is_active && !$domain->is_hibernated) {
......@@ -716,23 +716,36 @@ sub shutdown_domain {
if !$all;
next;
}
if ($domain->is_hibernated) {
print "Starting ".$domain->name."\n";
Ravada::Request->start_domain(
if ($DISCONNECTED && $client_status
&& $client_status eq 'disconnected') {
if ( $domain->autostart() ) {
print "\tautostart set, skipping shutdown\n";
next;
}
next DOMAIN if _verify_connection($domain);
}
my $at = 0;
my $txt_time = '';
my @after_req;
if ($domain->is_hibernated && !$DISCONNECTED) {
print $domain->name." is hibernated. Starting ".$domain->name."\n";
my $req_start = Ravada::Request->start_domain(
uid => Ravada::Utils::user_daemon->id
,id_domain => $domain->id
);
$at = time + 180;
$txt_time = " in 3 minutes";
my @after_req = ( after_request => $req_start->id);
}
if ($DISCONNECTED && $client_status
&& $client_status eq 'disconnected') {
next DOMAIN if _verify_connection($domain);
}
print "Shutting down ".$domain->name.".\n";
print "\tShutting down ".$domain->name;
print " in ".($at - time)." seconds" if $at;
print "\n";
Ravada::Request->shutdown_domain(uid => Ravada::Utils::user_daemon()->id
,id_domain => $domain->id
, timeout => 300
,@after_req
,at => $at
);
$down++;
warn $@ if $@;
......
......@@ -44,8 +44,9 @@ sub _download_alpine64 {
sub _driver_field($hardware) {
my $driver_field = 'driver';
$driver_field = 'type' if $hardware eq 'video';
$driver_field = 'model' if $hardware =~ /cpu|sound/;
$driver_field = 'type' if $hardware eq 'video';
$driver_field = 'model' if $hardware =~ /sound/;
$driver_field = 'mode' if $hardware eq 'cpu';
return $driver_field;
}
......@@ -1071,6 +1072,10 @@ sub test_change_drivers($domain, $hardware) {
my $domain_f = Ravada::Front::Domain->open($domain->id);
$info = $domain_f->info(user_admin);
die "Error: no field $driver_field in $hardware [$index] ".Dumper($info->{hardware}->{$hardware}->[$index])
if !exists $info->{hardware}->{$hardware}->[$index]->{$driver_field};
is ($info->{hardware}->{$hardware}->[$index]->{$driver_field}, $option
,Dumper($domain_f->name,$info->{hardware}->{$hardware}->[$index])) or exit;
......@@ -1248,7 +1253,7 @@ for my $vm_name (reverse vm_names()) {
test_change_hardware($vm, $domain_b, $hardware);
# change driver is not possible for displays
test_change_drivers($domain_b, $hardware) if $hardware !~ /^(display|usb|mock|features)$/;
test_change_drivers($domain_b, $hardware) if $hardware !~ /^(display|usb|mock|features|cpu)$/;
test_all_drivers($domain_b, $hardware) if $hardware !~ /^(display|usb|mock|features)$/;
# try to add with the machine started
......
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