This commit is contained in:
ahmadbilalkhalid 2019-09-12 21:38:12 +05:00
commit e79363e4a3
4 changed files with 165 additions and 254 deletions

14
main.py
View file

@ -24,19 +24,19 @@ def main():
]:
for request_event in request_iterator:
request_entry = RequestEntry(request_event)
logging.debug(f"{request_entry.key}, {request_entry.value}")
logging.debug("{}, {}".format(request_entry.key, request_entry.value))
# Never Run time critical mechanism inside timeout
# mechanism because timeout mechanism only comes
# when no other event is happening. It means under
# heavy load there would not be a timeout event.
if request_entry.type == "TIMEOUT":
if request_entry._type == "TIMEOUT":
# Detect hosts that are dead and set their status
# to "DEAD", and their VMs' status to "KILLED"
logging.debug("TIMEOUT event occured")
dead_hosts = dead_host_detection()
logging.debug(f"Dead hosts: {dead_hosts}")
logging.debug("Dead hosts: {}".format(dead_hosts))
dead_host_mitigation(dead_hosts)
# If there are VMs that weren't assigned a host
@ -46,12 +46,12 @@ def main():
# on our behalf.
while pending_vms:
pending_vm_entry = pending_vms.pop()
r = RequestEntry.from_scratch(type=f"ScheduleVM",
r = RequestEntry.from_scratch(type="ScheduleVM",
uuid=pending_vm_entry.uuid,
hostname=pending_vm_entry.hostname)
request_pool.put(r)
elif request_entry.type == RequestType.ScheduleVM:
elif request_entry._type == RequestType.ScheduleVM:
vm_entry = vm_pool.get(request_entry.uuid)
client.client.delete(request_entry.key) # consume Request
@ -63,7 +63,7 @@ def main():
get_suitable_host(vm_entry.specs, [host_pool.get(request_entry.destination)])
except NoSuitableHostFound:
logging.info("Requested destination host doesn't have enough capacity"
f"to hold {vm_entry.uuid}")
"to hold {}".format(vm_entry.uuid))
else:
r = RequestEntry.from_scratch(type=RequestType.InitVMMigration,
uuid=request_entry.uuid,
@ -84,5 +84,5 @@ def main():
logging.info("No Resource Left. Emailing admin....")
logging.info(f"{'*' * 5} SESSION STARTED {'*' * 5}")
logging.info("{} SESSION STARTED {}".format('*' * 5, '*' * 5))
main()