Skip to content

Commit d356d75

Browse files
committed
black
1 parent 0115b81 commit d356d75

File tree

116 files changed

+629
-1863
lines changed

Some content is hidden

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

116 files changed

+629
-1863
lines changed

plugins/module_utils/client.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,11 @@ class Response:
5959
# Response(raw_resp) would be simpler.
6060
# How is this used in other projects? Jure?
6161
# Maybe we need/want both.
62-
def __init__(
63-
self, status: int, data: Any, headers: Optional[dict[Any, Any]] = None
64-
):
62+
def __init__(self, status: int, data: Any, headers: Optional[dict[Any, Any]] = None):
6563
self.status = status
6664
self.data = data
6765
# [('h1', 'v1'), ('H2', 'V2')] -> {'h1': 'v1', 'h2': 'V2'}
68-
self.headers = (
69-
dict((k.lower(), v) for k, v in dict(headers).items()) if headers else {}
70-
)
66+
self.headers = dict((k.lower(), v) for k, v in dict(headers).items()) if headers else {}
7167

7268
self._json = None
7369

@@ -92,8 +88,7 @@ def __init__(
9288
):
9389
if not (host or "").startswith(("https://", "http://")):
9490
raise ScaleComputingError(
95-
"Invalid instance host value: '{0}'. "
96-
"Value must start with 'https://' or 'http://'".format(host)
91+
"Invalid instance host value: '{0}'. " "Value must start with 'https://' or 'http://'".format(host)
9792
)
9893

9994
self.host = host
@@ -213,23 +208,14 @@ def _request_no_log(
213208
except URLError as e:
214209
# TODO: Add other errors here; we need to handle them in modules.
215210
# TimeoutError is handled in the rest_client
216-
if (
217-
e.args
218-
and isinstance(e.args, tuple)
219-
and isinstance(e.args[0], ConnectionRefusedError)
220-
):
211+
if e.args and isinstance(e.args, tuple) and isinstance(e.args[0], ConnectionRefusedError):
221212
raise ConnectionRefusedError(e.reason)
222-
elif (
223-
e.args
224-
and isinstance(e.args, tuple)
225-
and isinstance(e.args[0], ConnectionResetError)
226-
):
213+
elif e.args and isinstance(e.args, tuple) and isinstance(e.args[0], ConnectionResetError):
227214
raise ConnectionResetError(e.reason)
228215
elif (
229216
e.args
230217
and isinstance(e.args, tuple)
231-
and type(e.args[0])
232-
in [ssl.SSLEOFError, ssl.SSLZeroReturnError, ssl.SSLSyscallError]
218+
and type(e.args[0]) in [ssl.SSLEOFError, ssl.SSLZeroReturnError, ssl.SSLSyscallError]
233219
):
234220
raise type(e.args[0])(e)
235221
raise ScaleComputingError(e.reason)
@@ -247,9 +233,7 @@ def request(
247233
) -> Response:
248234
# Make sure we only have one kind of payload
249235
if data is not None and binary_data is not None:
250-
raise AssertionError(
251-
"Cannot have JSON and binary payload in a single request."
252-
)
236+
raise AssertionError("Cannot have JSON and binary payload in a single request.")
253237
escaped_path = quote(path.strip("/"))
254238
if escaped_path:
255239
escaped_path = "/" + escaped_path
@@ -268,9 +252,7 @@ def request(
268252
)
269253
elif binary_data is not None:
270254
headers["Content-type"] = "application/octet-stream"
271-
return self._request(
272-
method, url, data=binary_data, headers=headers, timeout=timeout
273-
)
255+
return self._request(method, url, data=binary_data, headers=headers, timeout=timeout)
274256
return self._request(method, url, data=data, headers=headers, timeout=timeout)
275257

276258
def get(

plugins/module_utils/cluster.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,15 @@ def __eq__(self, other: object) -> bool:
6565

6666
@classmethod
6767
def get(cls, rest_client: RestClient, must_exist: bool = True) -> Cluster:
68-
hypercore_dict = rest_client.get_record(
69-
"/rest/v1/Cluster", must_exist=must_exist
70-
)
68+
hypercore_dict = rest_client.get_record("/rest/v1/Cluster", must_exist=must_exist)
7169
cluster = cls.from_hypercore(hypercore_dict) # type: ignore # cluster never None
7270
return cluster
7371

74-
def update_name(
75-
self, rest_client: RestClient, name_new: str, check_mode: bool = False
76-
) -> TypedTaskTag:
77-
return rest_client.update_record(
78-
f"/rest/v1/Cluster/{self.uuid}", dict(clusterName=name_new), check_mode
79-
)
72+
def update_name(self, rest_client: RestClient, name_new: str, check_mode: bool = False) -> TypedTaskTag:
73+
return rest_client.update_record(f"/rest/v1/Cluster/{self.uuid}", dict(clusterName=name_new), check_mode)
8074

8175
@staticmethod
82-
def shutdown(
83-
rest_client: RestClient, force_shutdown: bool = False, check_mode: bool = False
84-
) -> None:
76+
def shutdown(rest_client: RestClient, force_shutdown: bool = False, check_mode: bool = False) -> None:
8577
try:
8678
rest_client.create_record(
8779
"/rest/v1/Cluster/shutdown",

plugins/module_utils/disk.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,8 @@ def from_hypercore(cls, hypercore_data: dict[Any, Any]) -> Optional[Disk]:
126126
disable_snapshotting=hypercore_data["disableSnapshotting"],
127127
# Hypercore sometimes returns values outside the mapping table, so we set it to default.
128128
tiering_priority_factor=(
129-
TIERING_PRIORITY_MAPPING_FROM_HYPERCORE[
130-
hypercore_data["tieringPriorityFactor"]
131-
]
132-
if hypercore_data["tieringPriorityFactor"]
133-
in TIERING_PRIORITY_MAPPING_FROM_HYPERCORE
129+
TIERING_PRIORITY_MAPPING_FROM_HYPERCORE[hypercore_data["tieringPriorityFactor"]]
130+
if hypercore_data["tieringPriorityFactor"] in TIERING_PRIORITY_MAPPING_FROM_HYPERCORE
134131
else TIERING_PRIORITY_DEFAULT
135132
),
136133
mount_points=hypercore_data["mountPoints"],
@@ -225,10 +222,6 @@ def needs_reboot(self, action: str, desired_disk=None) -> bool:
225222
return False
226223

227224
@classmethod
228-
def get_by_uuid(
229-
cls, uuid: str, rest_client: RestClient, must_exist: bool
230-
) -> Optional[Disk]:
231-
hypercore_dict = rest_client.get_record(
232-
f"/rest/v1/VirDomainBlockDevice/{uuid}", must_exist=must_exist
233-
)
225+
def get_by_uuid(cls, uuid: str, rest_client: RestClient, must_exist: bool) -> Optional[Disk]:
226+
hypercore_dict = rest_client.get_record(f"/rest/v1/VirDomainBlockDevice/{uuid}", must_exist=must_exist)
234227
return cls.from_hypercore(hypercore_dict)

plugins/module_utils/dns_config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ def __eq__(self, other):
7676
@classmethod
7777
def get_by_uuid(cls, ansible_dict, rest_client, must_exist=False):
7878
query = get_query(ansible_dict, "uuid", ansible_hypercore_map=dict(uuid="uuid"))
79-
hypercore_dict = rest_client.get_record(
80-
"/rest/v1/DNSConfig", query, must_exist=must_exist
81-
)
79+
hypercore_dict = rest_client.get_record("/rest/v1/DNSConfig", query, must_exist=must_exist)
8280
dns_config_from_hypercore = DNSConfig.from_hypercore(hypercore_dict)
8381
return dns_config_from_hypercore
8482

plugins/module_utils/email_alert.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ def get_by_uuid(
105105
must_exist: bool = False,
106106
) -> Optional[EmailAlert]:
107107
query = get_query(ansible_dict, "uuid", ansible_hypercore_map=dict(uuid="uuid"))
108-
hypercore_dict = rest_client.get_record(
109-
"/rest/v1/AlertEmailTarget", query, must_exist=must_exist
110-
)
108+
hypercore_dict = rest_client.get_record("/rest/v1/AlertEmailTarget", query, must_exist=must_exist)
111109
alert_email_from_hypercore = cls.from_hypercore(hypercore_dict)
112110
return alert_email_from_hypercore
113111

@@ -123,9 +121,7 @@ def get_by_email(
123121
"email",
124122
ansible_hypercore_map=dict(email="emailAddress"),
125123
)
126-
hypercore_dict = rest_client.get_record(
127-
"/rest/v1/AlertEmailTarget", query, must_exist=must_exist
128-
)
124+
hypercore_dict = rest_client.get_record("/rest/v1/AlertEmailTarget", query, must_exist=must_exist)
129125

130126
alert_email_from_hypercore = EmailAlert.from_hypercore(hypercore_dict)
131127
return alert_email_from_hypercore
@@ -141,13 +137,9 @@ def list_by_email(
141137
"email",
142138
ansible_hypercore_map=dict(email="emailAddress"),
143139
)
144-
hypercore_dict_list = rest_client.list_records(
145-
"/rest/v1/AlertEmailTarget", query
146-
)
140+
hypercore_dict_list = rest_client.list_records("/rest/v1/AlertEmailTarget", query)
147141

148-
alert_email_from_hypercore_list = [
149-
EmailAlert.from_hypercore(hc_dict) for hc_dict in hypercore_dict_list
150-
]
142+
alert_email_from_hypercore_list = [EmailAlert.from_hypercore(hc_dict) for hc_dict in hypercore_dict_list]
151143
return alert_email_from_hypercore_list
152144

153145
@classmethod
@@ -169,9 +161,7 @@ def create(
169161
payload: Dict[Any, Any],
170162
check_mode: bool = False,
171163
):
172-
task_tag = rest_client.create_record(
173-
"/rest/v1/AlertEmailTarget/", payload, check_mode
174-
)
164+
task_tag = rest_client.create_record("/rest/v1/AlertEmailTarget/", payload, check_mode)
175165
email_alert = cls.get_by_uuid(
176166
dict(uuid=task_tag["createdUUID"]),
177167
rest_client,
@@ -185,9 +175,7 @@ def update(
185175
payload: Dict[Any, Any],
186176
check_mode: bool = False,
187177
) -> None:
188-
rest_client.update_record(
189-
f"/rest/v1/AlertEmailTarget/{self.uuid}", payload, check_mode
190-
)
178+
rest_client.update_record(f"/rest/v1/AlertEmailTarget/{self.uuid}", payload, check_mode)
191179

192180
def delete(
193181
self,
@@ -200,7 +188,5 @@ def test(
200188
self,
201189
rest_client: RestClient,
202190
) -> TypedTaskTag:
203-
response = rest_client.client.post(
204-
f"/rest/v1/AlertEmailTarget/{self.uuid}/test", None
205-
)
191+
response = rest_client.client.post(f"/rest/v1/AlertEmailTarget/{self.uuid}/test", None)
206192
return response

plugins/module_utils/errors.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ def __init__(self, data: Union[str, Exception]):
7979

8080
class ReplicationNotUnique(ScaleComputingError):
8181
def __init__(self, data: Union[str, Exception]):
82-
self.message = (
83-
f"There is already a replication on - {data} - virtual machine"
84-
)
82+
self.message = f"There is already a replication on - {data} - virtual machine"
8583
super(ReplicationNotUnique, self).__init__(self.message)
8684

8785

@@ -93,9 +91,7 @@ def __init__(self, data: Union[str, Exception]):
9391

9492
class SMBServerNotFound(ScaleComputingError):
9593
def __init__(self, data: Union[str, Exception]):
96-
self.message = "SMB server is either not connected or not in the same network - {0}".format(
97-
data
98-
)
94+
self.message = "SMB server is either not connected or not in the same network - {0}".format(data)
9995
super(SMBServerNotFound, self).__init__(self.message)
10096

10197

plugins/module_utils/hypercore_version.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,8 @@ def __init__(self, rest_client: RestClient):
4242
def version(self) -> str:
4343
if not self._version:
4444
record = self._rest_client.get_record("/rest/v1/Cluster")
45-
if (
46-
record is None
47-
or "icosVersion" not in record
48-
or not isinstance(record["icosVersion"], str)
49-
):
50-
raise AssertionError(
51-
"HyperCore version not found in REST API response."
52-
)
45+
if record is None or "icosVersion" not in record or not isinstance(record["icosVersion"], str):
46+
raise AssertionError("HyperCore version not found in REST API response.")
5347
self._version = record["icosVersion"]
5448
return self._version
5549

@@ -182,9 +176,7 @@ def from_ansible(cls, ansible_data: dict[Any, Any]) -> None:
182176
pass
183177

184178
@classmethod
185-
def from_hypercore(
186-
cls, hypercore_data: Optional[dict[Any, Any]]
187-
) -> Optional[Update]:
179+
def from_hypercore(cls, hypercore_data: Optional[dict[Any, Any]]) -> Optional[Update]:
188180
if not hypercore_data:
189181
return None
190182
return cls(
@@ -243,9 +235,7 @@ def get(
243235
) -> Optional[Update]:
244236
# api has a bug - the endpoint "/rest/v1/Update/{uuid}" returns a list of all available updates (and uuid can actually be anything),
245237
# that is why query is used
246-
update = rest_client.get_record(
247-
f"/rest/v1/Update/{uuid}", query=dict(uuid=uuid), must_exist=must_exist
248-
)
238+
update = rest_client.get_record(f"/rest/v1/Update/{uuid}", query=dict(uuid=uuid), must_exist=must_exist)
249239
return cls.from_hypercore(update)
250240

251241
@classmethod
@@ -255,9 +245,7 @@ def apply_update(
255245
version: str,
256246
check_mode: bool = False,
257247
) -> TypedTaskTag:
258-
return rest_client.create_record(
259-
f"/rest/v1/Update/{version}/apply", payload=None, check_mode=check_mode
260-
)
248+
return rest_client.create_record(f"/rest/v1/Update/{version}/apply", payload=None, check_mode=check_mode)
261249

262250

263251
class UpdateStatus(PayloadMapper):
@@ -300,9 +288,7 @@ def from_hypercore(cls, hypercore_data: dict[Any, Any]) -> UpdateStatus:
300288
to_build=hypercore_data["updateStatus"].get("toBuild"),
301289
to_version=hypercore_data["updateStatus"].get("toVersion"),
302290
percent=hypercore_data["updateStatus"].get("percent"),
303-
update_status_details=hypercore_data["updateStatus"]["status"].get(
304-
"statusdetails"
305-
),
291+
update_status_details=hypercore_data["updateStatus"]["status"].get("statusdetails"),
306292
usernotes=hypercore_data["updateStatus"]["status"].get("usernotes"),
307293
)
308294

plugins/module_utils/iso.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
class ISO(PayloadMapper):
1818
# Variables in ISO are written in ansible-native format
19-
def __init__(
20-
self, name, uuid=None, size=-1, mounts=None, ready_for_insert=False, path=None
21-
):
19+
def __init__(self, name, uuid=None, size=-1, mounts=None, ready_for_insert=False, path=None):
2220
if mounts is None:
2321
mounts = []
2422
self.uuid = uuid
@@ -47,10 +45,7 @@ def from_hypercore(cls, hypercore_data):
4745
uuid=hypercore_data["uuid"],
4846
name=hypercore_data["name"],
4947
size=hypercore_data["size"],
50-
mounts=[
51-
dict(vm_uuid=mount["vmUUID"], vm_name=mount["vmName"])
52-
for mount in hypercore_data["mounts"]
53-
],
48+
mounts=[dict(vm_uuid=mount["vmUUID"], vm_name=mount["vmName"]) for mount in hypercore_data["mounts"]],
5449
ready_for_insert=hypercore_data["readyForInsert"],
5550
path=hypercore_data["path"],
5651
)
@@ -95,11 +90,7 @@ def __str__(self):
9590
return super().__str__()
9691

9792
def build_iso_post_paylaod(self):
98-
return {
99-
key: value
100-
for key, value in self.to_hypercore().items()
101-
if key in ("name", "size", "readyForInsert")
102-
}
93+
return {key: value for key, value in self.to_hypercore().items() if key in ("name", "size", "readyForInsert")}
10394

10495
@classmethod
10596
def get_by_name(cls, ansible_dict, rest_client, must_exist=False):
@@ -108,9 +99,7 @@ def get_by_name(cls, ansible_dict, rest_client, must_exist=False):
10899
the record exists. If there is no record with such name, None is returned.
109100
"""
110101
query = get_query(ansible_dict, "name", ansible_hypercore_map=dict(name="name"))
111-
hypercore_dict = rest_client.get_record(
112-
"/rest/v1/ISO", query, must_exist=must_exist
113-
)
102+
hypercore_dict = rest_client.get_record("/rest/v1/ISO", query, must_exist=must_exist)
114103
iso_from_hypercore = ISO.from_hypercore(hypercore_dict)
115104
return iso_from_hypercore
116105

plugins/module_utils/nic.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
"VIRTIO": "virtio",
2222
"INTEL_E1000": "INTEL_E1000",
2323
}
24-
FROM_ANSIBLE_TO_HYPERCORE_NIC_TYPE = {
25-
v: k for k, v in FROM_HYPERCORE_TO_ANSIBLE_NIC_TYPE.items()
26-
}
24+
FROM_ANSIBLE_TO_HYPERCORE_NIC_TYPE = {v: k for k, v in FROM_HYPERCORE_TO_ANSIBLE_NIC_TYPE.items()}
2725

2826

2927
# Maybe create enums.py or scale_enums.py and move all enum classes there? @Jure @Justin
@@ -56,29 +54,13 @@ def __eq__(self, other):
5654
elif other.vlan_new is not None and not other.mac_new:
5755
return self.vlan == other.vlan_new and self.type == other.type
5856
elif self.mac_new and self.vlan_new is None:
59-
return (
60-
self.vlan == other.vlan
61-
and self.type == other.type
62-
and self.mac_new == other.mac
63-
)
57+
return self.vlan == other.vlan and self.type == other.type and self.mac_new == other.mac
6458
elif other.mac_new and other.vlan_new is None:
65-
return (
66-
self.vlan == other.vlan
67-
and self.type == other.type
68-
and self.mac == other.mac_new
69-
)
59+
return self.vlan == other.vlan and self.type == other.type and self.mac == other.mac_new
7060
elif self.vlan_new is not None and self.mac_new:
71-
return (
72-
self.vlan_new == other.vlan
73-
and self.type == other.type
74-
and self.mac_new == other.mac
75-
)
61+
return self.vlan_new == other.vlan and self.type == other.type and self.mac_new == other.mac
7662
elif other.vlan_new is not None and other.mac_new:
77-
return (
78-
self.vlan == other.vlan_new
79-
and self.type == other.type
80-
and self.mac == other.mac_new
81-
)
63+
return self.vlan == other.vlan_new and self.type == other.type and self.mac == other.mac_new
8264
return self.vlan == other.vlan and self.type == other.type
8365

8466
@classmethod

plugins/module_utils/node.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ def __eq__(self, other):
6363

6464
@classmethod
6565
def get_node(cls, query, rest_client, must_exist=False):
66-
hypercore_dict = rest_client.get_record(
67-
"/rest/v1/Node", query, must_exist=must_exist
68-
)
66+
hypercore_dict = rest_client.get_record("/rest/v1/Node", query, must_exist=must_exist)
6967
node_from_hypercore = cls.from_hypercore(hypercore_dict)
7068
return node_from_hypercore

0 commit comments

Comments
 (0)