From 5a5e5da663b7df9b9261e69c6b08a77332f0c80a Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sat, 6 Nov 2021 04:02:09 -0400 Subject: [PATCH] Add disable forcing to CLI References #148 --- client-cli/pvc/cli_lib/vm.py | 8 ++++++-- client-cli/pvc/pvc.py | 15 +++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/client-cli/pvc/cli_lib/vm.py b/client-cli/pvc/cli_lib/vm.py index 50369ca3..c8c75ad5 100644 --- a/client-cli/pvc/cli_lib/vm.py +++ b/client-cli/pvc/cli_lib/vm.py @@ -369,7 +369,7 @@ def vm_remove(config, vm, delete_disks=False): return retstatus, response.json().get("message", "") -def vm_state(config, vm, target_state, wait=False): +def vm_state(config, vm, target_state, force=False, wait=False): """ Modify the current state of VM @@ -377,7 +377,11 @@ def vm_state(config, vm, target_state, wait=False): API arguments: state={state}, wait={wait} API schema: {"message":"{data}"} """ - params = {"state": target_state, "wait": str(wait).lower()} + params = { + "state": target_state, + "force": str(force).lower(), + "wait": str(wait).lower(), + } response = call_api(config, "post", "/vm/{vm}/state".format(vm=vm), params=params) if response.status_code == 200: diff --git a/client-cli/pvc/pvc.py b/client-cli/pvc/pvc.py index 61044e50..a5da9bc5 100755 --- a/client-cli/pvc/pvc.py +++ b/client-cli/pvc/pvc.py @@ -1308,15 +1308,22 @@ def vm_stop(domain, confirm_flag): ############################################################################### @click.command(name="disable", short_help="Mark a virtual machine as disabled.") @click.argument("domain") +@click.option( + "--force", + "force", + is_flag=True, + default=False, + help="Forcibly stop the VM instead of waiting for shutdown.", +) @cluster_req -def vm_disable(domain): +def vm_disable(domain, force): """ - Prevent stopped virtual machine DOMAIN from being counted towards cluster health status. DOMAIN may be a UUID or name. + Shut down virtual machine DOMAIN and mark it as disabled. DOMAIN may be a UUID or name. - Use this option for VM that are stopped intentionally or long-term and which should not impact cluster health if stopped. A VM can be started directly from disable state. + Disabled VMs will not be counted towards a degraded cluster health status, unlike stopped VMs. Use this option for a VM that will remain off for an extended period. """ - retcode, retmsg = pvc_vm.vm_state(config, domain, "disable") + retcode, retmsg = pvc_vm.vm_state(config, domain, "disable", force=force) cleanup(retcode, retmsg)