Skip to content

Commit ecfd341

Browse files
author
Naor Livne
committed
adding configurable request timeouts
1 parent 181b0ed commit ecfd341

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

NebulaPythonSDK/sdk.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class Nebula:
55

66
# the nebula class init module serves as the login against the nebula API as it's the only shared thing among the
77
# class functions
8-
def __init__(self, username, password, host, port=80, protocol="http"):
8+
def __init__(self, username, password, host, port=80, protocol="http", request_timeout=60):
9+
self.request_timeout = request_timeout
910
self.username = username
1011
self.password = password
1112
self.protocol = protocol
@@ -23,49 +24,49 @@ def create_app(self, app, config):
2324
url = self.host + "/api/apps/" + app
2425
payload = json.dumps(config)
2526
headers = self.headers
26-
response = requests.request("POST", url, data=payload, headers=headers, timeout=300)
27+
response = requests.request("POST", url, data=payload, headers=headers, timeout=self.request_timeout)
2728
return response
2829

2930
# delete an existing nebula app, no confirmation required in SDK so be careful
3031
def delete_app(self, app):
3132
url = self.host + "/api/apps/" + app
3233
headers = self.headers
33-
response = requests.request("DELETE", url, headers=headers, timeout=300)
34+
response = requests.request("DELETE", url, headers=headers, timeout=self.request_timeout)
3435
return response
3536

3637
# list all of the apps managed by nebula
3738
def list_apps(self):
3839
url = self.host + "/api/apps"
3940
headers = self.headers
40-
response = requests.request("GET", url, headers=headers, timeout=300)
41+
response = requests.request("GET", url, headers=headers, timeout=self.request_timeout)
4142
return response
4243

4344
# list the config of a nebula app, only requires the app name
4445
def list_app_info(self, app):
4546
url = self.host + "/api/apps/" + app
4647
headers = self.headers
47-
response = requests.request("GET", url, headers=headers, timeout=300)
48+
response = requests.request("GET", url, headers=headers, timeout=self.request_timeout)
4849
return response
4950

5051
# stop a nebula app, only requires the app name
5152
def stop_app(self, app):
5253
url = self.host + "/api/apps/" + app + "/stop"
5354
headers = self.headers
54-
response = requests.request("POST", url, headers=headers, timeout=300)
55+
response = requests.request("POST", url, headers=headers, timeout=self.request_timeout)
5556
return response
5657

5758
# start a nebula app, only requires the app name
5859
def start_app(self, app):
5960
url = self.host + "/api/apps/" + app + "/start"
6061
headers = self.headers
61-
response = requests.request("POST", url, headers=headers, timeout=300)
62+
response = requests.request("POST", url, headers=headers, timeout=self.request_timeout)
6263
return response
6364

6465
# restart a nebula app, only requires the app name
6566
def restart_app(self, app):
6667
url = self.host + "/api/apps/" + app + "/restart"
6768
headers = self.headers
68-
response = requests.request("POST", url, headers=headers, timeout=300)
69+
response = requests.request("POST", url, headers=headers, timeout=self.request_timeout)
6970
return response
7071

7172
# update a nebula app, requires the app name and a dict of the config values you want to change, any combination of
@@ -74,19 +75,19 @@ def update_app(self, app, config):
7475
url = self.host + "/api/apps/" + app + "/update"
7576
payload = json.dumps(config)
7677
headers = self.headers
77-
response = requests.request("PUT", url, data=payload, headers=headers, timeout=300)
78+
response = requests.request("PUT", url, data=payload, headers=headers, timeout=self.request_timeout)
7879
return response
7980

8081
# rolling restart an app, only requires the app name
8182
def roll_app(self, app):
8283
url = self.host + "/api/apps/" + app + "/roll"
8384
headers = self.headers
84-
response = requests.request("POST", url, headers=headers, timeout=300)
85+
response = requests.request("POST", url, headers=headers, timeout=self.request_timeout)
8586
return response
8687

8788
# check that the contacted api is responding as expected
8889
def check_api(self):
8990
url = self.host + "/api/status"
9091
headers = self.headers
91-
response = requests.request("GET", url, headers=headers, timeout=300)
92+
response = requests.request("GET", url, headers=headers, timeout=self.request_timeout)
9293
return response

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ from NebulaPythonSDK import Nebula
1717

1818
# Create API object.
1919
# port defaults to 80 and protocol defaults to http if not set
20-
connection = Nebula(username="your_nebula_user", password="your_nebula_pass", host="nebula.example.com", port=80, protocol="http")
20+
connection = Nebula(username="your_nebula_user", password="your_nebula_pass", host="nebula.example.com", port=80, protocol="http", request_timeout=60)
2121

2222
# List apps
2323
app_list = connection.list_apps()

0 commit comments

Comments
 (0)