From 0ab6f6e0390943ecca53fec52801102e36b37fd7 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 11 Dec 2023 18:52:07 +0100 Subject: [PATCH] Add 5 minute timeout to requests.get() calls. (#18) --- inventory/cloudforms.py | 3 ++- inventory/phpipam_inventory.py | 2 +- inventory/rackhd.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/inventory/cloudforms.py b/inventory/cloudforms.py index c25dd14..d6455d0 100755 --- a/inventory/cloudforms.py +++ b/inventory/cloudforms.py @@ -229,7 +229,8 @@ def _http_request(self, url): ret = requests.get(url, auth=HTTPBasicAuth(self.cloudforms_username, self.cloudforms_pw), - verify=self.cloudforms_ssl_verify) + verify=self.cloudforms_ssl_verify, + timeout=300) ret.raise_for_status() diff --git a/inventory/phpipam_inventory.py b/inventory/phpipam_inventory.py index 10b1a95..8417c1d 100755 --- a/inventory/phpipam_inventory.py +++ b/inventory/phpipam_inventory.py @@ -46,7 +46,7 @@ "Content-Type": "application/json" } -response = requests.get(url, headers=headers) +response = requests.get(url, headers=headers, timeout=300) print("*********************************************") # Uncomment the below two lines to help when troublshooting to dump the contents of the API call to the console. diff --git a/inventory/rackhd.py b/inventory/rackhd.py index 9b4372f..6bc4bde 100755 --- a/inventory/rackhd.py +++ b/inventory/rackhd.py @@ -30,7 +30,7 @@ def _load_inventory_data(self, nodeid): results = {} for (key, url) in info.items(): - r = requests.get(url, verify=False) + r = requests.get(url, verify=False, timeout=300) results[key] = r.text self._inventory[nodeid] = results @@ -76,7 +76,7 @@ def parse_args(): if (parse_args().list): try: url = RACKHD_URL + '/api/common/nodes' - r = requests.get(url, verify=False) + r = requests.get(url, verify=False, timeout=300) data = json.loads(r.text) for entry in data: if entry['type'] == 'compute':