From c766648ed07f53e5b455f4691bb4289324f2b37e Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Wed, 11 Sep 2024 10:12:29 -0400 Subject: [PATCH] Add "mirror" VM state --- api-daemon/pvcapid/helper.py | 2 +- client-cli/pvc/cli/formatters.py | 6 +++--- client-cli/pvc/lib/vm.py | 1 + daemon-common/cluster.py | 1 + daemon-common/common.py | 1 + daemon-common/vm.py | 9 +++++---- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/api-daemon/pvcapid/helper.py b/api-daemon/pvcapid/helper.py index c4fc4cb3..85842976 100755 --- a/api-daemon/pvcapid/helper.py +++ b/api-daemon/pvcapid/helper.py @@ -1280,7 +1280,7 @@ def vm_flush_locks(zkhandler, vm): zkhandler, None, None, None, vm, is_fuzzy=False, negate=False ) - if retdata[0].get("state") not in ["stop", "disable"]: + if retdata[0].get("state") not in ["stop", "disable", "mirror"]: return {"message": "VM must be stopped to flush locks"}, 400 retflag, retdata = pvc_vm.flush_locks(zkhandler, vm) diff --git a/client-cli/pvc/cli/formatters.py b/client-cli/pvc/cli/formatters.py index ca55a633..12daf97e 100644 --- a/client-cli/pvc/cli/formatters.py +++ b/client-cli/pvc/cli/formatters.py @@ -206,12 +206,12 @@ def cli_cluster_status_format_pretty(CLI_CONFIG, data): output.append(f"{ansii['purple']}Nodes:{ansii['end']} {nodes_string}") - vm_states = ["start", "disable"] + vm_states = ["start", "disable", "mirror"] vm_states.extend( [ state for state in data.get("vms", {}).keys() - if state not in ["total", "start", "disable"] + if state not in ["total", "start", "disable", "mirror"] ] ) @@ -221,7 +221,7 @@ def cli_cluster_status_format_pretty(CLI_CONFIG, data): continue if state in ["start"]: state_colour = ansii["green"] - elif state in ["migrate", "disable", "provision"]: + elif state in ["migrate", "disable", "provision", "mirror"]: state_colour = ansii["blue"] elif state in ["stop", "fail"]: state_colour = ansii["red"] diff --git a/client-cli/pvc/lib/vm.py b/client-cli/pvc/lib/vm.py index e8811817..ce1e92d0 100644 --- a/client-cli/pvc/lib/vm.py +++ b/client-cli/pvc/lib/vm.py @@ -1760,6 +1760,7 @@ def format_info(config, domain_information, long_output): "provision": ansiprint.blue(), "restore": ansiprint.blue(), "import": ansiprint.blue(), + "mirror": ansiprint.blue(), } ainformation.append( "{}State:{} {}{}{}".format( diff --git a/daemon-common/cluster.py b/daemon-common/cluster.py index 614869e3..b85f1dcb 100644 --- a/daemon-common/cluster.py +++ b/daemon-common/cluster.py @@ -1160,6 +1160,7 @@ def get_resource_metrics(zkhandler): "fail": 8, "import": 9, "restore": 10, + "mirror": 99, } state = vm["state"] output_lines.append( diff --git a/daemon-common/common.py b/daemon-common/common.py index d1cb0bb5..c8e48569 100644 --- a/daemon-common/common.py +++ b/daemon-common/common.py @@ -85,6 +85,7 @@ vm_state_combinations = [ "provision", "import", "restore", + "mirror", ] ceph_osd_state_combinations = [ "up,in", diff --git a/daemon-common/vm.py b/daemon-common/vm.py index d7add399..88f733cf 100644 --- a/daemon-common/vm.py +++ b/daemon-common/vm.py @@ -580,7 +580,7 @@ def rename_vm(zkhandler, domain, new_domain): # Verify that the VM is in a stopped state; renaming is not supported otherwise state = zkhandler.read(("domain.state", dom_uuid)) - if state not in ["stop", "disable"]: + if state not in ["stop", "disable", "mirror"]: return ( False, 'ERROR: VM "{}" is not in stopped state; VMs cannot be renamed while running.'.format( @@ -1125,6 +1125,7 @@ def get_list( "migrate", "unmigrate", "provision", + "mirror", ] if state not in valid_states: return False, 'VM state "{}" is not valid.'.format(state) @@ -1903,10 +1904,10 @@ def vm_worker_flush_locks(zkhandler, celery, domain, force_unlock=False): # Check that the domain is stopped (unless force_unlock is set) domain_state = zkhandler.read(("domain.state", dom_uuid)) - if not force_unlock and domain_state not in ["stop", "disable", "fail"]: + if not force_unlock and domain_state not in ["stop", "disable", "fail", "mirror"]: fail( celery, - f"VM state {domain_state} not in [stop, disable, fail] and not forcing", + f"VM state {domain_state} not in [stop, disable, fail, mirror] and not forcing", ) return False @@ -2329,7 +2330,7 @@ def vm_worker_rollback_snapshot(zkhandler, celery, domain, snapshot_name): # Verify that the VM is in a stopped state; renaming is not supported otherwise state = zkhandler.read(("domain.state", dom_uuid)) - if state not in ["stop", "disable"]: + if state not in ["stop", "disable", "mirror"]: fail( celery, f"VM '{domain}' is not stopped or disabled; VMs cannot be rolled back while running",