Add disable forcing to CLI

References #148
This commit is contained in:
Joshua Boniface 2021-11-06 04:02:09 -04:00
parent 739b60b91e
commit 5a5e5da663
2 changed files with 17 additions and 6 deletions

View File

@ -369,7 +369,7 @@ def vm_remove(config, vm, delete_disks=False):
return retstatus, response.json().get("message", "") 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 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 arguments: state={state}, wait={wait}
API schema: {"message":"{data}"} 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) response = call_api(config, "post", "/vm/{vm}/state".format(vm=vm), params=params)
if response.status_code == 200: if response.status_code == 200:

View File

@ -1308,15 +1308,22 @@ def vm_stop(domain, confirm_flag):
############################################################################### ###############################################################################
@click.command(name="disable", short_help="Mark a virtual machine as disabled.") @click.command(name="disable", short_help="Mark a virtual machine as disabled.")
@click.argument("domain") @click.argument("domain")
@click.option(
"--force",
"force",
is_flag=True,
default=False,
help="Forcibly stop the VM instead of waiting for shutdown.",
)
@cluster_req @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) cleanup(retcode, retmsg)