Commit 098055f4 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

fix(nodes): shared storage remove fixed

issue #1085
parent c66ec54e
......@@ -1616,6 +1616,9 @@ sub remove_domain {
die "Error: user ".$user->name." can't remove domain $id"
if !$user->can_remove_machine($id);
my $domain0 = Ravada::Domain->open( $id );
$domain0->shutdown_now($user) if $domain0 && $domain0->is_active;
my $vm = Ravada::VM->open(type => $vm_type);
my $domain = Ravada::Domain->open(id => $id, _force => 1, id_vm => $vm->id)
or do {
......@@ -2579,6 +2582,12 @@ sub _cmd_rebase_volumes($self, $request) {
die "Error: ".$user->name." not authorized to dettach domain"
if !$user->is_admin;
if ($domain->is_active) {
Ravada::Request->shutdown_domain(uid => $user->id, id_domain => $domain->id, timeout => 120);
$request->status('retry');
die "Error: domain ".$domain->name." is still active, shut it down to rebase\n"
}
my $new_base = Ravada::Domain->open($request->args('id_base'));
$domain->rebase_volumes($new_base);
}
......
......@@ -1692,9 +1692,16 @@ sub _do_remove_base($self, $user) {
}
sub _pre_remove_base {
my ($domain) = @_;
_allow_manage(@_);
_check_has_clones(@_);
$_[0]->spinoff_volumes();
if (!$domain->is_local) {
my $vm_local = $domain->_vm->new( host => 'localhost' );
my $domain_local = $vm_local->search_domain($domain->name);
$domain = $domain_local if $domain_local;
}
$domain->spinoff_volumes();
}
sub _post_remove_base {
......
......@@ -179,7 +179,6 @@ sub remove_disks {
$self->_vm->connect();
for my $file ($self->list_disks( device => 'disk')) {
confess $file if $file =~ /iso$/;
if (! -e $file ) {
next;
}
......@@ -272,7 +271,8 @@ sub remove {
confess $@ if $@ && $@ !~ /libvirt error code: 42/;
for my $file ( @volumes ) {
$self->remove_volume($file);
eval { $self->remove_volume($file) };
warn $@ if $@;
}
eval { $self->_remove_file_image() };
......@@ -478,6 +478,7 @@ sub _create_qcow_base {
sub _cmd_convert {
my ($base_img, $qcow_img) = @_;
return ('qemu-img','convert',
'-O','qcow2', $base_img
,$qcow_img
......@@ -1549,12 +1550,7 @@ sub spinoff_volumes {
$self->_do_force_shutdown() if $self->is_active;
for my $disk ($self->_disk_devices_xml) {
my ($source) = $disk->findnodes('source');
next if !$source;
my $volume = $source->getAttribute('file') or next;
for my $volume ($self->list_disks) {
confess "ERROR: Domain ".$self->name
." volume '$volume' does not exists"
......@@ -1577,7 +1573,10 @@ sub spinoff_volumes {
warn $out if $out;
warn $err if $err;
die "ERROR: Temporary output file $volume_tmp not created at "
.join(" ",@cmd)."\n"
.join(" ",@cmd)
.($out or '')
.($err or '')
."\n"
if (! -e $volume_tmp );
copy($volume_tmp,$volume) or die "$! $volume_tmp -> $volume";
......@@ -1634,6 +1633,7 @@ sub _hwaddr {
sub _find_base {
my $self = shift;
my $file = shift;
my @cmd = ( 'qemu-img','info',$file);
my ($in,$out, $err);
run3(\@cmd,\$in, \$out, \$err);
......
......@@ -729,7 +729,7 @@ sub open_vm {
my $class = "Ravada::VM::$type";
if (my $vm = $VM{$type}) {
if (!$vm->ping) {
if (!$vm->ping || !$vm->is_alive) {
$vm->disconnect();
$vm->connect();
} else {
......
......@@ -77,6 +77,9 @@ our $CONNECTOR = \$Ravada::CONNECTOR;
our $WGET = `which wget`;
chomp $WGET;
our $BRCTL = `which brctl`;
chomp $BRCTL;
our $CACHE_DOWNLOAD = 1;
our $VERIFY_ISO = 1;
......@@ -2184,7 +2187,13 @@ Returns true if the virtual manager connection is active, false otherwise.
sub is_alive($self) {
return 0 if !$self->vm;
return 1 if $self->vm->is_alive;
my $is_alive = $self->vm->is_alive;
return 0 if !$is_alive;
eval {
$self->vm->get_hostname();
};
warn $@ if $@;
return 1 if !$@;
return 0;
}
......@@ -2298,9 +2307,10 @@ sub _list_qemu_bridges($self) {
sub _list_bridges($self) {
return () if !-e $BRCTL;
my %qemu_bridge = map { $_ => 1 } $self->_list_qemu_bridges();
my @cmd = ( '/sbin/brctl','show');
my @cmd = ( $BRCTL,'show');
my ($out,$err) = $self->run_command(@cmd);
die $err if $err;
......
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