add mechanism to handle already created vms
This commit is contained in:
parent
5adb3b2d8e
commit
c08aad01df
1 changed files with 11 additions and 7 deletions
18
main.py
18
main.py
|
@ -1,8 +1,7 @@
|
|||
# TODO
|
||||
# 1. on startup check if there is any VM with status REQUESTED_NEW already
|
||||
# 2. send an email to an email address defined by env['admin-email']
|
||||
# 1. send an email to an email address defined by env['admin-email']
|
||||
# if resources are finished
|
||||
# 3. v3) Introduce a status endpoint of the scheduler -
|
||||
# 2. v3) Introduce a status endpoint of the scheduler -
|
||||
# maybe expose a prometheus compatible output
|
||||
|
||||
import json
|
||||
|
@ -146,7 +145,11 @@ def assign_host(client, vm_prefix, host_prefix, e):
|
|||
client, vm_prefix, host_prefix, e.value["specs"]
|
||||
)
|
||||
if host_name:
|
||||
e.value["status"] = "SCHEDULED_DEPLOY"
|
||||
if e.value["status"] == "REQUESTED_NEW":
|
||||
e.value["status"] = "SCHEDULED_DEPLOY"
|
||||
else:
|
||||
e.value["status"] = "REQUESTED_START"
|
||||
|
||||
e.value["hostname"] = host_name
|
||||
client.put(e.key, json.dumps(e.value))
|
||||
return host_name
|
||||
|
@ -181,11 +184,12 @@ def main(vm_prefix, host_prefix):
|
|||
|
||||
if RESCAN_VMS:
|
||||
RESCAN_VMS = False # Assume we won't need it after this
|
||||
vms = client.get_prefix(vm_prefix, value_in_json=True)
|
||||
vms = client.get_prefix(vm_prefix)
|
||||
|
||||
for vm in vms:
|
||||
fake_e = EtcdEntry(
|
||||
PseudoEtcdMeta(key=vm.key.encode("utf-8")), value=vm.value
|
||||
PseudoEtcdMeta(key=vm.key.encode("utf-8")),
|
||||
value=vm.value.encode("utf-8"), value_in_json=True
|
||||
)
|
||||
if (assign_host(client, vm_prefix, host_prefix,
|
||||
fake_e) is None):
|
||||
|
@ -193,7 +197,7 @@ def main(vm_prefix, host_prefix):
|
|||
# to schedule
|
||||
RESCAN_VMS = True
|
||||
|
||||
elif e_status == "REQUESTED_NEW":
|
||||
elif e_status in ["REQUESTED_NEW", "REQUESTED_START"]:
|
||||
if assign_host(client, vm_prefix, host_prefix, e) is None:
|
||||
print("No Resource Left. Emailing admin....")
|
||||
RESCAN_VMS = True
|
||||
|
|
Loading…
Reference in a new issue