-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy path__init__.py
More file actions
95 lines (81 loc) · 2.86 KB
/
__init__.py
File metadata and controls
95 lines (81 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from upcloud_api.api import API
from upcloud_api.cloud_manager.firewall_mixin import FirewallManager
from upcloud_api.cloud_manager.host_mixin import HostManager
from upcloud_api.cloud_manager.ip_address_mixin import IPManager
from upcloud_api.cloud_manager.lb_mixin import LoadBalancerManager
from upcloud_api.cloud_manager.network_mixin import NetworkManager
from upcloud_api.cloud_manager.object_storage_mixin import ObjectStorageManager
from upcloud_api.cloud_manager.server_mixin import ServerManager
from upcloud_api.cloud_manager.storage_mixin import StorageManager
from upcloud_api.cloud_manager.tag_mixin import TagManager
from upcloud_api.credentials import Credentials
from upcloud_api.errors import UpCloudClientError
class CloudManager(
FirewallManager,
HostManager,
IPManager,
LoadBalancerManager,
NetworkManager,
ObjectStorageManager,
ServerManager,
StorageManager,
TagManager,
):
"""
CloudManager contains the core functionality of the upcloud API library.
All other managers are mixed in so code can be organized in corresponding sub-manager classes.
"""
api: API
def __init__(
self, username: str = None, password: str = None, timeout: int = 60, token: str = None
) -> None:
"""
Initiates CloudManager that handles all HTTP connections with UpCloud's API.
Optionally determine a timeout for API connections (in seconds). A timeout with the value
`None` means that there is no timeout.
"""
credentials = Credentials(username, password, token)
if not credentials.is_defined:
raise UpCloudClientError(
"Credentials are not defined. Please provide username and password or an API token."
)
self.api = API(
token=credentials.authorization,
timeout=timeout,
)
def authenticate(self):
"""
Authenticate.
"""
return self.get_account()
def get_account(self):
"""
Returns information on the user's account and resource limits.
"""
return self.api.get_request('/account')
def get_zones(self):
"""
Returns a list of available zones.
"""
return self.api.get_request('/zone')
def get_timezones(self):
"""
Returns a list of available timezones.
"""
return self.api.get_request('/timezone')
def get_prices(self):
"""
Returns a list of resource prices.
"""
return self.api.get_request('/price')
def get_server_sizes(self):
"""
Returns a list of available server configurations.
"""
return self.api.get_request('/server_size')
def get_server_plans(self):
"""
Returns a list of available server plans
:return:
"""
return self.api.get_request('/plan')