Skip to content

Commit 1841de9

Browse files
committed
flynt
Signed-off-by: Justin Cinkelj <[email protected]>
1 parent 56a1a56 commit 1841de9

File tree

17 files changed

+40
-58
lines changed

17 files changed

+40
-58
lines changed

plugins/module_utils/client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ def _request_no_log(
205205
# Wrong username/password, or expired access token
206206
if e.code == 401:
207207
raise AuthError(
208-
"Failed to authenticate with the instance: {0} {1}".format(
209-
e.code, e.reason
210-
),
208+
f"Failed to authenticate with the instance: {e.code} {e.reason}",
211209
)
212210
# Other HTTP error codes do not necessarily mean errors.
213211
# This is for the caller to decide.
@@ -255,9 +253,9 @@ def request(
255253
escaped_path = quote(path.strip("/"))
256254
if escaped_path:
257255
escaped_path = "/" + escaped_path
258-
url = "{0}{1}".format(self.host, escaped_path)
256+
url = f"{self.host}{escaped_path}"
259257
if query:
260-
url = "{0}?{1}".format(url, urlencode(query))
258+
url = f"{url}?{urlencode(query)}"
261259
headers = dict(headers or DEFAULT_HEADERS, **self.auth_header)
262260
if data is not None:
263261
headers["Content-type"] = "application/json"

plugins/module_utils/errors.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,63 +33,61 @@ def __init__(self, message: str):
3333

3434
class UnexpectedAPIResponse(ScaleComputingError):
3535
def __init__(self, response: Request):
36-
self.message = "Unexpected response - {0} {1}".format(
37-
response.status, response.data
38-
)
36+
self.message = f"Unexpected response - {response.status} {response.data}"
3937
self.response_status = response.status
4038
super(UnexpectedAPIResponse, self).__init__(self.message)
4139

4240

4341
class InvalidUuidFormatError(ScaleComputingError):
4442
def __init__(self, data: Union[str, Exception]):
45-
self.message = "Invalid UUID - {0}".format(data)
43+
self.message = f"Invalid UUID - {data}"
4644
super(InvalidUuidFormatError, self).__init__(self.message)
4745

4846

4947
# In-case function parameter is optional but required
5048
class MissingFunctionParameter(ScaleComputingError):
5149
def __init__(self, data: Union[str, Exception]):
52-
self.message = "Missing parameter - {0}".format(data)
50+
self.message = f"Missing parameter - {data}"
5351
super(MissingFunctionParameter, self).__init__(self.message)
5452

5553

5654
# In-case argument spec doesn't catch exception
5755
class MissingValueAnsible(ScaleComputingError):
5856
def __init__(self, data: Union[str, Exception]):
59-
self.message = "Missing value - {0}".format(data)
57+
self.message = f"Missing value - {data}"
6058
super(MissingValueAnsible, self).__init__(self.message)
6159

6260

6361
# In-case argument spec doesn't catch exception
6462
class MissingValueHypercore(ScaleComputingError):
6563
def __init__(self, data: Union[str, Exception]):
66-
self.message = "Missing values from hypercore API - {0}".format(data)
64+
self.message = f"Missing values from hypercore API - {data}"
6765
super(MissingValueHypercore, self).__init__(self.message)
6866

6967

7068
class DeviceNotUnique(ScaleComputingError):
7169
def __init__(self, data: Union[str, Exception]):
72-
self.message = "Device is not unique - {0} - already exists".format(data)
70+
self.message = f"Device is not unique - {data} - already exists"
7371
super(DeviceNotUnique, self).__init__(self.message)
7472

7573

7674
class VMNotFound(ScaleComputingError):
7775
def __init__(self, data: Union[str, Exception]):
78-
self.message = "Virtual machine - {0} - not found".format(data)
76+
self.message = f"Virtual machine - {data} - not found"
7977
super(VMNotFound, self).__init__(self.message)
8078

8179

8280
class ReplicationNotUnique(ScaleComputingError):
8381
def __init__(self, data: Union[str, Exception]):
8482
self.message = (
85-
"There is already a replication on - {0} - virtual machine".format(data)
83+
f"There is already a replication on - {data} - virtual machine"
8684
)
8785
super(ReplicationNotUnique, self).__init__(self.message)
8886

8987

9088
class ClusterConnectionNotFound(ScaleComputingError):
9189
def __init__(self, data: Union[str, Exception]):
92-
self.message = "No cluster connection found - {0}".format(data)
90+
self.message = f"No cluster connection found - {data}"
9391
super(ClusterConnectionNotFound, self).__init__(self.message)
9492

9593

@@ -109,7 +107,7 @@ def __init__(self) -> None:
109107

110108
class SupportTunnelError(ScaleComputingError):
111109
def __init__(self, data: Union[str, Exception]):
112-
self.message = "{0}".format(data)
110+
self.message = f"{data}"
113111
super(SupportTunnelError, self).__init__(self.message)
114112

115113

plugins/module_utils/rest_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ def get_record(
7777
)
7878
if must_exist and not records:
7979
raise errors.ScaleComputingError(
80-
"No records from endpoint {0} match the {1} query.".format(
81-
endpoint, query
82-
)
80+
f"No records from endpoint {endpoint} match the {query} query."
8381
)
8482
return records[0] if records else None
8583

plugins/module_utils/role.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def get_role_from_uuid(
6666
cls, role_uuid: str, rest_client: RestClient, must_exist: bool = False
6767
) -> Optional[Role]:
6868
hypercore_dict = rest_client.get_record(
69-
"/rest/v1/Role/{0}".format(role_uuid), must_exist=must_exist
69+
f"/rest/v1/Role/{role_uuid}", must_exist=must_exist
7070
)
7171
role = cls.from_hypercore(hypercore_dict)
7272
return role

plugins/module_utils/task_tag.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def wait_task(
4242

4343
while True:
4444
task_status = rest_client.get_record(
45-
"{0}/{1}".format("/rest/v1/TaskTag", task["taskTag"]), query={}
45+
f"/rest/v1/TaskTag/{task['taskTag']}", query={}
4646
)
4747
if task_status is None: # No such task_status is found
4848
break
@@ -71,6 +71,6 @@ def get_task_status(
7171
if not task["taskTag"]:
7272
return None
7373
task_status: Optional[Dict[Any, Any]] = rest_client.get_record(
74-
"{0}/{1}".format("/rest/v1/TaskTag", task["taskTag"]), query={}
74+
f"/rest/v1/TaskTag/{task['taskTag']}", query={}
7575
)
7676
return task_status if task_status else None

plugins/module_utils/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_user_from_uuid(
8989
cls, user_uuid, rest_client: RestClient, must_exist: bool = False
9090
) -> Optional[User]:
9191
hypercore_dict = rest_client.get_record(
92-
"/rest/v1/User/{0}".format(user_uuid), must_exist=must_exist
92+
f"/rest/v1/User/{user_uuid}", must_exist=must_exist
9393
)
9494
user = cls.from_hypercore(hypercore_dict)
9595
return user

plugins/module_utils/vm.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,7 @@ def filter_specific_objects(results, query, object_type):
809809
filtered_results = filter_results(results, query)
810810
if len(filtered_results) > 1:
811811
raise errors.ScaleComputingError(
812-
"{0} isn't uniquely identifyed by {1} in the VM.".format(
813-
object_type, query
814-
)
812+
f"{object_type} isn't uniquely identifyed by {query} in the VM."
815813
)
816814
return filtered_results[0] if filtered_results else None
817815

@@ -843,7 +841,7 @@ def update_boot_device_order(module, rest_client, vm, boot_order):
843841
# uuid is vm's uuid. boot_order is the desired order we want to set to boot devices
844842
vm.do_shutdown_steps(module, rest_client)
845843
task_tag = rest_client.update_record(
846-
"{0}/{1}".format("/rest/v1/VirDomain", vm.uuid),
844+
f"/rest/v1/VirDomain/{vm.uuid}",
847845
dict(bootDevices=boot_order),
848846
module.check_mode,
849847
)
@@ -1297,7 +1295,7 @@ def set_vm_params(cls, module, rest_client, vm, param_subset: List[str]):
12971295

12981296
if changed:
12991297
payload = ManageVMParams._build_payload(module, rest_client)
1300-
endpoint = "{0}/{1}".format("/rest/v1/VirDomain", vm.uuid)
1298+
endpoint = f"/rest/v1/VirDomain/{vm.uuid}"
13011299
task_tag = rest_client.update_record(endpoint, payload, module.check_mode)
13021300
TaskTag.wait_task(rest_client, task_tag)
13031301

@@ -1396,7 +1394,7 @@ def iso_image_management(module, rest_client, iso, uuid, attach):
13961394
# If false, it means you're detaching an image.
13971395
payload = iso.attach_iso_payload() if attach else iso.detach_iso_payload()
13981396
task_tag = rest_client.update_record(
1399-
"{0}/{1}".format("/rest/v1/VirDomainBlockDevice", uuid),
1397+
f"/rest/v1/VirDomainBlockDevice/{uuid}",
14001398
payload,
14011399
module.check_mode,
14021400
)
@@ -1412,7 +1410,7 @@ def _update_block_device(
14121410
if existing_disk.needs_reboot("update", desired_disk):
14131411
vm.do_shutdown_steps(module, rest_client)
14141412
task_tag = rest_client.update_record(
1415-
"{0}/{1}".format("/rest/v1/VirDomainBlockDevice", existing_disk.uuid),
1413+
f"/rest/v1/VirDomainBlockDevice/{existing_disk.uuid}",
14161414
payload,
14171415
module.check_mode,
14181416
)
@@ -1446,9 +1444,7 @@ def _delete_not_used_disks(cls, module, rest_client, vm, changed, disk_key):
14461444
if existing_disk.needs_reboot("delete"):
14471445
vm.do_shutdown_steps(module, rest_client)
14481446
task_tag = rest_client.delete_record(
1449-
"{0}/{1}".format(
1450-
"/rest/v1/VirDomainBlockDevice", existing_disk.uuid
1451-
),
1447+
f"/rest/v1/VirDomainBlockDevice/{existing_disk.uuid}",
14521448
module.check_mode,
14531449
)
14541450
try:
@@ -1468,9 +1464,7 @@ def _delete_not_used_disks(cls, module, rest_client, vm, changed, disk_key):
14681464
# shutdown and retry remove
14691465
vm.do_shutdown_steps(module, rest_client)
14701466
task_tag = rest_client.delete_record(
1471-
"{0}/{1}".format(
1472-
"/rest/v1/VirDomainBlockDevice", existing_disk.uuid
1473-
),
1467+
f"/rest/v1/VirDomainBlockDevice/{existing_disk.uuid}",
14741468
module.check_mode,
14751469
)
14761470
TaskTag.wait_task(rest_client, task_tag, module.check_mode)
@@ -1507,7 +1501,7 @@ def _force_remove_all_disks(module, rest_client, vm, disks_before):
15071501
# Delete all disks
15081502
for existing_disk in vm.disks:
15091503
task_tag = rest_client.delete_record(
1510-
"{0}/{1}".format("/rest/v1/VirDomainBlockDevice", existing_disk.uuid),
1504+
f"/rest/v1/VirDomainBlockDevice/{existing_disk.uuid}",
15111505
module.check_mode,
15121506
)
15131507
TaskTag.wait_task(rest_client, task_tag, module.check_mode)

plugins/modules/dns_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ def modify_dns_config(
230230
# update_record method uses method PATCH,
231231
# create_record method uses method POST.
232232
# [ NOTE: PUT method is not allowed on DNS Config ]
233-
task_tag = getattr(rest_client, "{0}_record".format(action))(
234-
endpoint="{0}/{1}".format("/rest/v1/DNSConfig", dns_config.uuid),
233+
task_tag = getattr(rest_client, f"{action}_record")(
234+
endpoint=f"/rest/v1/DNSConfig/{dns_config.uuid}",
235235
payload=dict(searchDomains=new_search_domains, serverIPs=new_dns_servers),
236236
check_mode=module.check_mode,
237237
)

plugins/modules/iso.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def ensure_present(module, rest_client):
201201
file_size = os.stat(module.params["source"]).st_size
202202
with open(module.params["source"], "rb") as source_file:
203203
rest_client.put_record(
204-
endpoint="/rest/v1/ISO/%s/data" % iso_uuid,
204+
endpoint=f"/rest/v1/ISO/{iso_uuid}/data",
205205
payload=None,
206206
check_mode=module.check_mode,
207207
timeout=ISO_TIMEOUT_TIME,
@@ -221,7 +221,7 @@ def ensure_present(module, rest_client):
221221

222222
# Now the ISO image is ready for insertion. Updating readyForInsert to True.
223223
task_tag_update = rest_client.update_record(
224-
endpoint="{0}/{1}".format("/rest/v1/ISO", iso_uuid),
224+
endpoint=f"/rest/v1/ISO/{iso_uuid}",
225225
payload=dict(readyForInsert=True),
226226
check_mode=module.check_mode,
227227
)
@@ -234,7 +234,7 @@ def ensure_absent(module, rest_client):
234234
iso_image = ISO.get_by_name(module.params, rest_client)
235235
if iso_image:
236236
task_tag_delete = rest_client.delete_record(
237-
endpoint="{0}/{1}".format("/rest/v1/ISO", iso_image.uuid),
237+
endpoint=f"/rest/v1/ISO/{iso_image.uuid}",
238238
check_mode=module.check_mode,
239239
)
240240
TaskTag.wait_task(rest_client, task_tag_delete)

plugins/modules/smtp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def modify_smtp_config(module: AnsibleModule, rest_client: RestClient) -> Tuple[
277277
# Set the task tag
278278
# update_record -> PATCH
279279
update_task_tag = rest_client.update_record(
280-
endpoint="{0}/{1}".format("/rest/v1/AlertSMTPConfig", smtp.uuid),
280+
endpoint=f"/rest/v1/AlertSMTPConfig/{smtp.uuid}",
281281
payload=payload,
282282
check_mode=module.check_mode,
283283
)

0 commit comments

Comments
 (0)