Perform automatic shutdown/stop on VM disable

Instead of requiring the VM to already be stopped, instead allow disable
state changes to perform a shutdown first. Also add a force option which
will do a hard stop instead of a shutdown.

References #148
This commit is contained in:
2021-11-06 03:53:44 -04:00
parent 78faa90139
commit 5f193a6134
4 changed files with 30 additions and 10 deletions

View File

@ -1868,6 +1868,7 @@ class API_VM_State(Resource):
"helptext": "A valid state must be specified",
"required": True,
},
{"name": "force"},
{"name": "wait"},
]
)
@ -1890,6 +1891,10 @@ class API_VM_State(Resource):
- stop
- restart
- disable
- in: query
name: force
type: boolean
description: Whether to force stop instead of shutdown VM during disable
- in: query
name: wait
type: boolean
@ -1907,6 +1912,7 @@ class API_VM_State(Resource):
id: Message
"""
state = reqargs.get("state", None)
force = bool(strtobool(reqargs.get("force", "false")))
wait = bool(strtobool(reqargs.get("wait", "false")))
if state == "start":
@ -1918,7 +1924,7 @@ class API_VM_State(Resource):
if state == "restart":
return api_helper.vm_restart(vm, wait)
if state == "disable":
return api_helper.vm_disable(vm)
return api_helper.vm_disable(vm, force)
abort(400)

View File

@ -719,11 +719,11 @@ def vm_start(zkhandler, name):
@ZKConnection(config)
def vm_restart(zkhandler, name, wait):
def vm_restart(zkhandler, name, wait=False):
"""
Restart a VM in the PVC cluster.
"""
retflag, retdata = pvc_vm.restart_vm(zkhandler, name, wait)
retflag, retdata = pvc_vm.restart_vm(zkhandler, name, wait=wait)
if retflag:
retcode = 200
@ -767,11 +767,11 @@ def vm_stop(zkhandler, name):
@ZKConnection(config)
def vm_disable(zkhandler, name):
def vm_disable(zkhandler, name, force=False):
"""
Disable a (stopped) VM in the PVC cluster.
Disable (shutdown or force stop if required)a VM in the PVC cluster.
"""
retflag, retdata = pvc_vm.disable_vm(zkhandler, name)
retflag, retdata = pvc_vm.disable_vm(zkhandler, name, force=force)
if retflag:
retcode = 200