From d1797ed2bb0500f813796d8cd71aaef5b614e9aa Mon Sep 17 00:00:00 2001 From: Arya Rizky Date: Fri, 15 May 2026 22:06:02 +0700 Subject: [PATCH] feat: honour ONTAP_TIMEOUT env var in OntapClient.from_env() Reads optional ONTAP_TIMEOUT environment variable (defaults to 30s) and passes it as the timeout argument to the OntapClient constructor. - Updated from_env() classmethod to read ONTAP_TIMEOUT - Updated docstring to document the new env var - Updated python/README.md with ONTAP_TIMEOUT usage examples Closes #35 --- python/README.md | 8 ++++++++ python/ontap_client.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/python/README.md b/python/README.md index 7146da6..fc5ff0e 100644 --- a/python/README.md +++ b/python/README.md @@ -62,6 +62,14 @@ set -a && source cluster.env && set +a > SSL verification is disabled by default to support environments that use > self-signed certificates. We recommend setting `ONTAP_VERIFY_SSL=true` > once CA-signed certificates are in place. +> +> The request timeout defaults to 30 seconds. Set `ONTAP_TIMEOUT` (in seconds) +> to adjust this for your environment: +> +> ```bash +> export ONTAP_TIMEOUT=10 # fail fast in CI +> export ONTAP_TIMEOUT=60 # allow extra time for slow clusters +> ``` --- diff --git a/python/ontap_client.py b/python/ontap_client.py index 1f9e41e..9a100af 100644 --- a/python/ontap_client.py +++ b/python/ontap_client.py @@ -110,7 +110,8 @@ def from_env(cls) -> OntapClient: Optional (with defaults): ``ONTAP_USER`` (default ``admin``), - ``ONTAP_VERIFY_SSL`` (default ``false``) + ``ONTAP_VERIFY_SSL`` (default ``false``), + ``ONTAP_TIMEOUT`` (default ``30`` seconds) """ host = os.environ.get("ONTAP_HOST", "") if not host: @@ -121,11 +122,14 @@ def from_env(cls) -> OntapClient: logger.error("ONTAP_PASS environment variable is required") sys.exit(1) + timeout = int(os.environ.get("ONTAP_TIMEOUT", str(_DEFAULT_TIMEOUT))) + return cls( host=host, username=os.environ.get("ONTAP_USER", "admin"), password=password, verify_ssl=os.environ.get("ONTAP_VERIFY_SSL", "false").lower() == "true", + timeout=timeout, ) # -- HTTP helpers -------------------------------------------------------