check any pending vm scheduling on start
This commit is contained in:
parent
f078b9b245
commit
eb015de8f1
1 changed files with 26 additions and 26 deletions
52
main.py
52
main.py
|
@ -144,36 +144,36 @@ def main(vm_prefix, host_prefix):
|
|||
host=config("ETCD_HOST"), port=int(config("ETCD_PORT"))
|
||||
)
|
||||
|
||||
events_iterator = client.watch_prefix(vm_prefix, timeout=10)
|
||||
for events_iterator in [client.get_prefix(vm_prefix),
|
||||
client.watch_prefix(vm_prefix, timeout=10)]:
|
||||
for e in events_iterator:
|
||||
try:
|
||||
e.value = json.loads(e.value)
|
||||
except json.JSONDecodeError:
|
||||
logging.error(f"Invalid JSON {e.value}")
|
||||
continue
|
||||
|
||||
for e in events_iterator:
|
||||
try:
|
||||
e.value = json.loads(e.value)
|
||||
except json.JSONDecodeError:
|
||||
logging.error(f"Invalid JSON {e.value}")
|
||||
continue
|
||||
logging.debug(e.key, e.value)
|
||||
|
||||
logging.debug(e.key, e.value)
|
||||
e_status = e.value["status"]
|
||||
|
||||
e_status = e.value["status"]
|
||||
if e_status == "TIMEOUT":
|
||||
logging.info("Timeout")
|
||||
hosts = client.get_prefix(host_prefix, value_in_json=True)
|
||||
dead_hosts = dead_host_detection(hosts)
|
||||
dead_host_mitigation(client, dead_hosts)
|
||||
|
||||
if e_status == "TIMEOUT":
|
||||
logging.info("Timeout")
|
||||
hosts = client.get_prefix(host_prefix, value_in_json=True)
|
||||
dead_hosts = dead_host_detection(hosts)
|
||||
dead_host_mitigation(client, dead_hosts)
|
||||
|
||||
elif e_status == "REQUESTED_NEW":
|
||||
host_name = get_suitable_host(
|
||||
client, vm_prefix, host_prefix, e.value["specs"]
|
||||
)
|
||||
if host_name:
|
||||
e.value["status"] = "SCHEDULED_DEPLOY"
|
||||
e.value["hostname"] = host_name
|
||||
client.put(e.key, json.dumps(e.value))
|
||||
else:
|
||||
# email admin
|
||||
print("No Resource Left. Emailing admin....")
|
||||
elif e_status == "REQUESTED_NEW":
|
||||
host_name = get_suitable_host(
|
||||
client, vm_prefix, host_prefix, e.value["specs"]
|
||||
)
|
||||
if host_name:
|
||||
e.value["status"] = "SCHEDULED_DEPLOY"
|
||||
e.value["hostname"] = host_name
|
||||
client.put(e.key, json.dumps(e.value))
|
||||
else:
|
||||
# email admin
|
||||
print("No Resource Left. Emailing admin....")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue