Destination Host of VM during migration now notify Source host of exact socket path

This commit is contained in:
ahmadbilalkhalid 2019-12-29 23:48:04 +05:00
parent f980cdb464
commit 29e938dc74
4 changed files with 17 additions and 8 deletions

View File

@ -19,6 +19,7 @@ class RequestType:
class RequestEntry(SpecificEtcdEntryBase): class RequestEntry(SpecificEtcdEntryBase):
def __init__(self, e): def __init__(self, e):
self.destination_sock_path = None
self.destination_host_key = None self.destination_host_key = None
self.type = None # type: str self.type = None # type: str
self.migration = None # type: bool self.migration = None # type: bool

View File

@ -76,7 +76,8 @@ def main(hostname):
elif request_event.type == RequestType.TransferVM: elif request_event.type == RequestType.TransferVM:
host = host_pool.get(request_event.destination_host_key) host = host_pool.get(request_event.destination_host_key)
if host: if host:
vm.migrate(destination=host.hostname) vm.migrate(destination_host=host.hostname,
destination_sock_path=request_event.destination_sock_path)
else: else:
logger.error('Host %s not found!', request_event.destination_host_key) logger.error('Host %s not found!', request_event.destination_host_key)
else: else:

View File

@ -78,6 +78,7 @@ class VM:
type=RequestType.TransferVM, # Transfer VM type=RequestType.TransferVM, # Transfer VM
hostname=self.host_key, # Which VM should get this request. It is source host hostname=self.host_key, # Which VM should get this request. It is source host
uuid=self.uuid, # uuid of VM 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 destination_host_key=destination_host_key, # Where source host transfer VM
request_prefix=settings['etcd']['request_prefix'] request_prefix=settings['etcd']['request_prefix']
) )
@ -94,8 +95,9 @@ class VM:
declare_stopped(self.vm) declare_stopped(self.vm)
self.sync() self.sync()
def migrate(self, destination): def migrate(self, destination_host, destination_sock_path):
self.vmm.transfer(src_uuid=self.uuid, dest_uuid=self.uuid, host=destination) self.vmm.transfer(src_uuid=self.uuid, destination_sock_path=destination_sock_path,
host=destination_host)
def create_network_dev(self): def create_network_dev(self):
command = '' command = ''

View File

@ -42,12 +42,11 @@ class VMQMPHandles:
class TransferVM(Process): 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.src_uuid = src_uuid
self.dest_uuid = dest_uuid
self.host = host self.host = host
self.src_sock_path = os.path.join(socket_dir, self.src_uuid) 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__() super().__init__()
@ -203,6 +202,12 @@ class VMM:
return output['return']['service'] return output['return']['service']
return None return None
def transfer(self, src_uuid, dest_uuid, host): def transfer(self, src_uuid, destination_sock_path, host):
p = TransferVM(src_uuid, dest_uuid, socket_dir=self.socket_dir, host=host) p = TransferVM(src_uuid, destination_sock_path, socket_dir=self.socket_dir, host=host)
p.start() 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