From 85cff6eb89cce427ceedb7785de99a3fd878e0fd Mon Sep 17 00:00:00 2001 From: Ahmed Bilal Khalid Date: Thu, 12 Sep 2019 22:31:39 +0500 Subject: [PATCH] a --- main.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index ac78058..ce3d6d8 100755 --- a/main.py +++ b/main.py @@ -6,25 +6,25 @@ import logging +from ucloud_common.request import RequestEntry, RequestType + 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, NoSuitableHostFound) -pending_vms = [] def main(): - global pending_vms + pending_vms = [] for request_iterator in [ - client.get_prefix(request_prefix, value_in_json=True), - client.watch_prefix(request_prefix, timeout=5, value_in_json=True), + client.get_prefix(request_prefix, value_in_json=True), + client.watch_prefix(request_prefix, timeout=5, value_in_json=True), ]: for request_event in request_iterator: request_entry = RequestEntry(request_event) - logging.debug("{}, {}".format(request_entry.key, request_entry.value)) + logging.debug("%s, %s", request_entry.key, request_entry.value) # Never Run time critical mechanism inside timeout # mechanism because timeout mechanism only comes @@ -36,7 +36,7 @@ def main(): # to "DEAD", and their VMs' status to "KILLED" logging.debug("TIMEOUT event occured") dead_hosts = dead_host_detection() - logging.debug("Dead hosts: {}".format(dead_hosts)) + logging.debug("Dead hosts: %s", dead_hosts) dead_host_mitigation(dead_hosts) # If there are VMs that weren't assigned a host @@ -60,10 +60,11 @@ def main(): if hasattr(request_entry, "migration") and request_entry.migration \ and hasattr(request_entry, "destination") and request_entry.destination: try: - get_suitable_host(vm_entry.specs, [host_pool.get(request_entry.destination)]) + get_suitable_host(vm_specs=vm_entry.specs, + hosts=[host_pool.get(request_entry.destination)]) except NoSuitableHostFound: logging.info("Requested destination host doesn't have enough capacity" - "to hold {}".format(vm_entry.uuid)) + "to hold %s", vm_entry.uuid) else: r = RequestEntry.from_scratch(type=RequestType.InitVMMigration, uuid=request_entry.uuid, @@ -84,5 +85,5 @@ def main(): logging.info("No Resource Left. Emailing admin....") -logging.info("{} SESSION STARTED {}".format('*' * 5, '*' * 5)) +logging.info("%s SESSION STARTED %s", '*' * 5, '*' * 5) main()