Apply more granular timeout formatting

We don't need to wait forever if state changes aren't waiting or disable
(which does a shutdown before returning).
This commit is contained in:
Joshua Boniface 2021-11-06 13:26:55 -04:00
parent 87ec31c023
commit 21b4bbe51a
1 changed files with 6 additions and 1 deletions

View File

@ -377,13 +377,18 @@ def vm_state(config, vm, target_state, force=False, wait=False):
API arguments: state={state}, wait={wait} API arguments: state={state}, wait={wait}
API schema: {"message":"{data}"} API schema: {"message":"{data}"}
""" """
if wait or target_state == "disable":
timeout = 300
else:
timeout = 3
params = { params = {
"state": target_state, "state": target_state,
"force": str(force).lower(), "force": str(force).lower(),
"wait": str(wait).lower(), "wait": str(wait).lower(),
} }
response = call_api( response = call_api(
config, "post", "/vm/{vm}/state".format(vm=vm), params=params, timeout=120 config, "post", "/vm/{vm}/state".format(vm=vm), params=params, timeout=timeout
) )
if response.status_code == 200: if response.status_code == 200: