Skip to content

Commit a7ef273

Browse files
author
Elias Nygren
committed
Merge pull request #14 from UpCloudLtd/0.3.3-devel
allow setting timeout (default 10s); bump to 0.3.3
2 parents 597f1d8 + b038268 commit a7ef273

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ python setup.py install
2727
(http://stackoverflow.com/questions/29099404/ssl-insecureplatform-error-when-using-requests-package)
2828

2929

30-
**Supported versions as of 0.3.0** (offline tests pass with tox):
30+
**Supported versions as of 0.3.3** (offline tests pass with tox):
3131

3232
* python 2.6
3333
* python 2.7
@@ -65,7 +65,7 @@ python setup.py install
6565

6666
## Examples
6767

68-
Note that operations are not instant, for example a server is not fully shut down when the API responds.
68+
Note that some operations are not instant, for example a server is not fully shut down when the API responds.
6969
You must take this into account in your automations.
7070

7171
### Defining and creating Servers

docs/CloudManager.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
# Account / Authentication
1+
# Cloud Manager
2+
3+
CloudManager handles all HTTP communications with UpCloud and mixes in the behavior of all Manager
4+
classes.
5+
6+
In addition to the credentials, CloudManager can be given a timeout parameter that is
7+
relayed to requests library, see [here](http://docs.python-requests.org/en/master/user/advanced/?highlight=timeout#timeouts).
8+
Default timeout is 10.
29

310
```python
411

512
# create manager and form a token
6-
manager = CloudManager("api-username", "password")
13+
manager = CloudManager("api-username", "password", timeout=15) # default timeout is 10
14+
15+
```
16+
17+
# Account / Authentication
18+
19+
```python
720

821
# test token
922
manager.authenticate() # alias: get_account()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
setup(
66
name='upcloud-api',
7-
version='0.3.2',
7+
version='0.3.3',
88
description='UpCloud API Client',
99
author='Elias Nygren',
1010
author_email='elias.nygren@upcloud.com',
1111
maintainer='Elias Nygren',
1212
maintainer_email='elias.nygren@upcloud.com',
1313
url='https://github.com/UpCloudLtd/upcloud-python-api',
1414
packages=['upcloud_api', 'upcloud_api.cloud_manager'],
15-
download='https://github.com/UpCloudLtd/upcloud-python-api/tarball/v0.3.2',
15+
download='https://github.com/UpCloudLtd/upcloud-python-api/tarball/v0.3.3',
1616
license='MIT',
1717
install_requires=[
1818
'future==0.14.3',

upcloud_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from future import standard_library
1010
standard_library.install_aliases()
1111

12-
__version__ = "0.3.2"
12+
__version__ = "0.3.3"
1313
__author__ = "Elias Nygren"
1414
__author_email__ = "elias.nygren@upcloud.com"
1515
__license__ = "MIT"

upcloud_api/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ class BaseAPI(object):
1212
api = "api.upcloud.com"
1313
api_v = "1.2"
1414

15-
def __init__(self, token):
15+
def __init__(self, token, timeout=None):
1616
self.token = token
17+
self.timeout = timeout
1718

1819
"""
1920
Performs a request with a given body to a given endpoint in UpCloud's API.
@@ -33,7 +34,11 @@ def request(self, method, endpoint, body=None):
3334
else: json_body_or_None = None
3435

3536
APIcall = getattr(requests, method.lower())
36-
res = APIcall("https://api.upcloud.com" + url, data=json_body_or_None, headers=headers)
37+
res = APIcall("https://api.upcloud.com" + url,
38+
data=json_body_or_None,
39+
headers=headers,
40+
timeout=self.timeout
41+
)
3742

3843
if( res.text ):
3944
res_json = res.json()

upcloud_api/cloud_manager/cloud_manager.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ class CloudManager(BaseAPI, ServerManager, IPManager, StorageManager, FirewallMa
1919
All other managers are mixed in so code can be organized in corresponding submanager classes.
2020
"""
2121

22-
def __init__(self, username, password):
22+
def __init__(self, username, password, timeout=10):
23+
"""
24+
Initiates CloudManager that handles all HTTP conections with UpCloud's API.
25+
Optionally determine a timeout for API connections (in seconds). A timeout with the value
26+
`None` means that there is no timeout.
27+
"""
28+
2329
self.token = "Basic " + base64.b64encode( (username + ":" + password).encode() ).decode()
30+
self.timeout = timeout
31+
2432

2533
def authenticate(self):
2634
return self.get_account()

0 commit comments

Comments
 (0)