small bug fix i.e previously updating vm['host'] instead of vm['hostname'] + update status of non-stopped vms on dead host to REQUESTED_NEW

This commit is contained in:
ahmadbilalkhalid 2019-07-25 13:07:59 +05:00
parent 3739b299f1
commit dd3b9fe1cb

11
main.py
View file

@ -80,15 +80,15 @@ def get_suitable_host(etcd_client, vm_prefix, host_prefix, vm_specs):
running_vms_specs = [vm[1]["specs"] for vm in vms] running_vms_specs = [vm[1]["specs"] for vm in vms]
# Accumulate all of their combined specs # Accumulate all of their combined specs
running_vms_accumulated_specs = accumulated_specs(running_vms_specs) running_vms_accumulated_specs = accumulated_specs(running_vms_specs)
print(running_vms_accumulated_specs) # print(running_vms_accumulated_specs)
# Find out remaining resources after # Find out remaining resources after
# host_specs - already running vm_specs # host_specs - already running vm_specs
print(host_value) # print(host_value)
remaining = remaining_resources( remaining = remaining_resources(
host_value["specs"], running_vms_accumulated_specs host_value["specs"], running_vms_accumulated_specs
) )
print(remaining) # print(remaining)
# Find out remaining - new_vm_specs # Find out remaining - new_vm_specs
remaining = remaining_resources(remaining, vm_specs) remaining = remaining_resources(remaining, vm_specs)
# if remaining resources >= 0 return this host_name # if remaining resources >= 0 return this host_name
@ -135,8 +135,9 @@ def dead_host_mitigation(client: Etcd3Wrapper, dead_hosts_keys):
lambda _vm: _vm.value["hostname"] == host_key, all_vms lambda _vm: _vm.value["hostname"] == host_key, all_vms
) )
for vm in vms_hosted_on_dead_host: for vm in vms_hosted_on_dead_host:
vm.value["host"] = "" vm.value["hostname"] = ""
vm.value["status"] = "REQUESTED_START" if vm.value["status"] != "STOPPED":
vm.value["status"] = "REQUESTED_NEW"
client.put(vm.key, vm.value, value_in_json=True) client.put(vm.key, vm.value, value_in_json=True)