Compare commits

..

No commits in common. "1cf8706a52409f7c91e09d2cde2fb8d6e5c6ae03" and "16544227ebf99c2540569fd51635f22bf8199fbf" have entirely different histories.

7 changed files with 22 additions and 59 deletions

View File

@ -1868,7 +1868,6 @@ class API_VM_State(Resource):
"helptext": "A valid state must be specified",
"required": True,
},
{"name": "force"},
{"name": "wait"},
]
)
@ -1891,10 +1890,6 @@ 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
@ -1912,7 +1907,6 @@ 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":
@ -1924,7 +1918,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, force)
return api_helper.vm_disable(vm)
abort(400)

View File

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

View File

@ -116,20 +116,16 @@ class ErrorResponse(requests.Response):
def call_api(
config,
operation,
request_uri,
headers={},
params=None,
data=None,
files=None,
timeout=3,
config, operation, request_uri, headers={}, params=None, data=None, files=None
):
# Craft the URI
uri = "{}://{}{}{}".format(
config["api_scheme"], config["api_host"], config["api_prefix"], request_uri
)
# Default timeout is 3 seconds
timeout = 3
# Craft the authentication header if required
if config["api_key"]:
headers["X-Api-Key"] = config["api_key"]

View File

@ -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, force=False, wait=False):
def vm_state(config, vm, target_state, wait=False):
"""
Modify the current state of VM
@ -377,14 +377,8 @@ def vm_state(config, vm, target_state, force=False, wait=False):
API arguments: state={state}, wait={wait}
API schema: {"message":"{data}"}
"""
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, timeout=120
)
params = {"state": target_state, "wait": str(wait).lower()}
response = call_api(config, "post", "/vm/{vm}/state".format(vm=vm), params=params)
if response.status_code == 200:
retstatus = True

View File

@ -1308,22 +1308,15 @@ 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, force):
def vm_disable(domain):
"""
Shut down virtual machine DOMAIN and mark it as disabled. DOMAIN may be a UUID or name.
Prevent stopped virtual machine DOMAIN from being counted towards cluster health status. DOMAIN may be a UUID or name.
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.
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.
"""
retcode, retmsg = pvc_vm.vm_state(config, domain, "disable", force=force)
retcode, retmsg = pvc_vm.vm_state(config, domain, "disable")
cleanup(retcode, retmsg)

View File

@ -837,29 +837,21 @@ def stop_vm(zkhandler, domain):
return True, 'Forcibly stopping VM "{}".'.format(domain)
def disable_vm(zkhandler, domain, force=False):
def disable_vm(zkhandler, domain):
# Validate that VM exists in cluster
dom_uuid = getDomainUUID(zkhandler, domain)
if not dom_uuid:
return False, 'ERROR: Could not find VM "{}" in the cluster!'.format(domain)
# Get state and perform a shutdown/stop if VM is online
# Get state and verify we're OK to proceed
current_state = zkhandler.read(("domain.state", dom_uuid))
if current_state in ["start"]:
if force:
change_state(zkhandler, dom_uuid, "stop")
# Wait for the command to be registered by the node
time.sleep(0.5)
else:
change_state(zkhandler, dom_uuid, "shutdown")
# Wait for the shutdown to complete
while zkhandler.read(("domain.state", dom_uuid)) != "stop":
time.sleep(0.5)
if current_state != "stop":
return False, 'ERROR: VM "{}" must be stopped before disabling!'.format(domain)
# Set the VM to disable
change_state(zkhandler, dom_uuid, "disable")
return True, 'Disabled VM "{}".'.format(domain)
return True, 'Marked VM "{}" as disable.'.format(domain)
def update_vm_sriov_nics(zkhandler, dom_uuid, source_node, target_node):

View File

@ -6680,12 +6680,6 @@
"required": true,
"type": "string"
},
{
"description": "Whether to force stop instead of shutdown VM during disable",
"in": "query",
"name": "force",
"type": "boolean"
},
{
"description": "Whether to block waiting for the state change to complete",
"in": "query",