Up timeout when setting VM state

Ensures the API won't time out immediately especially during a
wait-flagged or disable action.
This commit is contained in:
Joshua Boniface 2021-11-06 04:15:10 -04:00
parent 0d857d5ab8
commit 87ec31c023
2 changed files with 11 additions and 5 deletions

View File

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

View File

@ -382,7 +382,9 @@ def vm_state(config, vm, target_state, force=False, wait=False):
"force": str(force).lower(), "force": str(force).lower(),
"wait": str(wait).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, timeout=120
)
if response.status_code == 200: if response.status_code == 200:
retstatus = True retstatus = True