From 29e938dc74bfea7edd0c69963efe25ec844527cb Mon Sep 17 00:00:00 2001 From: meow Date: Sun, 29 Dec 2019 23:48:04 +0500 Subject: [PATCH] Destination Host of VM during migration now notify Source host of exact socket path --- ucloud/common/request.py | 1 + ucloud/host/main.py | 3 ++- ucloud/host/virtualmachine.py | 6 ++++-- ucloud/vmm/__init__.py | 15 ++++++++++----- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ucloud/common/request.py b/ucloud/common/request.py index 2d9be44..5705eed 100644 --- a/ucloud/common/request.py +++ b/ucloud/common/request.py @@ -19,6 +19,7 @@ class RequestType: class RequestEntry(SpecificEtcdEntryBase): def __init__(self, e): + self.destination_sock_path = None self.destination_host_key = None self.type = None # type: str self.migration = None # type: bool diff --git a/ucloud/host/main.py b/ucloud/host/main.py index b5aeee3..904f26c 100755 --- a/ucloud/host/main.py +++ b/ucloud/host/main.py @@ -76,7 +76,8 @@ def main(hostname): elif request_event.type == RequestType.TransferVM: host = host_pool.get(request_event.destination_host_key) if host: - vm.migrate(destination=host.hostname) + vm.migrate(destination_host=host.hostname, + destination_sock_path=request_event.destination_sock_path) else: logger.error('Host %s not found!', request_event.destination_host_key) else: diff --git a/ucloud/host/virtualmachine.py b/ucloud/host/virtualmachine.py index 6d25205..db0f7b8 100755 --- a/ucloud/host/virtualmachine.py +++ b/ucloud/host/virtualmachine.py @@ -78,6 +78,7 @@ class VM: type=RequestType.TransferVM, # Transfer VM hostname=self.host_key, # Which VM should get this request. It is source host uuid=self.uuid, # uuid of VM + destination_sock_path=join_path(self.vmm.socket_dir, self.uuid), destination_host_key=destination_host_key, # Where source host transfer VM request_prefix=settings['etcd']['request_prefix'] ) @@ -94,8 +95,9 @@ class VM: declare_stopped(self.vm) self.sync() - def migrate(self, destination): - self.vmm.transfer(src_uuid=self.uuid, dest_uuid=self.uuid, host=destination) + def migrate(self, destination_host, destination_sock_path): + self.vmm.transfer(src_uuid=self.uuid, destination_sock_path=destination_sock_path, + host=destination_host) def create_network_dev(self): command = '' diff --git a/ucloud/vmm/__init__.py b/ucloud/vmm/__init__.py index f85d7a3..9f9f5f9 100644 --- a/ucloud/vmm/__init__.py +++ b/ucloud/vmm/__init__.py @@ -42,12 +42,11 @@ class VMQMPHandles: class TransferVM(Process): - def __init__(self, src_uuid, dest_uuid, host, socket_dir): + def __init__(self, src_uuid, dest_sock_path, host, socket_dir): self.src_uuid = src_uuid - self.dest_uuid = dest_uuid self.host = host self.src_sock_path = os.path.join(socket_dir, self.src_uuid) - self.dest_sock_path = os.path.join(socket_dir, self.dest_uuid) + self.dest_sock_path = dest_sock_path super().__init__() @@ -203,6 +202,12 @@ class VMM: return output['return']['service'] return None - def transfer(self, src_uuid, dest_uuid, host): - p = TransferVM(src_uuid, dest_uuid, socket_dir=self.socket_dir, host=host) + def transfer(self, src_uuid, destination_sock_path, host): + p = TransferVM(src_uuid, destination_sock_path, socket_dir=self.socket_dir, host=host) p.start() + + # TODO: the following method should clean things that went wrong + # e.g If VM migration fails or didn't start for long time + # i.e 15 minutes we should stop the waiting VM. + def maintenace(self): + pass \ No newline at end of file