[pve-devel] [PATCH 07/19] phase2_cleanup : destroy remote external vm on error

Alexandre Derumier aderumier at odiso.com
Wed Feb 22 14:33:31 CET 2017


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuMigrate.pm | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 616632c..b711564 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -483,6 +483,7 @@ sub phase2 {
 
             if ($line =~ m/^vm (\d+) created$/) {
                 $vmid = $1;
+		$self->{opts}->{targetvmid} = $1;
             }
 	});
 
@@ -820,6 +821,7 @@ sub phase2 {
 sub phase2_cleanup {
     my ($self, $vmid, $err) = @_;
 
+
     return if !$self->{errors};
     $self->{phase2errors} = 1;
 
@@ -852,15 +854,37 @@ sub phase2_cleanup {
 	}
     }
 
-    my $nodename = PVE::INotify::nodename();
+    $vmid = $self->{opts}->{targetvmid} if $self->{opts}->{targetvmid};
  
-    my $cmd = [@{$self->{rem_ssh}}, 'qm', 'stop', $vmid, '--skiplock', '--migratedfrom', $nodename];
+    my $cmd = [@{$self->{rem_ssh}}, 'qm', 'stop', $vmid, '--skiplock'];
+    if (!$self->{opts}->{externalcluster}) {
+	my $nodename = PVE::INotify::nodename();
+        push @$cmd , '--migratedfrom', $nodename;
+    }
+
     eval{ PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}) };
     if (my $err = $@) {
         $self->log('err', $err);
         $self->{errors} = 1;
     }
 
+    if ($self->{opts}->{externalcluster} && $self->{opts}->{targetvmid}) {
+
+        my $cmdunlock = [ @{$self->{rem_ssh}}, 'qm', 'unlock', $vmid ];
+        eval { PVE::Tools::run_command($cmdunlock, outfunc => sub {}, errfunc => sub {}) };
+        if (my $err = $@) {
+            $self->log('err', $err);
+            $self->{errors} = 1;
+        }
+
+        my $cmddestroy = [@{$self->{rem_ssh}}, 'rm', "/etc/pve/qemu-server/$vmid.conf" ];
+        eval{ PVE::Tools::run_command($cmddestroy, outfunc => sub {}, errfunc => sub {}) };
+        if (my $err = $@) {
+            $self->log('err', $err);
+            $self->{errors} = 1;
+        }
+    }
+
     if ($self->{tunnel}) {
 	eval { finish_tunnel($self, $self->{tunnel});  };
 	if (my $err = $@) {
-- 
2.1.4




More information about the pve-devel mailing list