Add guard rails against manipulating mirrors
Snapshot mirrors should normally be promoted using "mirror promote", and not started manually. This adds guard rails against that to the "start", "stop", and "disable" state commands to prevent changing mirror states without an explicit "--force" option.
This commit is contained in:
@ -2645,7 +2645,7 @@ class API_VM_State(Resource):
|
||||
- in: query
|
||||
name: force
|
||||
type: boolean
|
||||
description: Whether to force stop instead of shutdown VM during disable
|
||||
description: For "disable", force stop instead of shutdown and/or force mirror state; for "start" or "stop", force mirror state.
|
||||
- in: query
|
||||
name: wait
|
||||
type: boolean
|
||||
@ -2667,15 +2667,15 @@ class API_VM_State(Resource):
|
||||
wait = bool(strtobool(reqargs.get("wait", "false")))
|
||||
|
||||
if state == "start":
|
||||
return api_helper.vm_start(vm)
|
||||
return api_helper.vm_start(vm, force=force)
|
||||
if state == "shutdown":
|
||||
return api_helper.vm_shutdown(vm, wait)
|
||||
if state == "stop":
|
||||
return api_helper.vm_stop(vm)
|
||||
return api_helper.vm_stop(vm, force=force)
|
||||
if state == "restart":
|
||||
return api_helper.vm_restart(vm, wait)
|
||||
if state == "disable":
|
||||
return api_helper.vm_disable(vm, force)
|
||||
return api_helper.vm_disable(vm, force=force)
|
||||
abort(400)
|
||||
|
||||
|
||||
|
@ -1153,11 +1153,11 @@ def vm_remove(zkhandler, name):
|
||||
|
||||
|
||||
@ZKConnection(config)
|
||||
def vm_start(zkhandler, name):
|
||||
def vm_start(zkhandler, name, force=False):
|
||||
"""
|
||||
Start a VM in the PVC cluster.
|
||||
"""
|
||||
retflag, retdata = pvc_vm.start_vm(zkhandler, name)
|
||||
retflag, retdata = pvc_vm.start_vm(zkhandler, name, force=force)
|
||||
|
||||
if retflag:
|
||||
retcode = 200
|
||||
@ -1201,11 +1201,11 @@ def vm_shutdown(zkhandler, name, wait):
|
||||
|
||||
|
||||
@ZKConnection(config)
|
||||
def vm_stop(zkhandler, name):
|
||||
def vm_stop(zkhandler, name, force=False):
|
||||
"""
|
||||
Forcibly stop a VM in the PVC cluster.
|
||||
"""
|
||||
retflag, retdata = pvc_vm.stop_vm(zkhandler, name)
|
||||
retflag, retdata = pvc_vm.stop_vm(zkhandler, name, force=force)
|
||||
|
||||
if retflag:
|
||||
retcode = 200
|
||||
@ -1219,7 +1219,7 @@ def vm_stop(zkhandler, name):
|
||||
@ZKConnection(config)
|
||||
def vm_disable(zkhandler, name, force=False):
|
||||
"""
|
||||
Disable (shutdown or force stop if required)a 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, force=force)
|
||||
|
||||
|
Reference in New Issue
Block a user