Skip to content

Commit 119b8df

Browse files
authored
Merge pull request #40 from scop/start-timeout
Use longer server start timeout by default
2 parents 0182d41 + a46276b commit 119b8df

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

upcloud_api/cloud_manager/base.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, token, timeout=None): # noqa
1818
self.token = token
1919
self.timeout = timeout
2020

21-
def request(self, method, endpoint, body=None):
21+
def request(self, method, endpoint, body=None, timeout=-1):
2222
"""
2323
Perform a request with a given body to a given endpoint in UpCloud's API.
2424
@@ -38,11 +38,13 @@ def request(self, method, endpoint, body=None):
3838
else:
3939
json_body_or_None = None
4040

41+
call_timeout = timeout if timeout != -1 else self.timeout
42+
4143
APIcall = getattr(requests, method.lower())
4244
res = APIcall('https://api.upcloud.com' + url,
4345
data=json_body_or_None,
4446
headers=headers,
45-
timeout=self.timeout)
47+
timeout=call_timeout)
4648

4749
if res.text:
4850
res_json = res.json()
@@ -51,17 +53,17 @@ def request(self, method, endpoint, body=None):
5153

5254
return self.__error_middleware(res, res_json)
5355

54-
def get_request(self, endpoint):
56+
def get_request(self, endpoint, timeout=-1):
5557
"""
5658
Perform a GET request to a given endpoint in UpCloud's API.
5759
"""
58-
return self.request('GET', endpoint)
60+
return self.request('GET', endpoint, timeout=timeout)
5961

60-
def post_request(self, endpoint, body=None):
62+
def post_request(self, endpoint, body=None, timeout=-1):
6163
"""
6264
Perform a POST request to a given endpoint in UpCloud's API.
6365
"""
64-
return self.request('POST', endpoint, body)
66+
return self.request('POST', endpoint, body, timeout)
6567

6668
def __error_middleware(self, res, res_json):
6769
"""

upcloud_api/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ def stop(self): # noqa
160160
"""
161161
self.shutdown()
162162

163-
def start(self):
163+
def start(self, timeout=120):
164164
"""
165165
Start the server. Note: slow and blocking request.
166166
167167
The API waits for confirmation from UpCloud's IaaS backend before responding.
168168
"""
169169
path = '/server/{0}/start'.format(self.uuid)
170-
self.cloud_manager.post_request(path)
170+
self.cloud_manager.post_request(path, timeout=timeout)
171171
object.__setattr__(self, 'state', 'started')
172172

173173
def restart(self, hard=False, timeout=30, force=True):

0 commit comments

Comments
 (0)