Skip to content

Commit 05f9822

Browse files
authored
Merge pull request #97 from akx/misc-fixes
A handful of miscellaneous fixes + TODOs
2 parents b5980a8 + 5b2b84f commit 05f9822

File tree

10 files changed

+22
-16
lines changed

10 files changed

+22
-16
lines changed

upcloud_api/cloud_manager/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def request(self, method, endpoint, body=None, params=None, timeout=-1, request_
2929
if method not in {'GET', 'POST', 'PUT', 'PATCH', 'DELETE'}:
3030
raise Exception('Invalid/Forbidden HTTP method')
3131

32+
# TODO: revise the semantics of `request_to_api` and where it is set to False
3233
url = 'https://api.upcloud.com/' + self.api_v + endpoint if request_to_api else endpoint
3334
headers = {'Authorization': self.token, 'User-Agent': self._get_user_agent()}
3435

@@ -45,8 +46,9 @@ def request(self, method, endpoint, body=None, params=None, timeout=-1, request_
4546

4647
call_timeout = timeout if timeout != -1 else self.timeout
4748

48-
APIcall = getattr(requests, method.lower())
49-
res = APIcall(url, data=data, params=params, headers=headers, timeout=call_timeout)
49+
res = requests.request(
50+
method=method, url=url, data=data, params=params, headers=headers, timeout=call_timeout
51+
)
5052

5153
if res.text:
5254
res_json = res.json()

upcloud_api/cloud_manager/cloud_manager.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class CloudManager(
2727
"""
2828
CloudManager contains the core functionality of the upcloud API library.
2929
30-
All other managers are mixed in so code can be organized in corresponding submanager classes.
30+
All other managers are mixed in so code can be organized in corresponding sub-manager classes.
3131
"""
3232

3333
def __init__(self, username: str, password: str, timeout: int = 60) -> None:
3434
"""
35-
Initiates CloudManager that handles all HTTP conections with UpCloud's API.
35+
Initiates CloudManager that handles all HTTP connections with UpCloud's API.
3636
3737
Optionally determine a timeout for API connections (in seconds). A timeout with the value
3838
`None` means that there is no timeout.
@@ -43,8 +43,10 @@ def __init__(self, username: str, password: str, timeout: int = 60) -> None:
4343
credentials = f'{username}:{password}'.encode()
4444
encoded_credentials = base64.b64encode(credentials).decode()
4545

46-
self.token = f'Basic {encoded_credentials}'
47-
self.timeout = timeout
46+
super().__init__(
47+
token=f'Basic {encoded_credentials}',
48+
timeout=timeout,
49+
)
4850

4951
def authenticate(self):
5052
"""

upcloud_api/cloud_manager/firewall_mixin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class FirewallManager:
1717
directly.
1818
"""
1919

20+
# TODO: server_instance is unused?
2021
def get_firewall_rule(self, server_uuid, firewall_rule_position, server_instance=None):
2122
"""
2223
Return a FirewallRule object based on server uuid and rule position.
@@ -43,7 +44,7 @@ def create_firewall_rule(self, server, firewall_rule_body):
4344
"""
4445
Create a new firewall rule for a given server uuid.
4546
46-
The rule can begiven as a dict or with FirewallRule.prepare_post_body().
47+
The rule can be given as a dict or with FirewallRule.prepare_post_body().
4748
Returns a FirewallRule object.
4849
"""
4950
server_uuid, server_instance = uuid_and_instance(server)

upcloud_api/cloud_manager/network_mixin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def create_network(
5757
},
5858
}
5959
}
60-
60+
# TODO: fix duplication c.f. modify_network
6161
if router:
6262
body['network']['router'] = router
6363
if dhcp_default_route:

upcloud_api/cloud_manager/object_storage_mixin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ObjectStorageManager:
1111

1212
def get_object_storages(self):
1313
"""
14-
List all Object Storage devices on the account or those which the subaccount has permissions.
14+
List all Object Storage devices on the account or those which the sub-account has permissions.
1515
"""
1616
url = '/object-storage'
1717
res = self.get_request(url)

upcloud_api/ip_address.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class IPAddress(UpCloudResource):
1313
ptr_record -- the reverse DNS name (string)
1414
server -- the UUID of the server this IP is attached to (string)
1515
16-
The only updateable field is the ptr_record.
16+
The only updatable field is the ptr_record.
1717
1818
Note that all of the fields are not always available depending on the API call,
1919
consult the official API docs for details.

upcloud_api/server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ def add_ip(self, family: str = 'IPv4') -> IPAddress:
211211
self.ip_addresses.append(IP)
212212
return IP
213213

214-
def remove_ip(self, IPAddress: IPAddress) -> None:
214+
def remove_ip(self, ip_address: IPAddress) -> None:
215215
"""
216216
Release the specified IP-address from the server.
217217
"""
218-
self.cloud_manager.release_ip(IPAddress.address)
219-
self.ip_addresses.remove(IPAddress)
218+
self.cloud_manager.release_ip(ip_address.address)
219+
self.ip_addresses.remove(ip_address)
220220

221221
def add_storage(
222222
self,
@@ -410,6 +410,7 @@ def to_dict(self):
410410
del fields['cloud_manager']
411411
return fields
412412

413+
# TODO: strict is unused?
413414
def get_ip(self, access='public', addr_family=None, strict=None):
414415
"""
415416
Return the server's IP address.

upcloud_api/storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _reset(self, **kwargs) -> None:
2424
Reset after repopulating from API.
2525
"""
2626

27-
# there are some inconsistenciens in the API regarding these
27+
# there are some inconsistencies in the API regarding these
2828
# note: this could be written in fancier ways, but this way is simpler
2929

3030
if 'uuid' in kwargs:

upcloud_api/tag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _reset(self, **kwargs) -> None:
2525
"""
2626
Reset the objects attributes.
2727
28-
Accepts servers as either unflattened or flattened UUID strings or Server objects.
28+
Accepts servers as either un-flattened or flattened UUID strings or Server objects.
2929
"""
3030
super()._reset(**kwargs)
3131

upcloud_api/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def try_it_n_times(operation, expected_error_codes, custom_error='operation fail
1010
1111
Raises if the API call fails with an error_code that is not expected.
1212
Raises if the API call has not succeeded within n attempts.
13-
Waits 3 seconds betwee each attempt.
13+
Waits 3 seconds between each attempt.
1414
"""
1515
for i in itertools.count():
1616
try:

0 commit comments

Comments
 (0)