This commit is contained in:
ahmadbilalkhalid 2019-09-05 15:16:26 +05:00
commit e09e5fd298
3 changed files with 28 additions and 29 deletions

23
main.py
View file

@ -10,7 +10,7 @@ from config import etcd_client as client
from config import (host_pool, request_pool, vm_pool, request_prefix)
from ucloud_common.request import RequestEntry, RequestType
from helper import (get_suitable_host, dead_host_mitigation, dead_host_detection,
assign_host)
assign_host, NoSuitableHostFound)
pending_vms = []
@ -51,29 +51,32 @@ def main():
hostname=pending_vm_entry.hostname)
request_pool.put(r)
logging.debug(f"Remaining Pending: {pending_vms}")
elif request_entry.type == RequestType.ScheduleVM:
vm_entry = vm_pool.get(request_entry.uuid)
client.client.delete(request_entry.key) # consume Request
# If Request is about a VM which is labelled as "migration"
# If the Request is about a VM which is labelled as "migration"
# and has a destination
if hasattr(request_entry, "migration") and request_entry.migration \
and hasattr(request_entry, "destination") and request_entry.destination:
host = get_suitable_host(vm_entry.specs, [host_pool.get(request_entry.destination)])
if host:
try:
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}")
else:
r = RequestEntry.from_scratch(type=RequestType.InitVMMigration,
uuid=request_entry.uuid,
destination=request_entry.destination)
request_pool.put(r)
else:
logging.info("Requested destination host doesn't have enough capacity"
f"to hold {vm_entry.uuid}")
# If the Request is about a VM that just want to get started/created
else:
# assign_host only returns None when we couldn't be able to assign
# a host to a VM because of resource constraints
if assign_host(vm_entry) is None:
try:
assign_host(vm_entry)
except NoSuitableHostFound:
vm_entry.log.append("Can't schedule VM. No Resource Left.")
vm_pool.put(vm_entry)