Skip to content

Commit 8517654

Browse files
author
Elias Nygren
committed
Merge pull request #10 from UpCloudLtd/0.3.0-devel
0.3.0 devel
2 parents 099024d + bf9de39 commit 8517654

28 files changed

+396
-185
lines changed

README.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# UpCloud-python-api
2-
Python client for [UpCloud's API](https://www.upcloud.com/documentation/api/).
1+
# UpCloud's Python API Client
2+
OOP-based api client for [UpCloud's API](https://www.upcloud.com/documentation/api/). Features most of the API's functionality and some convenience functions that combine several API endpoints and logic.
33

4-
NOTE: This Python client is still work-in-progress and is not considered production ready.
4+
NOTE: This Python client is still evolving. Please test all of your use cases thoroughly before actual production use. Using a separate UpCloud account for testing / developing the client is recommended.
55

66
## Installation
77

88
```
9-
pip install --pre upcloud-api-python
9+
pip install --pre upcloud-api
1010
1111
# with older pip:
12-
pip install upcloud-api-python
12+
pip install upcloud-api
1313
```
1414

1515
Alternatively, clone the project and run
1616
```
1717
python setup.py install
1818
```
1919

20-
**Supported versions** (offline tests pass with tox):
20+
**Supported versions as of 0.3.0** (offline tests pass with tox):
2121

2222
* python 2.6
2323
* python 2.7
@@ -112,6 +112,11 @@ for server in cluster:
112112

113113
```
114114

115+
New in 0.3.0: servers can now be defined as dicts without using Server or Storage classes.
116+
The syntax/attributes are exactly like above and under the hood they are converted to Server and Storage classes.
117+
This feature is mainly for easier usage of the module from Ansible, but may provide useful elsewhere.
118+
119+
115120
### Stop / Start / Destroy Servers
116121
```python
117122

@@ -126,6 +131,18 @@ for server in cluster:
126131

127132
```
128133

134+
New in 0.3.0: as the success of server.start() or server.destroy() and storage.destroy()
135+
depend on the Server's `state`, new helpers have been added. The helpers may be called regardless of
136+
the server's current state.
137+
138+
```python
139+
# makes sure that the server is stopped (blocking wait) and then destroys the server and its storages
140+
server.stop_and_destroy()
141+
142+
# makes sure that the server is started (blocking wait)
143+
server.ensure_started()
144+
```
145+
129146
### Upgrade a Server
130147
```python
131148

@@ -138,6 +155,20 @@ server.start()
138155

139156
```
140157

158+
### Easy access to servers and their information:
159+
160+
New in 0.3.0.
161+
162+
```python
163+
164+
# returns a public IPv4 (preferred) IPv6 (no public IPv4 was attached) address
165+
server.get_public_ip()
166+
167+
# returns a JSON serializable dict with the server's information (storages and ip-addresses included)
168+
server.to_dict()
169+
170+
```
171+
141172
### GET resources:
142173
```python
143174

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
from setuptools import setup
44

55
setup(
6-
name='upcloud-api-python',
7-
version='0.2.0',
6+
name='upcloud-api',
7+
version='0.3.0',
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',
14-
packages=['upcloud', 'upcloud.cloud_manager'],
15-
download='https://github.com/UpCloudLtd/upcloud-python-api/tarball/v0.2.0',
14+
packages=['upcloud_api', 'upcloud_api.cloud_manager'],
15+
download='https://github.com/UpCloudLtd/upcloud-python-api/tarball/v0.3.0',
1616
license='MIT',
1717
install_requires=[
1818
'future==0.14.3',

test/conftest.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@
22
from __future__ import print_function
33
from __future__ import division
44
from __future__ import absolute_import
5-
from builtins import open
5+
from builtins import object, open
66
from future import standard_library
77
standard_library.install_aliases()
8-
from builtins import object
9-
import os
10-
import pytest
11-
import responses
12-
import json
138

9+
import json, os, pytest, responses
1410

1511
@pytest.fixture(scope='module')
1612
def manager():
17-
import upcloud
18-
return upcloud.CloudManager("testuser", "mock-api-password")
13+
import upcloud_api
14+
return upcloud_api.CloudManager("testuser", "mock-api-password")
1915

2016

2117
class Mock(object):

test/json_data/server.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
"hostname" : "fi.example.com",
99
"memory_amount" : "512",
1010
"uuid" : "00798b85-efdc-41ca-8021-f6ef457b8531",
11-
"state" : "started"
11+
"state" : "started",
12+
"tags": {
13+
"tag": [
14+
"web1"
15+
]
16+
}
1217
},
1318
{
1419
"zone" : "uk-lon1",
@@ -17,8 +22,13 @@
1722
"hostname" : "uk.example.com",
1823
"memory_amount" : "512",
1924
"uuid" : "009d64ef-31d1-4684-a26b-c86c955cbf46",
20-
"state" : "stopped"
25+
"state" : "stopped",
26+
"tags": {
27+
"tag": [
28+
"web2"
29+
]
30+
}
2131
}
2232
]
2333
}
24-
}
34+
}

test/json_data/server_00798b85-efdc-41ca-8021-f6ef457b8531.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
}
3232
]
3333
},
34+
"tags": {
35+
"tag": [
36+
"web1"
37+
]
38+
},
3439
"timezone" : "UTC",
3540
"title" : "Helsinki server",
3641
"uuid" : "00798b85-efdc-41ca-8021-f6ef457b8531",
@@ -41,4 +46,4 @@
4146
"vnc_port" : "00000",
4247
"zone" : "fi-hel1"
4348
}
44-
}
49+
}

test/json_data/server_009d64ef-31d1-4684-a26b-c86c955cbf46.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
}
3232
]
3333
},
34+
"tags": {
35+
"tag": [
36+
"web2"
37+
]
38+
},
3439
"timezone" : "UTC",
3540
"title" : "London server",
3641
"uuid" : "009d64ef-31d1-4684-a26b-c86c955cbf46",
@@ -41,4 +46,4 @@
4146
"vnc_port" : "00000",
4247
"zone" : "uk-lon1"
4348
}
44-
}
49+
}

test/live_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from builtins import input
66
from future import standard_library
77
standard_library.install_aliases()
8-
import sys
9-
from time import sleep
108

11-
import upcloud
12-
from upcloud import CloudManager, Server, Storage, FirewallRule, ZONE
9+
from upcloud_api import CloudManager, Server, Storage, FirewallRule, ZONE
10+
11+
from time import sleep
12+
import sys
1313

1414
# cluster to be used in live tests
1515
cluster = {

test/test_cloud_manager.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
from __future__ import print_function
33
from __future__ import division
44
from __future__ import absolute_import
5+
from builtins import object
56
from future import standard_library
67
standard_library.install_aliases()
7-
from builtins import object
8-
import responses
9-
import json
8+
109
from conftest import Mock
10+
import json, responses
11+
1112

1213
class TestCloudManagerBasic(object):
1314
@responses.activate
1415
def test_get_account(self, manager):
1516
data = Mock.mock_get("account")
16-
17+
1718
res = manager.authenticate()
1819
assert json.loads(data) == res
1920
res = manager.get_account()

test/test_firewall.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
from __future__ import print_function
33
from __future__ import division
44
from __future__ import absolute_import
5+
from builtins import object
56
from future import standard_library
67
standard_library.install_aliases()
7-
from builtins import object
8-
from upcloud import FirewallRule
9-
import responses
10-
import json
8+
9+
from upcloud_api import FirewallRule
10+
1111
from conftest import Mock
12-
import pytest
12+
import json, pytest, responses
1313

1414

1515
def firewall_rule_callback(request):

test/test_ip_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from __future__ import print_function
33
from __future__ import division
44
from __future__ import absolute_import
5+
from builtins import object
56
from future import standard_library
67
standard_library.install_aliases()
7-
from builtins import object
8-
import responses
9-
import json
8+
109
from conftest import Mock
10+
import json, responses
1111

1212
class TestIP(object):
1313
@responses.activate
@@ -52,10 +52,10 @@ def test_modify_ip(self, manager):
5252
data = Mock.mock_put("ip_address/10.1.0.101")
5353
ip_addr = manager.modify_IP("10.1.0.101", ptr_record="my.ptr.record")
5454
assert ip_addr.ptr == "my.ptr.record"
55-
55+
5656

5757
@responses.activate
5858
def test_ip_delete(self, manager):
5959
Mock.mock_delete("ip_address/10.1.0.101")
6060
res = manager.release_IP("10.1.0.101")
61-
assert res == {}
61+
assert res == {}

0 commit comments

Comments
 (0)