a
This commit is contained in:
parent
e79363e4a3
commit
85cff6eb89
1 changed files with 11 additions and 10 deletions
21
main.py
21
main.py
|
|
@ -6,25 +6,25 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from ucloud_common.request import RequestEntry, RequestType
|
||||||
|
|
||||||
from config import etcd_client as client
|
from config import etcd_client as client
|
||||||
from config import (host_pool, request_pool, vm_pool, request_prefix)
|
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,
|
from helper import (get_suitable_host, dead_host_mitigation, dead_host_detection,
|
||||||
assign_host, NoSuitableHostFound)
|
assign_host, NoSuitableHostFound)
|
||||||
|
|
||||||
pending_vms = []
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global pending_vms
|
pending_vms = []
|
||||||
|
|
||||||
for request_iterator in [
|
for request_iterator in [
|
||||||
client.get_prefix(request_prefix, value_in_json=True),
|
client.get_prefix(request_prefix, value_in_json=True),
|
||||||
client.watch_prefix(request_prefix, timeout=5, value_in_json=True),
|
client.watch_prefix(request_prefix, timeout=5, value_in_json=True),
|
||||||
]:
|
]:
|
||||||
for request_event in request_iterator:
|
for request_event in request_iterator:
|
||||||
request_entry = RequestEntry(request_event)
|
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
|
# Never Run time critical mechanism inside timeout
|
||||||
# mechanism because timeout mechanism only comes
|
# mechanism because timeout mechanism only comes
|
||||||
|
|
@ -36,7 +36,7 @@ def main():
|
||||||
# to "DEAD", and their VMs' status to "KILLED"
|
# to "DEAD", and their VMs' status to "KILLED"
|
||||||
logging.debug("TIMEOUT event occured")
|
logging.debug("TIMEOUT event occured")
|
||||||
dead_hosts = dead_host_detection()
|
dead_hosts = dead_host_detection()
|
||||||
logging.debug("Dead hosts: {}".format(dead_hosts))
|
logging.debug("Dead hosts: %s", dead_hosts)
|
||||||
dead_host_mitigation(dead_hosts)
|
dead_host_mitigation(dead_hosts)
|
||||||
|
|
||||||
# If there are VMs that weren't assigned a host
|
# 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 \
|
if hasattr(request_entry, "migration") and request_entry.migration \
|
||||||
and hasattr(request_entry, "destination") and request_entry.destination:
|
and hasattr(request_entry, "destination") and request_entry.destination:
|
||||||
try:
|
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:
|
except NoSuitableHostFound:
|
||||||
logging.info("Requested destination host doesn't have enough capacity"
|
logging.info("Requested destination host doesn't have enough capacity"
|
||||||
"to hold {}".format(vm_entry.uuid))
|
"to hold %s", vm_entry.uuid)
|
||||||
else:
|
else:
|
||||||
r = RequestEntry.from_scratch(type=RequestType.InitVMMigration,
|
r = RequestEntry.from_scratch(type=RequestType.InitVMMigration,
|
||||||
uuid=request_entry.uuid,
|
uuid=request_entry.uuid,
|
||||||
|
|
@ -84,5 +85,5 @@ def main():
|
||||||
logging.info("No Resource Left. Emailing admin....")
|
logging.info("No Resource Left. Emailing admin....")
|
||||||
|
|
||||||
|
|
||||||
logging.info("{} SESSION STARTED {}".format('*' * 5, '*' * 5))
|
logging.info("%s SESSION STARTED %s", '*' * 5, '*' * 5)
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue