diff --git a/lib/Ravada/Front.pm b/lib/Ravada/Front.pm index 141ec3fc6..534848912 100644 --- a/lib/Ravada/Front.pm +++ b/lib/Ravada/Front.pm @@ -485,8 +485,13 @@ sub open_vm { my $type = shift or confess "I need vm type"; my $class = "Ravada::VM::$type"; - if ($VM{$type}) { - return $VM{$type} + if (my $vm = $VM{$type}) { + if (!$vm->ping) { + $vm->disconnect(); + $vm->connect(); + } else { + return $vm; + } } my $proto = {}; diff --git a/lib/Ravada/VM.pm b/lib/Ravada/VM.pm index c409b4e67..6cab30a8a 100644 --- a/lib/Ravada/VM.pm +++ b/lib/Ravada/VM.pm @@ -44,6 +44,7 @@ requires 'connect'; requires 'disconnect'; requires 'import_domain'; +requires 'ping'; ############################################################ has 'host' => ( diff --git a/lib/Ravada/VM/KVM.pm b/lib/Ravada/VM/KVM.pm index 98612b698..1b733af1a 100644 --- a/lib/Ravada/VM/KVM.pm +++ b/lib/Ravada/VM/KVM.pm @@ -1793,4 +1793,11 @@ sub import_domain { return $domain; } +sub ping($self) { + return 0 if !$self->vm; + eval { $self->vm->list_defined_networks }; + return 1 if !$@; + return 0; +} + 1; diff --git a/lib/Ravada/VM/Void.pm b/lib/Ravada/VM/Void.pm index 8643aff81..88eddcec3 100644 --- a/lib/Ravada/VM/Void.pm +++ b/lib/Ravada/VM/Void.pm @@ -148,6 +148,10 @@ sub import_domain { confess "Not implemented"; } +sub refresh_storage {} + +sub ping { return 1 } + #########################################################################3 1;