Skip to content

Commit 3b516e3

Browse files
author
Elias Nygren
committed
documentation and minor changes to make code more consistent
1 parent 4013dcd commit 3b516e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3808
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# UpCloud-python-api
22
Python client for [UpCloud's API](https://www.upcloud.com/documentation/api/).
33

4+
NOTE: This Python client is still work-in-progress and is not considered production ready.
5+
46
## Features
57
* OOP based management of Servers, Storages and IP-addresses with full CRUD.
68
* Clear way to define your infrastructure, emphasis on clear and easy syntax

docs/CloudManager.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Account / Authentication
2+
3+
```python
4+
5+
# create manager and form a token
6+
manager = CloudManager("api-username", "password")
7+
8+
# test token
9+
manager.authenticate() # alias: get_account()
10+
manager.get_account()
11+
12+
```
13+
14+
# Zone
15+
16+
Zones are already hardcoded as Enums in `upcloud.ZONE`. However, they can be queried from the API too.
17+
18+
```python
19+
20+
manager.get_zones()
21+
22+
```
23+
24+
# TimeZone
25+
26+
Timezone can be given as a parameter to a server during creation and update.
27+
28+
```python
29+
30+
manager.get_timezones()
31+
32+
```
33+
34+
# Pricing
35+
36+
```python
37+
38+
manager.get_pricing()
39+
40+
```
41+
42+
# Server Sizes
43+
44+
List the possible server CPU-ram configurations.
45+
46+
```python
47+
48+
manager.get_server_sizes
49+
50+
```

docs/IP-address-mixin.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## About
2+
3+
```python
4+
class IPManager():
5+
"""
6+
Functions for managing IP-addresses.
7+
Intended to be used as a mixin for CloudManager.
8+
"""
9+
```
10+
11+
`IPManager` is a mixed into `CloudManager` and the following methods are available by
12+
13+
```python
14+
manager = CloudManager("api-username", "password")
15+
manager.method()
16+
```
17+
18+
## Methods
19+
20+
21+
```python
22+
def get_IP(self, address):
23+
"""
24+
Get an IP_address object with the IP address (string) from the API.
25+
e.g manager.get_IP("80.69.175.210")
26+
"""
27+
```
28+
29+
```python
30+
def get_IPs(self):
31+
"""
32+
Get all IP_address objects from the API.
33+
"""
34+
```
35+
36+
```python
37+
def attach_IP(self, server):
38+
"""
39+
Attach a new (random) IP_address to the given server (object or UUID)
40+
"""
41+
```
42+
```python
43+
def modify_IP(self, IP_addr, ptr_record):
44+
"""
45+
Modify an IP address' ptr-record (Reverse DNS).
46+
Accepts an IP_address instance (object) or its address (string).
47+
"""
48+
```
49+
50+
```python
51+
def release_IP(self, IP_addr):
52+
"""
53+
Destroy an IP_address. Returns an empty object.
54+
Accepts an IP_address instance (object) or its address (string).
55+
"""
56+
```

docs/IP-address.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
3+
## About
4+
5+
6+
```
7+
Attributes:
8+
access -- "public" or "private"
9+
address -- the IP address (string)
10+
ptr_record -- the reverse DNS name (string)
11+
server -- the UUID of the server this IP is attached to (string)
12+
```
13+
14+
The only updateable attribute is the `ptr_record`.
15+
`ptr_record` and `server` are present only if /server/uuid endpoint was used.
16+
17+
## List / Get
18+
19+
CloudManager returns IP-address objects.
20+
21+
```python
22+
23+
manager.get_IPs()
24+
manager.get_IP("185.20.31.125")
25+
26+
```
27+
28+
## Create
29+
30+
The new IP-address must be attached to a server and has a random address.
31+
32+
```python
33+
34+
# param: server uuid or a Server object
35+
manager.attach_IP(server_uuid)
36+
manager.attach_IP(Server)
37+
38+
# or use Server instance
39+
server = manager.get_server(uuid)
40+
server.add_IP()
41+
42+
```
43+
44+
## Update
45+
46+
At the moment only the ptr_record (reverse DNS) of an IP can be changed.
47+
48+
```python
49+
50+
ip = manager.get_IP("185.20.31.125")
51+
ip.ptr_record = "the.new.ptr.record"
52+
ip.save()
53+
54+
```
55+
56+
## Destroy
57+
58+
```python
59+
60+
ip = manager.get_IP("185.20.31.125")
61+
ip.destroy()
62+
63+
```

docs/Server.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
The examples use the following:
2+
```python
3+
import upcloud
4+
from upcloud import Server
5+
from upcloud import Storage
6+
from upcloud import ZONE
7+
8+
manager = upcloud.CloudManager("username", "password")
9+
```
10+
11+
# Start / Stop / Restart
12+
13+
```python
14+
15+
server.stop()
16+
server.start()
17+
server.restart()
18+
19+
# populate the object with updated information from API
20+
server.populate()
21+
22+
```
23+
24+
Please note that the server might not be stopped/started/restarted immediately when the API responds. The `.populate()` method updates the object's fields from the API and is thus useful for checking `server.state`.
25+
26+
```
27+
Server states:
28+
"started","stopped" -- server is shut down or running
29+
"maintenance" -- when shutting down or (re)starting
30+
"error" -- erronous state in UpCloud's backend
31+
```
32+
33+
34+
35+
## List / Get
36+
37+
The CloudManager returns Server instances.
38+
39+
```python
40+
41+
servers = manager.get_servers()
42+
server = manager.get_server(servers[0].uuid)
43+
44+
```
45+
46+
## Create
47+
48+
Creation of servers in the API is handled by the CloudManager. It accepts a Server instance, forms the correct POST request and populates the Server instance's fields from the POST response.
49+
50+
```python
51+
52+
server = Server(
53+
core_number = 1,
54+
memory_amount = 512,
55+
hostname = "web1.example.com",
56+
zone = ZONE.London,
57+
storage_devices = [
58+
Storage(os = "Ubuntu 14.04", size=10),
59+
Storage(size=10, tier="hdd")
60+
])
61+
62+
manager.create_server( server )
63+
64+
```
65+
66+
Currently available Storage operating systems are the following UpCloud public templates:
67+
68+
```python
69+
# upcloud/tools.py
70+
71+
Operating Systems:
72+
"CentOS 6.5", "CentOS 7.0",
73+
"Debian 7.8", "Ubuntu 12.04", "Ubuntu 14.04",
74+
"Windows 2003", "Windows 2008", "Windows 2012"
75+
76+
```
77+
78+
79+
Please refer to the [API documentation](https://www.upcloud.com/static/downloads/upcloud-apidoc-1.1.1.pdf) for the allowed Server attributes.
80+
81+
## Update
82+
83+
### Attributes
84+
85+
Updating a Server's attributes is done with its `.save()` method that does a PUT request. If you want to manage the Server's Storages or IP-addresses, see below.
86+
87+
```python
88+
89+
server = manager.get_server( uuid )
90+
server.core_number = 4
91+
server.memory_amount = 4096
92+
server.save()
93+
94+
```
95+
96+
The following fields of Server instance may be updated, all other fields are read-only. Trying to assign values to other fields leads to an error.
97+
98+
```python
99+
Updateable attributes:
100+
"boot_order", "core_number", "firewall", "hostname", "memory_amount",
101+
"nic_model", "title", "timezone", "video_model", "vnc", "vnc_password"
102+
```
103+
104+
Please refer to the [API documentation](https://www.upcloud.com/static/downloads/upcloud-apidoc-1.1.1.pdf) for the allowed values.
105+
106+
### Storages
107+
108+
A Server's Storages can be attached and detached with `.add_storage()` and `.remove_storage()`. Both requests issue an API request instantly.
109+
110+
```python
111+
112+
# attach
113+
storage = manager.create_storage( size=100, zone=ZONE.Helsinki )
114+
server.add_storage(storage)
115+
116+
# detach
117+
storage = server.storage_devices[1]
118+
server.remove_storage(storage)
119+
120+
```
121+
122+
### IP-addresses
123+
124+
A Server's Storages can be attached and detached with `.add_IP()` and `.remove_IP()`. Both requests issue an API request instantly. Note that the attached IP is allocated randomly as UpCloud's does not (yet) support floating IPs.
125+
126+
```python
127+
128+
# attach
129+
IP = server.add_IP()
130+
131+
# detach
132+
server.remove_IP(IP)
133+
134+
```
135+
136+
## Destroy
137+
138+
Destroys the Server instance and its IP-addresses. However, does not destroy the Storages.
139+
140+
```python
141+
142+
server.destroy()
143+
144+
```

0 commit comments

Comments
 (0)