Remove pending vm handling mechanism from scheduler + fixed issue that update VM's hostname even on migration failure

This commit is contained in:
ahmadbilalkhalid 2019-12-30 20:05:12 +05:00
commit d13a4bcc37
5 changed files with 40 additions and 94 deletions

View file

@ -28,10 +28,8 @@ def maintenance(host):
vmm = VMM()
running_vms = vmm.discover()
for vm_uuid in running_vms:
if (
vmm.is_running(vm_uuid)
and vmm.get_status(vm_uuid) == "running"
):
if vmm.is_running(vm_uuid) and vmm.get_status(vm_uuid) == "running":
logger.debug('VM {} is running on {}'.format(vm_uuid, host))
vm = shared.vm_pool.get(
join_path(settings["etcd"]["vm_prefix"], vm_uuid)
)
@ -43,32 +41,18 @@ def maintenance(host):
def main(hostname):
host_pool = shared.host_pool
host = next(
filter(lambda h: h.hostname == hostname, host_pool.hosts), None
)
assert host is not None, "No such host with name = {}".format(
hostname
)
host = next(filter(lambda h: h.hostname == hostname, host_pool.hosts), None)
assert host is not None, "No such host with name = {}".format(hostname)
try:
heartbeat_updating_process = mp.Process(
target=update_heartbeat, args=(hostname,)
)
heartbeat_updating_process = mp.Process(target=update_heartbeat, args=(hostname,))
heartbeat_updating_process.start()
except Exception as e:
raise Exception(
"ucloud-host heartbeat updating mechanism is not working"
) from e
raise Exception("ucloud-host heartbeat updating mechanism is not working") from e
for events_iterator in [
shared.etcd_client.get_prefix(
settings["etcd"]["request_prefix"], value_in_json=True
),
shared.etcd_client.watch_prefix(
settings["etcd"]["request_prefix"],
timeout=10,
value_in_json=True,
),
shared.etcd_client.get_prefix(settings["etcd"]["request_prefix"], value_in_json=True),
shared.etcd_client.watch_prefix(settings["etcd"]["request_prefix"], timeout=10, value_in_json=True)
]:
for request_event in events_iterator:
request_event = RequestEntry(request_event)
@ -76,52 +60,35 @@ def main(hostname):
if request_event.type == "TIMEOUT":
maintenance(host.key)
if request_event.hostname == host.key:
logger.debug("VM Request: %s", request_event)
shared.request_pool.client.client.delete(
request_event.key
)
elif request_event.hostname == host.key:
logger.debug("VM Request: %s on Host %s", request_event, host.hostname)
shared.request_pool.client.client.delete(request_event.key)
vm_entry = shared.etcd_client.get(
join_path(
settings["etcd"]["vm_prefix"],
request_event.uuid,
)
join_path(settings["etcd"]["vm_prefix"], request_event.uuid)
)
logger.debug("VM hostname: {}".format(vm_entry.value))
vm = virtualmachine.VM(vm_entry)
if request_event.type == RequestType.StartVM:
vm.start()
if vm_entry:
vm = virtualmachine.VM(vm_entry)
if request_event.type == RequestType.StartVM:
vm.start()
elif request_event.type == RequestType.StopVM:
vm.stop()
elif request_event.type == RequestType.StopVM:
vm.stop()
elif request_event.type == RequestType.DeleteVM:
vm.delete()
elif request_event.type == RequestType.DeleteVM:
vm.delete()
elif request_event.type == RequestType.InitVMMigration:
vm.start(destination_host_key=host.key)
elif (
request_event.type
== RequestType.InitVMMigration
):
vm.start(destination_host_key=host.key)
elif request_event.type == RequestType.TransferVM:
host = host_pool.get(
request_event.destination_host_key
elif request_event.type == RequestType.TransferVM:
destination_host = host_pool.get(request_event.destination_host_key)
if destination_host:
vm.migrate(
destination_host=destination_host.hostname,
destination_sock_path=request_event.destination_sock_path,
)
if host:
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:
logger.info("VM Entry missing")
else:
logger.error("Host %s not found!", request_event.destination_host_key)
if __name__ == "__main__":