at exit set running vm status to requested_start
This commit is contained in:
parent
cbcbbdd9d7
commit
0d443ab285
3 changed files with 37 additions and 2 deletions
8
main.py
8
main.py
|
@ -21,6 +21,7 @@ from typing import Union
|
|||
from functools import wraps
|
||||
from decouple import config
|
||||
from datetime import datetime
|
||||
from ucloud_common.enums import VMStatus
|
||||
|
||||
running_vms = []
|
||||
vnc_port_pool = list(range(0, 100))
|
||||
|
@ -65,11 +66,14 @@ def goodbye(host):
|
|||
vms = filter(lambda v: v.value["hostname"] == host.key, vms)
|
||||
for vm in vms:
|
||||
vm.value["hostname"] = ""
|
||||
if vm.value["status"] != "STOPPED":
|
||||
vm.value["status"] = "REQUESTED_NEW"
|
||||
|
||||
if vm.value["status"] in VMStatus.running_vm_statuses:
|
||||
vm.value["status"] = VMStatus.requested_start
|
||||
|
||||
client.put(vm.key, vm.value, value_in_json=True)
|
||||
|
||||
logging.info(f"Host {host.key} dead! at {host.value['last_heartbeat']}")
|
||||
print("Goodbye")
|
||||
os.kill(os.getpid(), signal.SIGKILL)
|
||||
|
||||
|
||||
|
|
0
ucloud_common/__init__.py
Normal file
0
ucloud_common/__init__.py
Normal file
31
ucloud_common/enums.py
Normal file
31
ucloud_common/enums.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from enum import Enum
|
||||
|
||||
class VMStatus(Enum):
|
||||
# Must be only assigned to brand new VM
|
||||
requested_new = "REQUESTED_NEW"
|
||||
|
||||
# Only Assigned to already created vm
|
||||
requested_start = "REQUESTED_START"
|
||||
|
||||
# These all are for running vms
|
||||
requested_shutdown = "REQUESTED_SHUTDOWN"
|
||||
requested_suspend = "REQUESTED_SUSPEND"
|
||||
requested_resume = "REQUESTED_RESUME"
|
||||
requested_migrate = "REQUESTED_MIGRATE"
|
||||
|
||||
# either its image is not found or user requested
|
||||
# to delete it
|
||||
deleted = "DELETED"
|
||||
|
||||
stopped = "STOPPED" # After requested_shutdown
|
||||
killed = "KILLED" # either host died or vm died itself
|
||||
|
||||
running = "RUNNING"
|
||||
suspended = "SUSPENDED"
|
||||
|
||||
running_vm_statuses = [requested_shutdown, requested_suspend,
|
||||
requested_resume, requested_migrate,
|
||||
running, suspended]
|
||||
class HostStatus(Enum):
|
||||
alive = "ALIVE"
|
||||
dead = "DEAD"
|
Loading…
Reference in a new issue