diff --git a/ucloud/vmm/__init__.py b/ucloud/vmm/__init__.py index 3d3c304..d64473b 100644 --- a/ucloud/vmm/__init__.py +++ b/ucloud/vmm/__init__.py @@ -57,6 +57,7 @@ class TransferVM(Process): os.remove(self.src_sock_path) command = [ + "sudo" "ssh", "-nNT", "-L", @@ -73,9 +74,7 @@ class TransferVM(Process): else: time.sleep(2) vmm = VMM() - logger.debug( - "Executing: ssh forwarding command: %s", command - ) + logger.debug("Executing: ssh forwarding command: %s", command) vmm.execute_command( self.src_uuid, command="migrate", @@ -83,22 +82,20 @@ class TransferVM(Process): ) while p.poll() is None: - success, output = vmm.execute_command( - self.src_uuid, command="query-migrate" - ) + success, output = vmm.execute_command(self.src_uuid, command="query-migrate") if success: status = output["return"]["status"] - - if status != "active": - print("Migration Status: ", status) - if status == "completed": - vmm.stop(self.src_uuid) + logger.info('Migration Status: {}'.format(status)) + if status == "completed": + vmm.stop(self.src_uuid) + return + elif status in ['failed', 'cancelled']: return - else: - print("Migration Status: ", status) else: + logger.error("Couldn't be able to query VM {} that was in migration".format(self.src_uuid)) return - time.sleep(0.2) + + time.sleep(2) class VMM: