From d76da0f25a41152ef06b1aad3e1799e1c21f0f23 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 8 Nov 2021 03:04:24 -0500 Subject: [PATCH] Use separate connect and data timeouts This allows us to keep a very low connect timeout of 3 seconds, but also ensure that long commands (e.g. --wait or VM disable) can take as long as the API requires to complete. Avoids having to explicitly set very long single-instance timeouts for other functions which would block forever on an unreachable API. --- client-cli/pvc/cli_lib/common.py | 4 +++- client-cli/pvc/cli_lib/vm.py | 9 +-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/client-cli/pvc/cli_lib/common.py b/client-cli/pvc/cli_lib/common.py index dbdc954f..94117114 100644 --- a/client-cli/pvc/cli_lib/common.py +++ b/client-cli/pvc/cli_lib/common.py @@ -123,8 +123,10 @@ def call_api( params=None, data=None, files=None, - timeout=3, ): + # Set the connect timeout to 3 seconds but extremely long (48 hour) data timeout + timeout = (3, 172800) + # Craft the URI uri = "{}://{}{}{}".format( config["api_scheme"], config["api_host"], config["api_prefix"], request_uri diff --git a/client-cli/pvc/cli_lib/vm.py b/client-cli/pvc/cli_lib/vm.py index c94ea5b2..c8c75ad5 100644 --- a/client-cli/pvc/cli_lib/vm.py +++ b/client-cli/pvc/cli_lib/vm.py @@ -377,19 +377,12 @@ def vm_state(config, vm, target_state, force=False, wait=False): API arguments: state={state}, wait={wait} API schema: {"message":"{data}"} """ - if wait or target_state == "disable": - timeout = 300 - else: - timeout = 3 - 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=timeout - ) + response = call_api(config, "post", "/vm/{vm}/state".format(vm=vm), params=params) if response.status_code == 200: retstatus = True