Skip to content

Commit 4dd8901

Browse files
authored
Merge pull request #79 from TechConsult/storage_imports
feat: object storage - readme updates
2 parents 074ce56 + f6a7dc6 commit 4dd8901

17 files changed

+423
-22
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Build Status](https://travis-ci.org/UpCloudLtd/upcloud-python-api.svg?branch=master)](https://travis-ci.org/UpCloudLtd/upcloud-python-api) [![Code Health](https://landscape.io/github/UpCloudLtd/upcloud-python-api/master/landscape.svg?style=flat)](https://landscape.io/github/UpCloudLtd/upcloud-python-api/master) [![PyPI version](https://badge.fury.io/py/upcloud-api.svg)](https://badge.fury.io/py/upcloud-api) [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/UpCloudLtd/upcloud-python-api/blob/master/LICENSE)
22

33
# UpCloud's Python API Client
4-
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.
4+
OOP-based api client for [UpCloud's API](https://developers.upcloud.com/1.3/). Features most of the API's functionality and some convenience functions that combine several API endpoints and logic.
55

66
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.
77

@@ -29,15 +29,18 @@ python setup.py install
2929
(http://stackoverflow.com/questions/29099404/ssl-insecureplatform-error-when-using-requests-package)
3030

3131

32-
**Supported versions as of 0.3.3** (offline tests pass with tox):
32+
**Supported versions in the next release** (offline tests pass with tox):
3333

3434
* <del>python 2.6</del> removed due to deprecation
35-
* python 2.7
35+
* python 2.7 supported but not recommended, especially when upcloud-ansible will be ported to python3
3636
* <del>python 3.2</del> removed due to python2/3 support
37-
* <del>python 3.3</del> removed due to deprecation
38-
* python 3.4
39-
* python 3.5
40-
* pypi3 2.4.0
37+
* <del>python 3.3</del> removed due to python2/3 support
38+
* <del>python 3.4</del> removed due to python2/3 support
39+
* <del>python 3.5</del> removed due to python2/3 support
40+
* python 3.6
41+
* python 3.7
42+
* python 3.9
43+
* pypi3
4144

4245
## Features
4346
* OOP based management of Servers, Storages and IP-addresses with full CRUD.
@@ -53,9 +56,6 @@ python setup.py install
5356
**Changelog:**
5457
* See the [Releases page](https://github.com/UpCloudLtd/upcloud-python-api/releases)
5558

56-
**Documentation:**
57-
* Available [here](http://upcloudltd.github.io/upcloud-python-api/)
58-
5959

6060

6161
## Examples
@@ -233,7 +233,7 @@ Set up environment and install dependencies:
233233
# run at project root, python3 and virtualenv must be installed
234234
virtualenv ENV
235235
source ENV/bin/activate
236-
pip install -r requirements.txt or pip install -r requirements-dev.txt if changes to the api need to be made
236+
pip install -r requirements.txt && pip install -r requirements-dev.txt
237237
```
238238

239239
Install the package in editable mode, as mentioned in

docs/object_storage-mixin.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## About
2+
```python
3+
class ObjectStorageManager():
4+
"""
5+
Functions for managing Object Storages. Intended to be used as a mixin for CloudManager.
6+
"""
7+
```
8+
`ObjectStorageManager` is a mixed into `CloudManager` and the following methods are available by
9+
10+
```python
11+
manager = CloudManager("api-username", "password")
12+
manager.method()
13+
```
14+
15+
## Methods
16+
17+
```python
18+
def get_object_storages(self):
19+
"""
20+
List all Object Storage devices on the account or those which the subaccount has permissions.
21+
Returns a list of ObjectStorage objects.
22+
"""
23+
```
24+
25+
```python
26+
def create_object_storage(self, zone, access_key, secret_key, size, name=None, description=None):
27+
"""
28+
Used to create a new Object Storage device with a given name, size and location.
29+
Zone, access_key, secret_key and size are mandatory while name and description are optional.
30+
"""
31+
```
32+
33+
```python
34+
def modify_object_storage(self, object_storage, access_key=None, secret_key=None, description=None, size=None):
35+
"""
36+
Modify requests can be used to update the details of an Object Storage including description, access_key and secret_key.
37+
Object_storage is mandatory and can be a uuid or a ObjectStorage object.
38+
Access_key, secret_key, description and size are optional.
39+
If passed access_key needs to be provided with secret_key and vice-versa.
40+
"""
41+
```
42+
43+
```python
44+
def delete_object_storage(self, object_storage):
45+
"""
46+
Object Storage devices can be deleted using the following API request.
47+
Object_storage is mandatory and can be a uuid or a ObjectStorage object.
48+
"""
49+
```
50+
51+
```python
52+
def get_object_storage_network_statistics(
53+
self,
54+
object_storage,
55+
datetime_from,
56+
datetime_to=None,
57+
interval=None,
58+
bucket=[],
59+
filename=[],
60+
method=[],
61+
status=[],
62+
group_by=[],
63+
order_by=[],
64+
limit=None
65+
):
66+
"""
67+
The network usage of an Object Storage device is metered and can be reviewed using the statistics request.
68+
Object_storage is mandatory and can be a uuid or a ObjectStorage object.
69+
Datetime_from is mandatory and needs to be a string example: 2020-11-03 00:00:00
70+
Datetime_to is optional and needs to be a string example: 2020-11-04 00:00:00
71+
Interval is optional and needs to be an integer
72+
Bucket is optional and needs to be a list of bucket name strings
73+
Filename is optional and needs to be a list of filename strings
74+
Method is optional and needs to be a list of method name strings
75+
Status is optional and needs to be a list of http status codes as integers
76+
Group_by is optional and needs to be a list of specified properties as strings
77+
Order_by is optional and needs to be a list of specified properties as strings
78+
Limit is optional and needs to be an integer
79+
"""
80+
```

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
urllib3==1.25.9
22
requests==2.24.0
33
six==1.15.0
4+
python-dateutil==2.8.1

test/json_data/object-storage.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"object_storages":
3+
{
4+
"object_storage":
5+
[
6+
{
7+
"created": "2020-11-03T15:28:59Z",
8+
"description": "test for python api",
9+
"name": "pyapi-test3",
10+
"size": 250,
11+
"state": "started",
12+
"url": "https://pyapi-test3.fi-hel2.upcloudobjects.com/",
13+
"uuid": "06b0e4fc-d74b-455e-a373-60cd6ca84022",
14+
"zone": "fi-hel2"
15+
},
16+
{
17+
"created": "2020-11-03T15:16:15Z",
18+
"description": "test-python-api",
19+
"name": "test-python-api",
20+
"size": 250,
21+
"state": "started",
22+
"url": "https://test-python-api.fi-hel2.upcloudobjects.com/",
23+
"uuid": "06f12ae8-8531-44c9-9529-acdd278c7408",
24+
"zone": "fi-hel2"
25+
}
26+
]
27+
}
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"object_storage": {
3+
"created": "2020-11-03T15:28:59Z",
4+
"description": "new description",
5+
"name": "test-os",
6+
"size": 500,
7+
"state": "started",
8+
"url": "https://pyapi-test3.fi-hel2.upcloudobjects.com/",
9+
"uuid": "0608edc4-d4a3-4b01-abe4-e147bd7ffe45",
10+
"zone": "fi-hel2"
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"object_storage": {
3+
"created": "2020-11-03T15:28:59Z",
4+
"description": "test for python api",
5+
"name": "pyapi-test3",
6+
"size": 250,
7+
"state": "started",
8+
"url": "https://pyapi-test3.fi-hel2.upcloudobjects.com/",
9+
"uuid": "06b0e4fc-d74b-455e-a373-60cd6ca84022",
10+
"zone": "fi-hel2"
11+
}
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"stats":
3+
{
4+
"stat":
5+
[
6+
{
7+
"bytes_received": 1041,
8+
"bytes_transmitted": 3011,
9+
"requests": 5,
10+
"timestamp": "2020-11-03T15:00:00Z"
11+
},
12+
{
13+
"bytes_received": 583,
14+
"bytes_transmitted": 1296,
15+
"requests": 2,
16+
"timestamp": "2020-11-04T10:00:00Z"
17+
},
18+
{
19+
"bytes_received": 279,
20+
"bytes_transmitted": 648,
21+
"requests": 1,
22+
"timestamp": "2020-11-04T11:00:00Z"
23+
}
24+
]
25+
}
26+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"object_storage":
3+
{
4+
"created": "2020-11-05T13:30:21Z",
5+
"description": "for tests",
6+
"name": "test-os",
7+
"size": 250,
8+
"state": "started",
9+
"url": "https://test-os.fi-hel2.upcloudobjects.com/",
10+
"used_space": 0,
11+
"uuid": "0608edc4-d4a3-4b01-abe4-e147bd7ffe45",
12+
"zone": "fi-hel2"
13+
}
14+
}

test/test_object_storage.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from __future__ import unicode_literals
2+
from __future__ import print_function
3+
from __future__ import division
4+
from __future__ import absolute_import
5+
6+
from conftest import Mock
7+
import responses
8+
9+
10+
class TestObjectStorage(object):
11+
@responses.activate
12+
def test_get_object_storages(self, manager):
13+
data = Mock.mock_get('object-storage')
14+
object_storages = manager.get_object_storages()
15+
16+
for object_storage in object_storages:
17+
assert type(object_storage).__name__ == 'ObjectStorage'
18+
19+
@responses.activate
20+
def test_create_object_storage(self, manager):
21+
data = Mock.mock_post('object-storage', ignore_data_field=True)
22+
object_storage = manager.create_object_storage('fi-hel2', 'access_key', 'secret_key', 250, 'test-os', 'for tests')
23+
24+
assert type(object_storage).__name__ == 'ObjectStorage'
25+
assert object_storage.name == 'test-os'
26+
assert object_storage.description == 'for tests'
27+
assert object_storage.zone == 'fi-hel2'
28+
assert object_storage.size == 250
29+
30+
@responses.activate
31+
def test_get_object_storage(self, manager):
32+
data = Mock.mock_get('object-storage/06b0e4fc-d74b-455e-a373-60cd6ca84022')
33+
object_storage = manager.get_object_storage('06b0e4fc-d74b-455e-a373-60cd6ca84022')
34+
35+
assert type(object_storage).__name__ == 'ObjectStorage'
36+
assert object_storage.name == 'pyapi-test3'
37+
assert object_storage.description == 'test for python api'
38+
assert object_storage.zone == 'fi-hel2'
39+
assert object_storage.size == 250
40+
41+
@responses.activate
42+
def test_modify_object_storage(self, manager):
43+
data = Mock.mock_patch('object-storage/0608edc4-d4a3-4b01-abe4-e147bd7ffe45', ignore_data_field=True)
44+
object_storage = manager.modify_object_storage('0608edc4-d4a3-4b01-abe4-e147bd7ffe45', 'access_key', 'secret_key', 'new description', 500)
45+
46+
assert type(object_storage).__name__ == 'ObjectStorage'
47+
assert object_storage.name == 'test-os'
48+
assert object_storage.description == 'new description'
49+
assert object_storage.zone == 'fi-hel2'
50+
assert object_storage.size == 500
51+
52+
@responses.activate
53+
def test_delete_object_storage(self, manager):
54+
data = Mock.mock_delete('object-storage/0608edc4-d4a3-4b01-abe4-e147bd7ffe45')
55+
res = manager.delete_object_storage('0608edc4-d4a3-4b01-abe4-e147bd7ffe45')
56+
57+
assert res == {}
58+
59+
@responses.activate
60+
def test_get_object_storage_network_statistics(self, manager):
61+
data = Mock.mock_get('object-storage/06b0e4fc-d74b-455e-a373-60cd6ca84022/stats/network/', response_file='object-storage_06b0e4fc-d74b-455e-a373-60cd6ca84022_stats_network.json')
62+
res = manager.get_object_storage_network_statistics('06b0e4fc-d74b-455e-a373-60cd6ca84022', '2020-11-03 00:00:00')
63+
64+
assert 'stats' in res
65+
assert len(res.get('stats').get('stat')) == 3

upcloud_api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929
from upcloud_api.router import Router
3030
from upcloud_api.host import Host
3131
from upcloud_api.ip_network import IpNetwork
32+
from upcloud_api.object_storage import ObjectStorage
3233
from upcloud_api.cloud_manager.cloud_manager import CloudManager

0 commit comments

Comments
 (0)