a
This commit is contained in:
parent
e70270041a
commit
e09e5fd298
3 changed files with 28 additions and 29 deletions
33
helper.py
33
helper.py
|
|
@ -28,6 +28,11 @@ def remaining_resources(host_specs, vms_specs):
|
|||
return remaining
|
||||
|
||||
|
||||
class NoSuitableHostFound(Exception):
|
||||
"""Raise this exception when no host found
|
||||
that can host a VM"""
|
||||
|
||||
|
||||
def get_suitable_host(vm_specs, hosts=None):
|
||||
if hosts is None:
|
||||
hosts = host_pool.by_status(HostStatus.alive)
|
||||
|
|
@ -62,7 +67,7 @@ def get_suitable_host(vm_specs, hosts=None):
|
|||
):
|
||||
return host.key
|
||||
|
||||
return None
|
||||
raise NoSuitableHostFound
|
||||
|
||||
|
||||
def dead_host_detection():
|
||||
|
|
@ -92,23 +97,13 @@ def dead_host_mitigation(dead_hosts_keys):
|
|||
|
||||
|
||||
def assign_host(vm):
|
||||
host_name = get_suitable_host(vm.specs)
|
||||
if host_name:
|
||||
# if vm.status == VMStatus.requested_new:
|
||||
# vm.status = VMStatus.scheduled_deploy
|
||||
#
|
||||
# if vm.status == VMStatus.killed:
|
||||
# vm.status = VMStatus.requested_start
|
||||
vm.hostname = get_suitable_host(vm.specs)
|
||||
vm_pool.put(vm)
|
||||
|
||||
vm.hostname = host_name
|
||||
vm_pool.put(vm)
|
||||
r = RequestEntry.from_scratch(type=RequestType.StartVM,
|
||||
uuid=vm.uuid,
|
||||
hostname=vm.hostname)
|
||||
request_pool.put(r)
|
||||
|
||||
r = RequestEntry.from_scratch(type=RequestType.StartVM,
|
||||
uuid=vm.uuid,
|
||||
hostname=vm.hostname)
|
||||
request_pool.put(r)
|
||||
|
||||
vm.log.append("VM scheduled for starting")
|
||||
|
||||
return host_name
|
||||
return None
|
||||
vm.log.append("VM scheduled for starting")
|
||||
return vm.hostname
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue