diff --git a/changelogs/fragments/10976-mod-fstr-sae.yml b/changelogs/fragments/10976-mod-fstr-sae.yml new file mode 100644 index 0000000000..aebed22161 --- /dev/null +++ b/changelogs/fragments/10976-mod-fstr-sae.yml @@ -0,0 +1,28 @@ +minor_changes: + - say - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_compute - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_compute_private_network - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_container - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_container_info - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_container_namespace - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_container_namespace_info - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_container_registry - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_container_registry_info - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_database_backup - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_function - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_function_info - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_function_namespace - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_function_namespace_info - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_ip - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_lb - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_private_network - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_security_group - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_security_group_rule - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_sshkey - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_user_data - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - scaleway_volume - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - sefcontext - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - selogin - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - sendgrid - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - seport - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). + - serverless - use f-strings for string templating (https://github.com/ansible-collections/community.general/pull/10976). diff --git a/plugins/modules/say.py b/plugins/modules/say.py index 84dc65a840..b19e9212ad 100644 --- a/plugins/modules/say.py +++ b/plugins/modules/say.py @@ -83,7 +83,7 @@ def main(): if executable: break else: - module.fail_json(msg='Unable to find either %s' % ', '.join(possibles)) + module.fail_json(msg=f"Unable to find either {', '.join(possibles)}") if module.check_mode: module.exit_json(msg=msg, changed=False) diff --git a/plugins/modules/scaleway_compute.py b/plugins/modules/scaleway_compute.py index 4cc23f9571..8214a05117 100644 --- a/plugins/modules/scaleway_compute.py +++ b/plugins/modules/scaleway_compute.py @@ -205,29 +205,29 @@ SCALEWAY_TRANSITIONS_STATES = ( def check_image_id(compute_api, image_id): - response = compute_api.get(path="images/%s" % image_id) + response = compute_api.get(path=f"images/{image_id}") if not response.ok: - msg = 'Error in getting image %s on %s : %s' % (image_id, compute_api.module.params.get('api_url'), response.json) + msg = f"Error in getting image {image_id} on {compute_api.module.params.get('api_url')} : {response.json}" compute_api.module.fail_json(msg=msg) def fetch_state(compute_api, server): - compute_api.module.debug("fetch_state of server: %s" % server["id"]) - response = compute_api.get(path="servers/%s" % server["id"]) + compute_api.module.debug(f"fetch_state of server: {server['id']}") + response = compute_api.get(path=f"servers/{server['id']}") if response.status_code == 404: return "absent" if not response.ok: - msg = 'Error during state fetching: (%s) %s' % (response.status_code, response.json) + msg = f'Error during state fetching: ({response.status_code}) {response.json}' compute_api.module.fail_json(msg=msg) try: - compute_api.module.debug("Server %s in state: %s" % (server["id"], response.json["server"]["state"])) + compute_api.module.debug(f"Server {server['id']} in state: {response.json['server']['state']}") return response.json["server"]["state"] except KeyError: - compute_api.module.fail_json(msg="Could not fetch state in %s" % response.json) + compute_api.module.fail_json(msg=f"Could not fetch state in {response.json}") def wait_to_complete_state_transition(compute_api, server, wait=None): @@ -245,7 +245,7 @@ def wait_to_complete_state_transition(compute_api, server, wait=None): compute_api.module.debug("We are going to wait for the server to finish its transition") if fetch_state(compute_api, server) not in SCALEWAY_TRANSITIONS_STATES: compute_api.module.debug("It seems that the server is not in transition anymore.") - compute_api.module.debug("Server in state: %s" % fetch_state(compute_api, server)) + compute_api.module.debug(f"Server in state: {fetch_state(compute_api, server)}") break time.sleep(wait_sleep_time) else: @@ -264,14 +264,14 @@ def public_ip_payload(compute_api, public_ip): # We check that the IP we want to attach exists, if so its ID is returned response = compute_api.get("ips") if not response.ok: - msg = 'Error during public IP validation: (%s) %s' % (response.status_code, response.json) + msg = f'Error during public IP validation: ({response.status_code}) {response.json}' compute_api.module.fail_json(msg=msg) ip_list = [] try: ip_list = response.json["ips"] except KeyError: - compute_api.module.fail_json(msg="Error in getting the IP information from: %s" % response.json) + compute_api.module.fail_json(msg=f"Error in getting the IP information from: {response.json}") lookup = [ip["id"] for ip in ip_list] if public_ip in lookup: @@ -301,13 +301,13 @@ def create_server(compute_api, server): response = compute_api.post(path="servers", data=data) if not response.ok: - msg = 'Error during server creation: (%s) %s' % (response.status_code, response.json) + msg = f'Error during server creation: ({response.status_code}) {response.json}' compute_api.module.fail_json(msg=msg) try: target_server = response.json["server"] except KeyError: - compute_api.module.fail_json(msg="Error in getting the server information from: %s" % response.json) + compute_api.module.fail_json(msg=f"Error in getting the server information from: {response.json}") wait_to_complete_state_transition(compute_api=compute_api, server=target_server) @@ -327,10 +327,10 @@ def start_server(compute_api, server): def perform_action(compute_api, server, action): - response = compute_api.post(path="servers/%s/action" % server["id"], + response = compute_api.post(path=f"servers/{server['id']}/action", data={"action": action}) if not response.ok: - msg = 'Error during server %s: (%s) %s' % (action, response.status_code, response.json) + msg = f'Error during server {action}: ({response.status_code}) {response.json}' compute_api.module.fail_json(msg=msg) wait_to_complete_state_transition(compute_api=compute_api, server=server) @@ -340,9 +340,9 @@ def perform_action(compute_api, server, action): def remove_server(compute_api, server): compute_api.module.debug("Starting remove server strategy") - response = compute_api.delete(path="servers/%s" % server["id"]) + response = compute_api.delete(path=f"servers/{server['id']}") if not response.ok: - msg = 'Error during server deletion: (%s) %s' % (response.status_code, response.json) + msg = f'Error during server deletion: ({response.status_code}) {response.json}' compute_api.module.fail_json(msg=msg) wait_to_complete_state_transition(compute_api=compute_api, server=server) @@ -369,7 +369,7 @@ def present_strategy(compute_api, wished_server): changed = True if compute_api.module.check_mode: - return changed, {"status": "Server %s attributes would be changed." % target_server["id"]} + return changed, {"status": f"Server {target_server['id']} attributes would be changed."} target_server = server_change_attributes(compute_api=compute_api, target_server=target_server, wished_server=wished_server) @@ -390,7 +390,7 @@ def absent_strategy(compute_api, wished_server): changed = True if compute_api.module.check_mode: - return changed, {"status": "Server %s would be made absent." % target_server["id"]} + return changed, {"status": f"Server {target_server['id']} would be made absent."} # A server MUST be stopped to be deleted. while fetch_state(compute_api=compute_api, server=target_server) != "stopped": @@ -398,8 +398,7 @@ def absent_strategy(compute_api, wished_server): response = stop_server(compute_api=compute_api, server=target_server) if not response.ok: - err_msg = 'Error while stopping a server before removing it [{0}: {1}]'.format(response.status_code, - response.json) + err_msg = f'Error while stopping a server before removing it [{response.status_code}: {response.json}]' compute_api.module.fail_json(msg=err_msg) wait_to_complete_state_transition(compute_api=compute_api, server=target_server, wait=True) @@ -407,10 +406,10 @@ def absent_strategy(compute_api, wished_server): response = remove_server(compute_api=compute_api, server=target_server) if not response.ok: - err_msg = 'Error while removing server [{0}: {1}]'.format(response.status_code, response.json) + err_msg = f'Error while removing server [{response.status_code}: {response.json}]' compute_api.module.fail_json(msg=err_msg) - return changed, {"status": "Server %s deleted" % target_server["id"]} + return changed, {"status": f"Server {target_server['id']} deleted"} def running_strategy(compute_api, wished_server): @@ -432,21 +431,21 @@ def running_strategy(compute_api, wished_server): changed = True if compute_api.module.check_mode: - return changed, {"status": "Server %s attributes would be changed before running it." % target_server["id"]} + return changed, {"status": f"Server {target_server['id']} attributes would be changed before running it."} target_server = server_change_attributes(compute_api=compute_api, target_server=target_server, wished_server=wished_server) current_state = fetch_state(compute_api=compute_api, server=target_server) if current_state not in ("running", "starting"): - compute_api.module.debug("running_strategy: Server in state: %s" % current_state) + compute_api.module.debug(f"running_strategy: Server in state: {current_state}") changed = True if compute_api.module.check_mode: - return changed, {"status": "Server %s attributes would be changed." % target_server["id"]} + return changed, {"status": f"Server {target_server['id']} attributes would be changed."} response = start_server(compute_api=compute_api, server=target_server) if not response.ok: - msg = 'Error while running server [{0}: {1}]'.format(response.status_code, response.json) + msg = f'Error while running server [{response.status_code}: {response.json}]' compute_api.module.fail_json(msg=msg) return changed, target_server @@ -476,7 +475,7 @@ def stop_strategy(compute_api, wished_server): if compute_api.module.check_mode: return changed, { - "status": "Server %s attributes would be changed before stopping it." % target_server["id"]} + "status": f"Server {target_server['id']} attributes would be changed before stopping it."} target_server = server_change_attributes(compute_api=compute_api, target_server=target_server, wished_server=wished_server) @@ -484,19 +483,19 @@ def stop_strategy(compute_api, wished_server): current_state = fetch_state(compute_api=compute_api, server=target_server) if current_state not in ("stopped",): - compute_api.module.debug("stop_strategy: Server in state: %s" % current_state) + compute_api.module.debug(f"stop_strategy: Server in state: {current_state}") changed = True if compute_api.module.check_mode: - return changed, {"status": "Server %s would be stopped." % target_server["id"]} + return changed, {"status": f"Server {target_server['id']} would be stopped."} response = stop_server(compute_api=compute_api, server=target_server) compute_api.module.debug(response.json) compute_api.module.debug(response.ok) if not response.ok: - msg = 'Error while stopping server [{0}: {1}]'.format(response.status_code, response.json) + msg = f'Error while stopping server [{response.status_code}: {response.json}]' compute_api.module.fail_json(msg=msg) return changed, target_server @@ -523,13 +522,13 @@ def restart_strategy(compute_api, wished_server): if compute_api.module.check_mode: return changed, { - "status": "Server %s attributes would be changed before rebooting it." % target_server["id"]} + "status": f"Server {target_server['id']} attributes would be changed before rebooting it."} target_server = server_change_attributes(compute_api=compute_api, target_server=target_server, wished_server=wished_server) changed = True if compute_api.module.check_mode: - return changed, {"status": "Server %s would be rebooted." % target_server["id"]} + return changed, {"status": f"Server {target_server['id']} would be rebooted."} wait_to_complete_state_transition(compute_api=compute_api, server=target_server) @@ -537,16 +536,14 @@ def restart_strategy(compute_api, wished_server): response = restart_server(compute_api=compute_api, server=target_server) wait_to_complete_state_transition(compute_api=compute_api, server=target_server) if not response.ok: - msg = 'Error while restarting server that was running [{0}: {1}].'.format(response.status_code, - response.json) + msg = f'Error while restarting server that was running [{response.status_code}: {response.json}].' compute_api.module.fail_json(msg=msg) if fetch_state(compute_api=compute_api, server=target_server) in ("stopped",): response = restart_server(compute_api=compute_api, server=target_server) wait_to_complete_state_transition(compute_api=compute_api, server=target_server) if not response.ok: - msg = 'Error while restarting server that was stopped [{0}: {1}].'.format(response.status_code, - response.json) + msg = f'Error while restarting server that was stopped [{response.status_code}: {response.json}].' compute_api.module.fail_json(msg=msg) return changed, target_server @@ -568,7 +565,7 @@ def find(compute_api, wished_server, per_page=1): "per_page": per_page}) if not response.ok: - msg = 'Error during server search: (%s) %s' % (response.status_code, response.json) + msg = f'Error during server search: ({response.status_code}) {response.json}' compute_api.module.fail_json(msg=msg) search_results = response.json["servers"] @@ -587,14 +584,14 @@ PATCH_MUTABLE_SERVER_ATTRIBUTES = ( def server_attributes_should_be_changed(compute_api, target_server, wished_server): compute_api.module.debug("Checking if server attributes should be changed") - compute_api.module.debug("Current Server: %s" % target_server) - compute_api.module.debug("Wished Server: %s" % wished_server) + compute_api.module.debug(f"Current Server: {target_server}") + compute_api.module.debug(f"Wished Server: {wished_server}") debug_dict = { x: (target_server[x], wished_server[x]) for x in PATCH_MUTABLE_SERVER_ATTRIBUTES if x in target_server and x in wished_server } - compute_api.module.debug("Debug dict %s" % debug_dict) + compute_api.module.debug(f"Debug dict {debug_dict}") try: for key in PATCH_MUTABLE_SERVER_ATTRIBUTES: if key in target_server and key in wished_server: @@ -626,16 +623,16 @@ def server_change_attributes(compute_api, target_server, wished_server): elif not isinstance(target_server[key], dict): patch_payload[key] = wished_server[key] - response = compute_api.patch(path="servers/%s" % target_server["id"], + response = compute_api.patch(path=f"servers/{target_server['id']}", data=patch_payload) if not response.ok: - msg = 'Error during server attributes patching: (%s) %s' % (response.status_code, response.json) + msg = f'Error during server attributes patching: ({response.status_code}) {response.json}' compute_api.module.fail_json(msg=msg) try: target_server = response.json["server"] except KeyError: - compute_api.module.fail_json(msg="Error in getting the server information from: %s" % response.json) + compute_api.module.fail_json(msg=f"Error in getting the server information from: {response.json}") wait_to_complete_state_transition(compute_api=compute_api, server=target_server) diff --git a/plugins/modules/scaleway_compute_private_network.py b/plugins/modules/scaleway_compute_private_network.py index 33be950f22..79274757df 100644 --- a/plugins/modules/scaleway_compute_private_network.py +++ b/plugins/modules/scaleway_compute_private_network.py @@ -127,9 +127,9 @@ from ansible.module_utils.basic import AnsibleModule def get_nics_info(api, compute_id, private_network_id): - response = api.get('servers/' + compute_id + '/private_nics') + response = api.get(f"servers/{compute_id}/private_nics") if not response.ok: - msg = "Error during get servers information: %s: '%s' (%s)" % (response.info['msg'], response.json['message'], response.json) + msg = f"Error during get servers information: {response.info['msg']}: '{response.json['message']}' ({response.json})" api.module.fail_json(msg=msg) i = 0 @@ -155,10 +155,10 @@ def present_strategy(api, compute_id, private_network_id): if api.module.check_mode: return changed, {"status": "a private network would be add to a server"} - response = api.post(path='servers/' + compute_id + '/private_nics', data=data) + response = api.post(path=f"servers/{compute_id}/private_nics", data=data) if not response.ok: - api.module.fail_json(msg='Error when adding a private network to a server [{0}: {1}]'.format(response.status_code, response.json)) + api.module.fail_json(msg=f'Error when adding a private network to a server [{response.status_code}: {response.json}]') return changed, response.json @@ -174,11 +174,10 @@ def absent_strategy(api, compute_id, private_network_id): if api.module.check_mode: return changed, {"status": "private network would be destroyed"} - response = api.delete('servers/' + compute_id + '/private_nics/' + nic['id']) + response = api.delete(f"servers/{compute_id}/private_nics/{nic['id']}") if not response.ok: - api.module.fail_json(msg='Error deleting private network from server [{0}: {1}]'.format( - response.status_code, response.json)) + api.module.fail_json(msg=f'Error deleting private network from server [{response.status_code}: {response.json}]') return changed, response.json diff --git a/plugins/modules/scaleway_container.py b/plugins/modules/scaleway_container.py index 2281c555c1..21c5882399 100644 --- a/plugins/modules/scaleway_container.py +++ b/plugins/modules/scaleway_container.py @@ -283,10 +283,9 @@ def absent_strategy(api, wished_cn): return changed, {"status": "Container would be destroyed"} api.wait_to_complete_state_transition(resource=target_cn, stable_states=STABLE_STATES, force_wait=True) - response = api.delete(path=api.api_path + "/%s" % target_cn["id"]) + response = api.delete(path=f"{api.api_path}/{target_cn['id']}") if not response.ok: - api.module.fail_json(msg='Error deleting container [{0}: {1}]'.format( - response.status_code, response.json)) + api.module.fail_json(msg=f'Error deleting container [{response.status_code}: {response.json}]') api.wait_to_complete_state_transition(resource=target_cn, stable_states=STABLE_STATES) return changed, response.json @@ -314,13 +313,11 @@ def present_strategy(api, wished_cn): data=payload_cn) if not creation_response.ok: - msg = "Error during container creation: %s: '%s' (%s)" % (creation_response.info['msg'], - creation_response.json['message'], - creation_response.json) + msg = f"Error during container creation: {creation_response.info['msg']}: '{creation_response.json['message']}' ({creation_response.json})" api.module.fail_json(msg=msg) api.wait_to_complete_state_transition(resource=creation_response.json, stable_states=STABLE_STATES) - response = api.get(path=api.api_path + "/%s" % creation_response.json["id"]) + response = api.get(path=f"{api.api_path}/{creation_response.json['id']}") return changed, response.json target_cn = cn_lookup[wished_cn["name"]] @@ -339,15 +336,14 @@ def present_strategy(api, wished_cn): if api.module.check_mode: return changed, {"status": "Container attributes would be changed."} - cn_patch_response = api.patch(path=api.api_path + "/%s" % target_cn["id"], + cn_patch_response = api.patch(path=f"{api.api_path}/{target_cn['id']}", data=patch_payload) if not cn_patch_response.ok: - api.module.fail_json(msg='Error during container attributes update: [{0}: {1}]'.format( - cn_patch_response.status_code, cn_patch_response.json['message'])) + api.module.fail_json(msg=f"Error during container attributes update: [{cn_patch_response.status_code}: {cn_patch_response.json['message']}]") api.wait_to_complete_state_transition(resource=target_cn, stable_states=STABLE_STATES) - response = api.get(path=api.api_path + "/%s" % target_cn["id"]) + response = api.get(path=f"{api.api_path}/{target_cn['id']}") return changed, response.json @@ -382,7 +378,7 @@ def core(module): } api = Scaleway(module=module) - api.api_path = "containers/v1beta1/regions/%s/containers" % region + api.api_path = f"containers/v1beta1/regions/{region}/containers" changed, summary = state_strategy[wished_container["state"]](api=api, wished_cn=wished_container) diff --git a/plugins/modules/scaleway_container_info.py b/plugins/modules/scaleway_container_info.py index fd729bf336..7ae30a4dd6 100644 --- a/plugins/modules/scaleway_container_info.py +++ b/plugins/modules/scaleway_container_info.py @@ -102,18 +102,15 @@ def info_strategy(api, wished_cn): cn_lookup = {cn["name"]: cn for cn in cn_list} if wished_cn["name"] not in cn_lookup: - msg = "Error during container lookup: Unable to find container named '%s' in namespace '%s'" % (wished_cn["name"], - wished_cn["namespace_id"]) + msg = f"Error during container lookup: Unable to find container named '{wished_cn['name']}' in namespace '{wished_cn['namespace_id']}'" api.module.fail_json(msg=msg) target_cn = cn_lookup[wished_cn["name"]] - response = api.get(path=api.api_path + "/%s" % target_cn["id"]) + response = api.get(path=f"{api.api_path}/{target_cn['id']}") if not response.ok: - msg = "Error during container lookup: %s: '%s' (%s)" % (response.info['msg'], - response.json['message'], - response.json) + msg = f"Error during container lookup: {response.info['msg']}: '{response.json['message']}' ({response.json})" api.module.fail_json(msg=msg) return response.json @@ -127,7 +124,7 @@ def core(module): } api = Scaleway(module=module) - api.api_path = "containers/v1beta1/regions/%s/containers" % region + api.api_path = f"containers/v1beta1/regions/{region}/containers" summary = info_strategy(api=api, wished_cn=wished_container) diff --git a/plugins/modules/scaleway_container_namespace.py b/plugins/modules/scaleway_container_namespace.py index 2d76f75315..e5305077a6 100644 --- a/plugins/modules/scaleway_container_namespace.py +++ b/plugins/modules/scaleway_container_namespace.py @@ -178,10 +178,9 @@ def absent_strategy(api, wished_cn): return changed, {"status": "Container namespace would be destroyed"} api.wait_to_complete_state_transition(resource=target_cn, stable_states=STABLE_STATES, force_wait=True) - response = api.delete(path=api.api_path + "/%s" % target_cn["id"]) + response = api.delete(path=f"{api.api_path}/{target_cn['id']}") if not response.ok: - api.module.fail_json(msg='Error deleting container namespace [{0}: {1}]'.format( - response.status_code, response.json)) + api.module.fail_json(msg=f'Error deleting container namespace [{response.status_code}: {response.json}]') api.wait_to_complete_state_transition(resource=target_cn, stable_states=STABLE_STATES) return changed, response.json @@ -206,13 +205,12 @@ def present_strategy(api, wished_cn): data=payload_cn) if not creation_response.ok: - msg = "Error during container namespace creation: %s: '%s' (%s)" % (creation_response.info['msg'], - creation_response.json['message'], - creation_response.json) + msg = (f"Error during container namespace creation: {creation_response.info['msg']}: " + f"'{creation_response.json['message']}' ({creation_response.json})") api.module.fail_json(msg=msg) api.wait_to_complete_state_transition(resource=creation_response.json, stable_states=STABLE_STATES) - response = api.get(path=api.api_path + "/%s" % creation_response.json["id"]) + response = api.get(path=f"{api.api_path}/{creation_response.json['id']}") return changed, response.json target_cn = cn_lookup[wished_cn["name"]] @@ -231,15 +229,14 @@ def present_strategy(api, wished_cn): if api.module.check_mode: return changed, {"status": "Container namespace attributes would be changed."} - cn_patch_response = api.patch(path=api.api_path + "/%s" % target_cn["id"], + cn_patch_response = api.patch(path=f"{api.api_path}/{target_cn['id']}", data=patch_payload) if not cn_patch_response.ok: - api.module.fail_json(msg='Error during container namespace attributes update: [{0}: {1}]'.format( - cn_patch_response.status_code, cn_patch_response.json['message'])) + api.module.fail_json(msg=f"Error during container namespace attributes update: [{cn_patch_response.status_code}: {cn_patch_response.json['message']}]") api.wait_to_complete_state_transition(resource=target_cn, stable_states=STABLE_STATES) - response = api.get(path=api.api_path + "/%s" % target_cn["id"]) + response = api.get(path=f"{api.api_path}/{target_cn['id']}") return changed, cn_patch_response.json @@ -263,7 +260,7 @@ def core(module): } api = Scaleway(module=module) - api.api_path = "containers/v1beta1/regions/%s/namespaces" % region + api.api_path = f"containers/v1beta1/regions/{region}/namespaces" changed, summary = state_strategy[wished_container_namespace["state"]](api=api, wished_cn=wished_container_namespace) diff --git a/plugins/modules/scaleway_container_namespace_info.py b/plugins/modules/scaleway_container_namespace_info.py index efd1b3b816..0f974cb973 100644 --- a/plugins/modules/scaleway_container_namespace_info.py +++ b/plugins/modules/scaleway_container_namespace_info.py @@ -93,18 +93,15 @@ def info_strategy(api, wished_cn): cn_lookup = {cn["name"]: cn for cn in cn_list} if wished_cn["name"] not in cn_lookup: - msg = "Error during container namespace lookup: Unable to find container namespace named '%s' in project '%s'" % (wished_cn["name"], - wished_cn["project_id"]) + msg = f"Error during container namespace lookup: Unable to find container namespace named '{wished_cn['name']}' in project '{wished_cn['project_id']}'" api.module.fail_json(msg=msg) target_cn = cn_lookup[wished_cn["name"]] - response = api.get(path=api.api_path + "/%s" % target_cn["id"]) + response = api.get(path=f"{api.api_path}/{target_cn['id']}") if not response.ok: - msg = "Error during container namespace lookup: %s: '%s' (%s)" % (response.info['msg'], - response.json['message'], - response.json) + msg = f"Error during container namespace lookup: {response.info['msg']}: '{response.json['message']}' ({response.json})" api.module.fail_json(msg=msg) return response.json @@ -118,7 +115,7 @@ def core(module): } api = Scaleway(module=module) - api.api_path = "containers/v1beta1/regions/%s/namespaces" % region + api.api_path = f"containers/v1beta1/regions/{region}/namespaces" summary = info_strategy(api=api, wished_cn=wished_container_namespace) diff --git a/plugins/modules/scaleway_container_registry.py b/plugins/modules/scaleway_container_registry.py index 179b9b5ff7..eb9665bc8b 100644 --- a/plugins/modules/scaleway_container_registry.py +++ b/plugins/modules/scaleway_container_registry.py @@ -161,10 +161,9 @@ def absent_strategy(api, wished_cr): return changed, {"status": "Container registry would be destroyed"} api.wait_to_complete_state_transition(resource=target_cr, stable_states=STABLE_STATES, force_wait=True) - response = api.delete(path=api.api_path + "/%s" % target_cr["id"]) + response = api.delete(path=f"{api.api_path}/{target_cr['id']}") if not response.ok: - api.module.fail_json(msg='Error deleting container registry [{0}: {1}]'.format( - response.status_code, response.json)) + api.module.fail_json(msg=f'Error deleting container registry [{response.status_code}: {response.json}]') api.wait_to_complete_state_transition(resource=target_cr, stable_states=STABLE_STATES) return changed, response.json @@ -189,13 +188,11 @@ def present_strategy(api, wished_cr): data=payload_cr) if not creation_response.ok: - msg = "Error during container registry creation: %s: '%s' (%s)" % (creation_response.info['msg'], - creation_response.json['message'], - creation_response.json) + msg = f"Error during container registry creation: {creation_response.info['msg']}: '{creation_response.json['message']}' ({creation_response.json})" api.module.fail_json(msg=msg) api.wait_to_complete_state_transition(resource=creation_response.json, stable_states=STABLE_STATES) - response = api.get(path=api.api_path + "/%s" % creation_response.json["id"]) + response = api.get(path=f"{api.api_path}/{creation_response.json['id']}") return changed, response.json target_cr = cr_lookup[wished_cr["name"]] @@ -211,15 +208,14 @@ def present_strategy(api, wished_cr): if api.module.check_mode: return changed, {"status": "Container registry attributes would be changed."} - cr_patch_response = api.patch(path=api.api_path + "/%s" % target_cr["id"], + cr_patch_response = api.patch(path=f"{api.api_path}/{target_cr['id']}", data=patch_payload) if not cr_patch_response.ok: - api.module.fail_json(msg='Error during container registry attributes update: [{0}: {1}]'.format( - cr_patch_response.status_code, cr_patch_response.json['message'])) + api.module.fail_json(msg=f"Error during container registry attributes update: [{cr_patch_response.status_code}: {cr_patch_response.json['message']}]") api.wait_to_complete_state_transition(resource=target_cr, stable_states=STABLE_STATES) - response = api.get(path=api.api_path + "/%s" % target_cr["id"]) + response = api.get(path=f"{api.api_path}/{target_cr['id']}") return changed, response.json @@ -240,7 +236,7 @@ def core(module): } api = Scaleway(module=module) - api.api_path = "registry/v1/regions/%s/namespaces" % region + api.api_path = f"registry/v1/regions/{region}/namespaces" changed, summary = state_strategy[wished_container_registry["state"]](api=api, wished_cr=wished_container_registry) diff --git a/plugins/modules/scaleway_container_registry_info.py b/plugins/modules/scaleway_container_registry_info.py index 6dac97234b..ce72bfc801 100644 --- a/plugins/modules/scaleway_container_registry_info.py +++ b/plugins/modules/scaleway_container_registry_info.py @@ -92,18 +92,15 @@ def info_strategy(api, wished_cn): cn_lookup = {cn["name"]: cn for cn in cn_list} if wished_cn["name"] not in cn_lookup: - msg = "Error during container registries lookup: Unable to find container registry named '%s' in project '%s'" % (wished_cn["name"], - wished_cn["project_id"]) + msg = f"Error during container registries lookup: Unable to find container registry named '{wished_cn['name']}' in project '{wished_cn['project_id']}'" api.module.fail_json(msg=msg) target_cn = cn_lookup[wished_cn["name"]] - response = api.get(path=api.api_path + "/%s" % target_cn["id"]) + response = api.get(path=f"{api.api_path}/{target_cn['id']}") if not response.ok: - msg = "Error during container registry lookup: %s: '%s' (%s)" % (response.info['msg'], - response.json['message'], - response.json) + msg = f"Error during container registry lookup: {response.info['msg']}: '{response.json['message']}' ({response.json})" api.module.fail_json(msg=msg) return response.json @@ -117,7 +114,7 @@ def core(module): } api = Scaleway(module=module) - api.api_path = "registry/v1/regions/%s/namespaces" % region + api.api_path = f"registry/v1/regions/{region}/namespaces" summary = info_strategy(api=api, wished_cn=wished_container_namespace) diff --git a/plugins/modules/scaleway_database_backup.py b/plugins/modules/scaleway_database_backup.py index 33497c41a9..7c07577dbb 100644 --- a/plugins/modules/scaleway_database_backup.py +++ b/plugins/modules/scaleway_database_backup.py @@ -199,15 +199,15 @@ def wait_to_complete_state_transition(module, account_api, backup=None): while now() < end: module.debug('We are going to wait for the backup to finish its transition') - response = account_api.get('/rdb/v1/regions/%s/backups/%s' % (module.params.get('region'), backup['id'])) + response = account_api.get(f"/rdb/v1/regions/{module.params.get('region')}/backups/{backup['id']}") if not response.ok: - module.fail_json(msg='Error getting backup [{0}: {1}]'.format(response.status_code, response.json)) + module.fail_json(msg=f'Error getting backup [{response.status_code}: {response.json}]') break response_json = response.json if response_json['status'] in stable_states: module.debug('It seems that the backup is not in transition anymore.') - module.debug('Backup in state: %s' % response_json['status']) + module.debug(f"Backup in state: {response_json['status']}") return response_json time.sleep(wait_sleep_time) else: @@ -235,13 +235,13 @@ def present_strategy(module, account_api, backup): if expiration_date is not None: payload['expires_at'] = expiration_date - response = account_api.patch('/rdb/v1/regions/%s/backups/%s' % (module.params.get('region'), backup['id']), + response = account_api.patch(f"/rdb/v1/regions/{module.params.get('region')}/backups/{backup['id']}", payload) if response.ok: result = wait_to_complete_state_transition(module, account_api, response.json) module.exit_json(changed=True, metadata=result) - module.fail_json(msg='Error modifying backup [{0}: {1}]'.format(response.status_code, response.json)) + module.fail_json(msg=f'Error modifying backup [{response.status_code}: {response.json}]') if module.check_mode: module.exit_json(changed=True) @@ -250,13 +250,13 @@ def present_strategy(module, account_api, backup): if expiration_date is not None: payload['expires_at'] = expiration_date - response = account_api.post('/rdb/v1/regions/%s/backups' % module.params.get('region'), payload) + response = account_api.post(f"/rdb/v1/regions/{module.params.get('region')}/backups", payload) if response.ok: result = wait_to_complete_state_transition(module, account_api, response.json) module.exit_json(changed=True, metadata=result) - module.fail_json(msg='Error creating backup [{0}: {1}]'.format(response.status_code, response.json)) + module.fail_json(msg=f'Error creating backup [{response.status_code}: {response.json}]') def absent_strategy(module, account_api, backup): @@ -266,17 +266,17 @@ def absent_strategy(module, account_api, backup): if module.check_mode: module.exit_json(changed=True) - response = account_api.delete('/rdb/v1/regions/%s/backups/%s' % (module.params.get('region'), backup['id'])) + response = account_api.delete(f"/rdb/v1/regions/{module.params.get('region')}/backups/{backup['id']}") if response.ok: result = wait_to_complete_state_transition(module, account_api, response.json) module.exit_json(changed=True, metadata=result) - module.fail_json(msg='Error deleting backup [{0}: {1}]'.format(response.status_code, response.json)) + module.fail_json(msg=f'Error deleting backup [{response.status_code}: {response.json}]') def exported_strategy(module, account_api, backup): if backup is None: - module.fail_json(msg=('Backup "%s" not found' % module.params['id'])) + module.fail_json(msg=f'Backup "{module.params["id"]}" not found') if backup['download_url'] is not None: module.exit_json(changed=False, metadata=backup) @@ -286,18 +286,18 @@ def exported_strategy(module, account_api, backup): backup = wait_to_complete_state_transition(module, account_api, backup) response = account_api.post( - '/rdb/v1/regions/%s/backups/%s/export' % (module.params.get('region'), backup['id']), {}) + f"/rdb/v1/regions/{module.params.get('region')}/backups/{backup['id']}/export", {}) if response.ok: result = wait_to_complete_state_transition(module, account_api, response.json) module.exit_json(changed=True, metadata=result) - module.fail_json(msg='Error exporting backup [{0}: {1}]'.format(response.status_code, response.json)) + module.fail_json(msg=f'Error exporting backup [{response.status_code}: {response.json}]') def restored_strategy(module, account_api, backup): if backup is None: - module.fail_json(msg=('Backup "%s" not found' % module.params['id'])) + module.fail_json(msg=f'Backup "{module.params["id"]}" not found') database_name = module.params['database_name'] instance_id = module.params['instance_id'] @@ -308,14 +308,14 @@ def restored_strategy(module, account_api, backup): backup = wait_to_complete_state_transition(module, account_api, backup) payload = {'database_name': database_name, 'instance_id': instance_id} - response = account_api.post('/rdb/v1/regions/%s/backups/%s/restore' % (module.params.get('region'), backup['id']), + response = account_api.post(f"/rdb/v1/regions/{module.params.get('region')}/backups/{backup['id']}/restore", payload) if response.ok: result = wait_to_complete_state_transition(module, account_api, response.json) module.exit_json(changed=True, metadata=result) - module.fail_json(msg='Error restoring backup [{0}: {1}]'.format(response.status_code, response.json)) + module.fail_json(msg=f'Error restoring backup [{response.status_code}: {response.json}]') state_strategy = { @@ -335,7 +335,7 @@ def core(module): if backup_id is None: backup_by_id = None else: - response = account_api.get('/rdb/v1/regions/%s/backups/%s' % (module.params.get('region'), backup_id)) + response = account_api.get(f"/rdb/v1/regions/{module.params.get('region')}/backups/{backup_id}") status_code = response.status_code backup_json = response.json backup_by_id = None @@ -344,7 +344,7 @@ def core(module): elif response.ok: backup_by_id = backup_json else: - module.fail_json(msg='Error getting backup [{0}: {1}]'.format(status_code, response.json['message'])) + module.fail_json(msg=f"Error getting backup [{status_code}: {response.json['message']}]") state_strategy[state](module, account_api, backup_by_id) diff --git a/plugins/modules/scaleway_function.py b/plugins/modules/scaleway_function.py index a8d0680c71..27e404ba10 100644 --- a/plugins/modules/scaleway_function.py +++ b/plugins/modules/scaleway_function.py @@ -258,10 +258,9 @@ def absent_strategy(api, wished_fn): return changed, {"status": "Function would be destroyed"} api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES, force_wait=True) - response = api.delete(path=api.api_path + "/%s" % target_fn["id"]) + response = api.delete(path=f"{api.api_path}/{target_fn['id']}") if not response.ok: - api.module.fail_json(msg='Error deleting function [{0}: {1}]'.format( - response.status_code, response.json)) + api.module.fail_json(msg=f'Error deleting function [{response.status_code}: {response.json}]') api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES) return changed, response.json @@ -289,13 +288,11 @@ def present_strategy(api, wished_fn): data=payload_fn) if not creation_response.ok: - msg = "Error during function creation: %s: '%s' (%s)" % (creation_response.info['msg'], - creation_response.json['message'], - creation_response.json) + msg = f"Error during function creation: {creation_response.info['msg']}: '{creation_response.json['message']}' ({creation_response.json})" api.module.fail_json(msg=msg) api.wait_to_complete_state_transition(resource=creation_response.json, stable_states=STABLE_STATES) - response = api.get(path=api.api_path + "/%s" % creation_response.json["id"]) + response = api.get(path=f"{api.api_path}/{creation_response.json['id']}") return changed, response.json target_fn = fn_lookup[wished_fn["name"]] @@ -315,15 +312,14 @@ def present_strategy(api, wished_fn): if api.module.check_mode: return changed, {"status": "Function attributes would be changed."} - fn_patch_response = api.patch(path=api.api_path + "/%s" % target_fn["id"], + fn_patch_response = api.patch(path=f"{api.api_path}/{target_fn['id']}", data=patch_payload) if not fn_patch_response.ok: - api.module.fail_json(msg='Error during function attributes update: [{0}: {1}]'.format( - fn_patch_response.status_code, fn_patch_response.json['message'])) + api.module.fail_json(msg=f"Error during function attributes update: [{fn_patch_response.status_code}: {fn_patch_response.json['message']}]") api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES) - response = api.get(path=api.api_path + "/%s" % target_fn["id"]) + response = api.get(path=f"{api.api_path}/{target_fn['id']}") return changed, response.json @@ -355,7 +351,7 @@ def core(module): } api = Scaleway(module=module) - api.api_path = "functions/v1beta1/regions/%s/functions" % region + api.api_path = f"functions/v1beta1/regions/{region}/functions" changed, summary = state_strategy[wished_function["state"]](api=api, wished_fn=wished_function) diff --git a/plugins/modules/scaleway_function_info.py b/plugins/modules/scaleway_function_info.py index d41e45fba2..e9c7dff3ec 100644 --- a/plugins/modules/scaleway_function_info.py +++ b/plugins/modules/scaleway_function_info.py @@ -101,18 +101,15 @@ def info_strategy(api, wished_fn): fn_lookup = {fn["name"]: fn for fn in fn_list} if wished_fn["name"] not in fn_lookup: - msg = "Error during function lookup: Unable to find function named '%s' in namespace '%s'" % (wished_fn["name"], - wished_fn["namespace_id"]) + msg = f"Error during function lookup: Unable to find function named '{wished_fn['name']}' in namespace '{wished_fn['namespace_id']}'" api.module.fail_json(msg=msg) target_fn = fn_lookup[wished_fn["name"]] - response = api.get(path=api.api_path + "/%s" % target_fn["id"]) + response = api.get(path=f"{api.api_path}/{target_fn['id']}") if not response.ok: - msg = "Error during function lookup: %s: '%s' (%s)" % (response.info['msg'], - response.json['message'], - response.json) + msg = f"Error during function lookup: {response.info['msg']}: '{response.json['message']}' ({response.json})" api.module.fail_json(msg=msg) return response.json @@ -126,7 +123,7 @@ def core(module): } api = Scaleway(module=module) - api.api_path = "functions/v1beta1/regions/%s/functions" % region + api.api_path = f"functions/v1beta1/regions/{region}/functions" summary = info_strategy(api=api, wished_fn=wished_function) diff --git a/plugins/modules/scaleway_function_namespace.py b/plugins/modules/scaleway_function_namespace.py index b5600831b5..cdaf0bdc43 100644 --- a/plugins/modules/scaleway_function_namespace.py +++ b/plugins/modules/scaleway_function_namespace.py @@ -179,10 +179,9 @@ def absent_strategy(api, wished_fn): return changed, {"status": "Function namespace would be destroyed"} api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES, force_wait=True) - response = api.delete(path=api.api_path + "/%s" % target_fn["id"]) + response = api.delete(path=f"{api.api_path}/{target_fn['id']}") if not response.ok: - api.module.fail_json(msg='Error deleting function namespace [{0}: {1}]'.format( - response.status_code, response.json)) + api.module.fail_json(msg=f'Error deleting function namespace [{response.status_code}: {response.json}]') api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES) return changed, response.json @@ -207,13 +206,11 @@ def present_strategy(api, wished_fn): data=payload_fn) if not creation_response.ok: - msg = "Error during function namespace creation: %s: '%s' (%s)" % (creation_response.info['msg'], - creation_response.json['message'], - creation_response.json) + msg = f"Error during function namespace creation: {creation_response.info['msg']}: '{creation_response.json['message']}' ({creation_response.json})" api.module.fail_json(msg=msg) api.wait_to_complete_state_transition(resource=creation_response.json, stable_states=STABLE_STATES) - response = api.get(path=api.api_path + "/%s" % creation_response.json["id"]) + response = api.get(path=f"{api.api_path}/{creation_response.json['id']}") return changed, response.json target_fn = fn_lookup[wished_fn["name"]] @@ -233,15 +230,14 @@ def present_strategy(api, wished_fn): if api.module.check_mode: return changed, {"status": "Function namespace attributes would be changed."} - fn_patch_response = api.patch(path=api.api_path + "/%s" % target_fn["id"], + fn_patch_response = api.patch(path=f"{api.api_path}/{target_fn['id']}", data=patch_payload) if not fn_patch_response.ok: - api.module.fail_json(msg='Error during function namespace attributes update: [{0}: {1}]'.format( - fn_patch_response.status_code, fn_patch_response.json['message'])) + api.module.fail_json(msg=f"Error during function namespace attributes update: [{fn_patch_response.status_code}: {fn_patch_response.json['message']}]") api.wait_to_complete_state_transition(resource=target_fn, stable_states=STABLE_STATES) - response = api.get(path=api.api_path + "/%s" % target_fn["id"]) + response = api.get(path=f"{api.api_path}/{target_fn['id']}") return changed, response.json @@ -265,7 +261,7 @@ def core(module): } api = Scaleway(module=module) - api.api_path = "functions/v1beta1/regions/%s/namespaces" % region + api.api_path = f"functions/v1beta1/regions/{region}/namespaces" changed, summary = state_strategy[wished_function_namespace["state"]](api=api, wished_fn=wished_function_namespace) diff --git a/plugins/modules/scaleway_function_namespace_info.py b/plugins/modules/scaleway_function_namespace_info.py index 89c0fdfa61..e58fd7e0a4 100644 --- a/plugins/modules/scaleway_function_namespace_info.py +++ b/plugins/modules/scaleway_function_namespace_info.py @@ -93,18 +93,15 @@ def info_strategy(api, wished_fn): fn_lookup = {fn["name"]: fn for fn in fn_list} if wished_fn["name"] not in fn_lookup: - msg = "Error during function namespace lookup: Unable to find function namespace named '%s' in project '%s'" % (wished_fn["name"], - wished_fn["project_id"]) + msg = f"Error during function namespace lookup: Unable to find function namespace named '{wished_fn['name']}' in project '{wished_fn['project_id']}'" api.module.fail_json(msg=msg) target_fn = fn_lookup[wished_fn["name"]] - response = api.get(path=api.api_path + "/%s" % target_fn["id"]) + response = api.get(path=f"{api.api_path}/{target_fn['id']}") if not response.ok: - msg = "Error during function namespace lookup: %s: '%s' (%s)" % (response.info['msg'], - response.json['message'], - response.json) + msg = f"Error during function namespace lookup: {response.info['msg']}: '{response.json['message']}' ({response.json})" api.module.fail_json(msg=msg) return response.json @@ -118,7 +115,7 @@ def core(module): } api = Scaleway(module=module) - api.api_path = "functions/v1beta1/regions/%s/namespaces" % region + api.api_path = f"functions/v1beta1/regions/{region}/namespaces" summary = info_strategy(api=api, wished_fn=wished_function_namespace) diff --git a/plugins/modules/scaleway_ip.py b/plugins/modules/scaleway_ip.py index 0edf8f3d31..d1e8840ef5 100644 --- a/plugins/modules/scaleway_ip.py +++ b/plugins/modules/scaleway_ip.py @@ -160,8 +160,7 @@ def present_strategy(api, wished_ip): response = api.get('ips') if not response.ok: - api.module.fail_json(msg='Error getting IPs [{0}: {1}]'.format( - response.status_code, response.json['message'])) + api.module.fail_json(msg=f"Error getting IPs [{response.status_code}: {response.json['message']}]") ips_list = response.json["ips"] ip_lookup = {ip["id"]: ip for ip in ips_list} @@ -176,9 +175,7 @@ def present_strategy(api, wished_ip): data=payload_from_wished_ip(wished_ip)) if not creation_response.ok: - msg = "Error during ip creation: %s: '%s' (%s)" % (creation_response.info['msg'], - creation_response.json['message'], - creation_response.json) + msg = f"Error during ip creation: {creation_response.info['msg']}: '{creation_response.json['message']}' ({creation_response.json})" api.module.fail_json(msg=msg) return changed, creation_response.json["ip"] @@ -192,12 +189,11 @@ def present_strategy(api, wished_ip): if api.module.check_mode: return changed, {"status": "IP attributes would be changed."} - ip_patch_response = api.patch(path="ips/%s" % target_ip["id"], + ip_patch_response = api.patch(path=f"ips/{target_ip['id']}", data=patch_payload) if not ip_patch_response.ok: - api.module.fail_json(msg='Error during IP attributes update: [{0}: {1}]'.format( - ip_patch_response.status_code, ip_patch_response.json['message'])) + api.module.fail_json(msg=f"Error during IP attributes update: [{ip_patch_response.status_code}: {ip_patch_response.json['message']}]") return changed, ip_patch_response.json["ip"] @@ -211,8 +207,7 @@ def absent_strategy(api, wished_ip): ips_list = ips_json["ips"] if not response.ok: - api.module.fail_json(msg='Error getting IPs [{0}: {1}]'.format( - status_code, response.json['message'])) + api.module.fail_json(msg=f"Error getting IPs [{status_code}: {response.json['message']}]") ip_lookup = {ip["id"]: ip for ip in ips_list} if wished_ip["id"] not in ip_lookup.keys(): @@ -222,10 +217,9 @@ def absent_strategy(api, wished_ip): if api.module.check_mode: return changed, {"status": "IP would be destroyed"} - response = api.delete('/ips/' + wished_ip["id"]) + response = api.delete(f"/ips/{wished_ip['id']}") if not response.ok: - api.module.fail_json(msg='Error deleting IP [{0}: {1}]'.format( - response.status_code, response.json)) + api.module.fail_json(msg=f'Error deleting IP [{response.status_code}: {response.json}]') return changed, response.json diff --git a/plugins/modules/scaleway_lb.py b/plugins/modules/scaleway_lb.py index 6e0aaa91f1..e1c90ba3eb 100644 --- a/plugins/modules/scaleway_lb.py +++ b/plugins/modules/scaleway_lb.py @@ -187,21 +187,21 @@ def payload_from_wished_lb(wished_lb): def fetch_state(api, lb): - api.module.debug("fetch_state of load-balancer: %s" % lb["id"]) - response = api.get(path=api.api_path + "/%s" % lb["id"]) + api.module.debug(f"fetch_state of load-balancer: {lb['id']}") + response = api.get(path=f"{api.api_path}/{lb['id']}") if response.status_code == 404: return "absent" if not response.ok: - msg = 'Error during state fetching: (%s) %s' % (response.status_code, response.json) + msg = f'Error during state fetching: ({response.status_code}) {response.json}' api.module.fail_json(msg=msg) try: - api.module.debug("Load-balancer %s in state: %s" % (lb["id"], response.json["status"])) + api.module.debug(f"Load-balancer {lb['id']} in state: {response.json['status']}") return response.json["status"] except KeyError: - api.module.fail_json(msg="Could not fetch state in %s" % response.json) + api.module.fail_json(msg=f"Could not fetch state in {response.json}") def wait_to_complete_state_transition(api, lb, force_wait=False): @@ -218,7 +218,7 @@ def wait_to_complete_state_transition(api, lb, force_wait=False): state = fetch_state(api, lb) if state in STABLE_STATES: api.module.debug("It seems that the load-balancer is not in transition anymore.") - api.module.debug("load-balancer in state: %s" % fetch_state(api, lb)) + api.module.debug(f"load-balancer in state: {fetch_state(api, lb)}") break time.sleep(wait_sleep_time) else: @@ -239,8 +239,7 @@ def present_strategy(api, wished_lb): response = api.get(path=api.api_path) if not response.ok: - api.module.fail_json(msg='Error getting load-balancers [{0}: {1}]'.format( - response.status_code, response.json['message'])) + api.module.fail_json(msg=f"Error getting load-balancers [{response.status_code}: {response.json['message']}]") lbs_list = response.json["lbs"] lb_lookup = {lb["name"]: lb for lb in lbs_list} @@ -256,13 +255,11 @@ def present_strategy(api, wished_lb): data=payload_from_wished_lb(wished_lb)) if not creation_response.ok: - msg = "Error during lb creation: %s: '%s' (%s)" % (creation_response.info['msg'], - creation_response.json['message'], - creation_response.json) + msg = f"Error during lb creation: {creation_response.info['msg']}: '{creation_response.json['message']}' ({creation_response.json})" api.module.fail_json(msg=msg) wait_to_complete_state_transition(api=api, lb=creation_response.json) - response = api.get(path=api.api_path + "/%s" % creation_response.json["id"]) + response = api.get(path=f"{api.api_path}/{creation_response.json['id']}") return changed, response.json target_lb = lb_lookup[wished_lb["name"]] @@ -276,12 +273,11 @@ def present_strategy(api, wished_lb): if api.module.check_mode: return changed, {"status": "Load-balancer attributes would be changed."} - lb_patch_response = api.put(path=api.api_path + "/%s" % target_lb["id"], + lb_patch_response = api.put(path=f"{api.api_path}/{target_lb['id']}", data=patch_payload) if not lb_patch_response.ok: - api.module.fail_json(msg='Error during load-balancer attributes update: [{0}: {1}]'.format( - lb_patch_response.status_code, lb_patch_response.json['message'])) + api.module.fail_json(msg=f"Error during load-balancer attributes update: [{lb_patch_response.status_code}: {lb_patch_response.json['message']}]") wait_to_complete_state_transition(api=api, lb=target_lb) return changed, lb_patch_response.json @@ -296,8 +292,7 @@ def absent_strategy(api, wished_lb): lbs_list = lbs_json["lbs"] if not response.ok: - api.module.fail_json(msg='Error getting load-balancers [{0}: {1}]'.format( - status_code, response.json['message'])) + api.module.fail_json(msg=f"Error getting load-balancers [{status_code}: {response.json['message']}]") lb_lookup = {lb["name"]: lb for lb in lbs_list} if wished_lb["name"] not in lb_lookup.keys(): @@ -309,10 +304,9 @@ def absent_strategy(api, wished_lb): return changed, {"status": "Load-balancer would be destroyed"} wait_to_complete_state_transition(api=api, lb=target_lb, force_wait=True) - response = api.delete(path=api.api_path + "/%s" % target_lb["id"]) + response = api.delete(path=f"{api.api_path}/{target_lb['id']}") if not response.ok: - api.module.fail_json(msg='Error deleting load-balancer [{0}: {1}]'.format( - response.status_code, response.json)) + api.module.fail_json(msg=f'Error deleting load-balancer [{response.status_code}: {response.json}]') wait_to_complete_state_transition(api=api, lb=target_lb) return changed, response.json @@ -335,7 +329,7 @@ def core(module): } module.params['api_url'] = SCALEWAY_ENDPOINT api = Scaleway(module=module) - api.api_path = "lb/v1/regions/%s/lbs" % region + api.api_path = f"lb/v1/regions/{region}/lbs" changed, summary = state_strategy[wished_load_balancer["state"]](api=api, wished_lb=wished_load_balancer) diff --git a/plugins/modules/scaleway_private_network.py b/plugins/modules/scaleway_private_network.py index 040477a246..bac81ebd55 100644 --- a/plugins/modules/scaleway_private_network.py +++ b/plugins/modules/scaleway_private_network.py @@ -125,7 +125,7 @@ def get_private_network(api, name, page=1): page_size = 10 response = api.get('private-networks', params={'name': name, 'order_by': 'name_asc', 'page': page, 'page_size': page_size}) if not response.ok: - msg = "Error during get private network creation: %s: '%s' (%s)" % (response.info['msg'], response.json['message'], response.json) + msg = f"Error during get private network creation: {response.info['msg']}: '{response.json['message']}' ({response.json})" api.module.fail_json(msg=msg) if response.json['total_count'] == 0: @@ -160,9 +160,9 @@ def present_strategy(api, wished_private_network): if api.module.check_mode: return changed, {"status": "private network would be updated"} - response = api.patch(path='private-networks/' + private_network['id'], data=data) + response = api.patch(path=f"private-networks/{private_network['id']}", data=data) if not response.ok: - api.module.fail_json(msg='Error updating private network [{0}: {1}]'.format(response.status_code, response.json)) + api.module.fail_json(msg=f'Error updating private network [{response.status_code}: {response.json}]') return changed, response.json @@ -179,7 +179,7 @@ def present_strategy(api, wished_private_network): response = api.post(path='private-networks/', data=data) if not response.ok: - api.module.fail_json(msg='Error creating private network [{0}: {1}]'.format(response.status_code, response.json)) + api.module.fail_json(msg=f'Error creating private network [{response.status_code}: {response.json}]') return changed, response.json @@ -195,11 +195,10 @@ def absent_strategy(api, wished_private_network): if api.module.check_mode: return changed, {"status": "private network would be destroyed"} - response = api.delete('private-networks/' + private_network['id']) + response = api.delete(f"private-networks/{private_network['id']}") if not response.ok: - api.module.fail_json(msg='Error deleting private network [{0}: {1}]'.format( - response.status_code, response.json)) + api.module.fail_json(msg=f'Error deleting private network [{response.status_code}: {response.json}]') return changed, response.json diff --git a/plugins/modules/scaleway_security_group.py b/plugins/modules/scaleway_security_group.py index ea25234588..70980ce4a0 100644 --- a/plugins/modules/scaleway_security_group.py +++ b/plugins/modules/scaleway_security_group.py @@ -153,7 +153,7 @@ def present_strategy(api, security_group): response = api.get('security_groups') if not response.ok: - api.module.fail_json(msg='Error getting security groups "%s": "%s" (%s)' % (response.info['msg'], response.json['message'], response.json)) + api.module.fail_json(msg=f'Error getting security groups "{response.info["msg"]}": "{response.json["message"]}" ({response.json})') security_group_lookup = {sg['name']: sg for sg in response.json['security_groups']} @@ -169,7 +169,7 @@ def present_strategy(api, security_group): data=payload_from_security_group(security_group)) if not response.ok: - msg = 'Error during security group creation: "%s": "%s" (%s)' % (response.info['msg'], response.json['message'], response.json) + msg = f'Error during security group creation: "{response.info["msg"]}": "{response.json["message"]}" ({response.json})' api.module.fail_json(msg=msg) ret['scaleway_security_group'] = response.json['security_group'] @@ -184,7 +184,7 @@ def absent_strategy(api, security_group): ret = {'changed': False} if not response.ok: - api.module.fail_json(msg='Error getting security groups "%s": "%s" (%s)' % (response.info['msg'], response.json['message'], response.json)) + api.module.fail_json(msg=f'Error getting security groups "{response.info["msg"]}": "{response.json["message"]}" ({response.json})') security_group_lookup = {sg['name']: sg for sg in response.json['security_groups']} if security_group['name'] not in security_group_lookup.keys(): @@ -194,9 +194,9 @@ def absent_strategy(api, security_group): if api.module.check_mode: return ret - response = api.delete('/security_groups/' + security_group_lookup[security_group['name']]['id']) + response = api.delete(f"/security_groups/{security_group_lookup[security_group['name']]['id']}") if not response.ok: - api.module.fail_json(msg='Error deleting security group "%s": "%s" (%s)' % (response.info['msg'], response.json['message'], response.json)) + api.module.fail_json(msg=f'Error deleting security group "{response.info["msg"]}": "{response.json["message"]}" ({response.json})') return ret diff --git a/plugins/modules/scaleway_security_group_rule.py b/plugins/modules/scaleway_security_group_rule.py index edfb6a3565..9146f983d9 100644 --- a/plugins/modules/scaleway_security_group_rule.py +++ b/plugins/modules/scaleway_security_group_rule.py @@ -162,11 +162,10 @@ def get_sgr_from_api(security_group_rules, security_group_rule): def present_strategy(api, security_group_id, security_group_rule): ret = {'changed': False} - response = api.get('security_groups/%s/rules' % security_group_id) + response = api.get(f'security_groups/{security_group_id}/rules') if not response.ok: api.module.fail_json( - msg='Error getting security group rules "%s": "%s" (%s)' % - (response.info['msg'], response.json['message'], response.json)) + msg=f'Error getting security group rules "{response.info["msg"]}": "{response.json["message"]}" ({response.json})') existing_rule = get_sgr_from_api( response.json['rules'], security_group_rule) @@ -177,13 +176,12 @@ def present_strategy(api, security_group_id, security_group_rule): return ret # Create Security Group Rule - response = api.post('/security_groups/%s/rules' % security_group_id, + response = api.post(f'/security_groups/{security_group_id}/rules', data=payload_from_object(security_group_rule)) if not response.ok: api.module.fail_json( - msg='Error during security group rule creation: "%s": "%s" (%s)' % - (response.info['msg'], response.json['message'], response.json)) + msg=f'Error during security group rule creation: "{response.info["msg"]}": "{response.json["message"]}" ({response.json})') ret['scaleway_security_group_rule'] = response.json['rule'] else: @@ -195,11 +193,10 @@ def present_strategy(api, security_group_id, security_group_rule): def absent_strategy(api, security_group_id, security_group_rule): ret = {'changed': False} - response = api.get('security_groups/%s/rules' % security_group_id) + response = api.get(f'security_groups/{security_group_id}/rules') if not response.ok: api.module.fail_json( - msg='Error getting security group rules "%s": "%s" (%s)' % - (response.info['msg'], response.json['message'], response.json)) + msg=f'Error getting security group rules "{response.info["msg"]}": "{response.json["message"]}" ({response.json})') existing_rule = get_sgr_from_api( response.json['rules'], security_group_rule) @@ -212,12 +209,10 @@ def absent_strategy(api, security_group_id, security_group_rule): return ret response = api.delete( - '/security_groups/%s/rules/%s' % - (security_group_id, existing_rule['id'])) + f"/security_groups/{security_group_id}/rules/{existing_rule['id']}") if not response.ok: api.module.fail_json( - msg='Error deleting security group rule "%s": "%s" (%s)' % - (response.info['msg'], response.json['message'], response.json)) + msg=f'Error deleting security group rule "{response.info["msg"]}": "{response.json["message"]}" ({response.json})') return ret diff --git a/plugins/modules/scaleway_sshkey.py b/plugins/modules/scaleway_sshkey.py index 213e6a2010..f1e07cd8f2 100644 --- a/plugins/modules/scaleway_sshkey.py +++ b/plugins/modules/scaleway_sshkey.py @@ -115,8 +115,7 @@ def core(module): organization_json = response.json if not response.ok: - module.fail_json(msg='Error getting ssh key [{0}: {1}]'.format( - status_code, response.json['message'])) + module.fail_json(msg=f"Error getting ssh key [{status_code}: {response.json['message']}]") user_id = extract_user_id(organization_json) present_sshkeys = [] @@ -136,13 +135,12 @@ def core(module): present_sshkeys.append(ssh_pub_key) payload = sshkey_user_patch(present_sshkeys) - response = account_api.patch('/users/%s' % user_id, data=payload) + response = account_api.patch(f'/users/{user_id}', data=payload) if response.ok: module.exit_json(changed=True, data=response.json) - module.fail_json(msg='Error creating ssh key [{0}: {1}]'.format( - response.status_code, response.json)) + module.fail_json(msg=f'Error creating ssh key [{response.status_code}: {response.json}]') elif state in ('absent',): if ssh_pub_key not in present_sshkeys: @@ -154,13 +152,12 @@ def core(module): present_sshkeys.remove(ssh_pub_key) payload = sshkey_user_patch(present_sshkeys) - response = account_api.patch('/users/%s' % user_id, data=payload) + response = account_api.patch(f'/users/{user_id}', data=payload) if response.ok: module.exit_json(changed=True, data=response.json) - module.fail_json(msg='Error deleting ssh key [{0}: {1}]'.format( - response.status_code, response.json)) + module.fail_json(msg=f'Error deleting ssh key [{response.status_code}: {response.json}]') def main(): diff --git a/plugins/modules/scaleway_user_data.py b/plugins/modules/scaleway_user_data.py index 2dadf4439a..fa42370b0e 100644 --- a/plugins/modules/scaleway_user_data.py +++ b/plugins/modules/scaleway_user_data.py @@ -86,19 +86,19 @@ from ansible_collections.community.general.plugins.module_utils.scaleway import def patch_user_data(compute_api, server_id, key, value): compute_api.module.debug("Starting patching user_data attributes") - path = "servers/%s/user_data/%s" % (server_id, key) + path = f"servers/{server_id}/user_data/{key}" response = compute_api.patch(path=path, data=value, headers={"Content-Type": "text/plain"}) if not response.ok: - msg = 'Error during user_data patching: %s %s' % (response.status_code, response.body) + msg = f'Error during user_data patching: {response.status_code} {response.body}' compute_api.module.fail_json(msg=msg) return response def delete_user_data(compute_api, server_id, key): - compute_api.module.debug("Starting deleting user_data attributes: %s" % key) + compute_api.module.debug(f"Starting deleting user_data attributes: {key}") - response = compute_api.delete(path="servers/%s/user_data/%s" % (server_id, key)) + response = compute_api.delete(path=f"servers/{server_id}/user_data/{key}") if not response.ok: msg = 'Error during user_data deleting: (%s) %s' % response.status_code, response.body @@ -110,10 +110,10 @@ def delete_user_data(compute_api, server_id, key): def get_user_data(compute_api, server_id, key): compute_api.module.debug("Starting patching user_data attributes") - path = "servers/%s/user_data/%s" % (server_id, key) + path = f"servers/{server_id}/user_data/{key}" response = compute_api.get(path=path) if not response.ok: - msg = 'Error during user_data patching: %s %s' % (response.status_code, response.body) + msg = f'Error during user_data patching: {response.status_code} {response.body}' compute_api.module.fail_json(msg=msg) return response.json @@ -128,7 +128,7 @@ def core(module): module.params['api_url'] = SCALEWAY_LOCATION[region]["api_endpoint"] compute_api = Scaleway(module=module) - user_data_list = compute_api.get(path="servers/%s/user_data" % server_id) + user_data_list = compute_api.get(path=f"servers/{server_id}/user_data") if not user_data_list.ok: msg = 'Error during user_data fetching: %s %s' % user_data_list.status_code, user_data_list.body compute_api.module.fail_json(msg=msg) @@ -148,7 +148,7 @@ def core(module): changed = True if compute_api.module.check_mode: - module.exit_json(changed=changed, msg={"status": "User-data of %s would be patched." % server_id}) + module.exit_json(changed=changed, msg={"status": f"User-data of {server_id} would be patched."}) delete_user_data(compute_api=compute_api, server_id=server_id, key=key) @@ -158,7 +158,7 @@ def core(module): changed = True if compute_api.module.check_mode: - module.exit_json(changed=changed, msg={"status": "User-data of %s would be patched." % server_id}) + module.exit_json(changed=changed, msg={"status": f"User-data of {server_id} would be patched."}) patch_user_data(compute_api=compute_api, server_id=server_id, key=key, value=value) diff --git a/plugins/modules/scaleway_volume.py b/plugins/modules/scaleway_volume.py index f30856538b..83f2e4e731 100644 --- a/plugins/modules/scaleway_volume.py +++ b/plugins/modules/scaleway_volume.py @@ -141,8 +141,7 @@ def core(module): project = organization if not response.ok: - module.fail_json(msg='Error getting volume [{0}: {1}]'.format( - status_code, response.json['message'])) + module.fail_json(msg=f"Error getting volume [{status_code}: {response.json['message']}]") volumeByName = None for volume in volumes_json['volumes']: @@ -160,8 +159,7 @@ def core(module): if response.ok: module.exit_json(changed=True, data=response.json) - module.fail_json(msg='Error creating volume [{0}: {1}]'.format( - response.status_code, response.json)) + module.fail_json(msg=f'Error creating volume [{response.status_code}: {response.json}]') elif state in ('absent',): if volumeByName is None: @@ -170,12 +168,11 @@ def core(module): if module.check_mode: module.exit_json(changed=True) - response = account_api.delete('/volumes/' + volumeByName['id']) + response = account_api.delete(f"/volumes/{volumeByName['id']}") if response.status_code == 204: module.exit_json(changed=True, data=response.json) - module.fail_json(msg='Error deleting volume [{0}: {1}]'.format( - response.status_code, response.json)) + module.fail_json(msg=f'Error deleting volume [{response.status_code}: {response.json}]') def main(): diff --git a/plugins/modules/sefcontext.py b/plugins/modules/sefcontext.py index f08370ff70..d1d399f8da 100644 --- a/plugins/modules/sefcontext.py +++ b/plugins/modules/sefcontext.py @@ -138,7 +138,6 @@ RETURN = r""" import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native SELINUX_IMP_ERR = None try: @@ -231,8 +230,8 @@ def semanage_fcontext_modify(module, result, target, ftype, setype, substitute, if module._diff: prepared_diff += '# Change to semanage file context mappings\n' - prepared_diff += '-%s %s %s:%s:%s:%s\n' % (target, ftype, orig_seuser, orig_serole, orig_setype, orig_serange) - prepared_diff += '+%s %s %s:%s:%s:%s\n' % (target, ftype, seuser, orig_serole, setype, serange) + prepared_diff += f'-{target} {ftype} {orig_seuser}:{orig_serole}:{orig_setype}:{orig_serange}\n' + prepared_diff += f'+{target} {ftype} {seuser}:{orig_serole}:{setype}:{serange}\n' else: # Add missing entry if seuser is None: @@ -246,7 +245,7 @@ def semanage_fcontext_modify(module, result, target, ftype, setype, substitute, if module._diff: prepared_diff += '# Addition to semanage file context mappings\n' - prepared_diff += '+%s %s %s:%s:%s:%s\n' % (target, ftype, seuser, 'object_r', setype, serange) + prepared_diff += f'+{target} {ftype} {seuser}:object_r:{setype}:{serange}\n' else: exists = semanage_fcontext_substitute_exists(sefcontext, target) if exists: @@ -260,8 +259,8 @@ def semanage_fcontext_modify(module, result, target, ftype, setype, substitute, if module._diff: prepared_diff += '# Change to semanage file context path substitutions\n' - prepared_diff += '-%s = %s\n' % (target, orig_substitute) - prepared_diff += '+%s = %s\n' % (target, substitute) + prepared_diff += f'-{target} = {orig_substitute}\n' + prepared_diff += f'+{target} = {substitute}\n' else: # Add missing path substitution entry if not module.check_mode: @@ -269,10 +268,10 @@ def semanage_fcontext_modify(module, result, target, ftype, setype, substitute, changed = True if module._diff: prepared_diff += '# Addition to semanage file context path substitutions\n' - prepared_diff += '+%s = %s\n' % (target, substitute) + prepared_diff += f'+{target} = {substitute}\n' except Exception as e: - module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, to_native(e))) + module.fail_json(msg=f"{e.__class__.__name__}: {e}\n") if module._diff and prepared_diff: result['diff'] = dict(prepared=prepared_diff) @@ -301,7 +300,7 @@ def semanage_fcontext_delete(module, result, target, ftype, setype, substitute, if module._diff: prepared_diff += '# Deletion to semanage file context mappings\n' - prepared_diff += '-%s %s %s:%s:%s:%s\n' % (target, ftype, exists[0], exists[1], exists[2], exists[3]) + prepared_diff += f'-{target} {ftype} {exists[0]}:{exists[1]}:{exists[2]}:{exists[3]}\n' if substitute_exists and setype is None and ((substitute is not None and substitute_exists == substitute) or substitute is None): # Remove existing path substitution entry orig_substitute = substitute_exists @@ -312,10 +311,10 @@ def semanage_fcontext_delete(module, result, target, ftype, setype, substitute, if module._diff: prepared_diff += '# Deletion to semanage file context path substitutions\n' - prepared_diff += '-%s = %s\n' % (target, orig_substitute) + prepared_diff += f'-{target} = {orig_substitute}\n' except Exception as e: - module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, to_native(e))) + module.fail_json(msg=f"{e.__class__.__name__}: {e}\n") if module._diff and prepared_diff: result['diff'] = dict(prepared=prepared_diff) @@ -375,7 +374,7 @@ def main(): elif state == 'absent': semanage_fcontext_delete(module, result, target, ftype, setype, substitute, do_reload) else: - module.fail_json(msg='Invalid value of argument "state": {0}'.format(state)) + module.fail_json(msg=f'Invalid value of argument "state": {state}') if __name__ == '__main__': diff --git a/plugins/modules/selogin.py b/plugins/modules/selogin.py index d1e0faf085..7b0144893e 100644 --- a/plugins/modules/selogin.py +++ b/plugins/modules/selogin.py @@ -107,7 +107,6 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native def semanage_login_add(module, login, seuser, do_reload, serange='s0', sestore=''): @@ -152,7 +151,7 @@ def semanage_login_add(module, login, seuser, do_reload, serange='s0', sestore=' selogin.modify(login, seuser, serange) except (ValueError, KeyError, OSError, RuntimeError) as e: - module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, to_native(e)), exception=traceback.format_exc()) + module.fail_json(msg=f"{e.__class__.__name__}: {e}\n", exception=traceback.format_exc()) return change @@ -190,7 +189,7 @@ def semanage_login_del(module, login, seuser, do_reload, sestore=''): selogin.delete(login) except (ValueError, KeyError, OSError, RuntimeError) as e: - module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, to_native(e)), exception=traceback.format_exc()) + module.fail_json(msg=f"{e.__class__.__name__}: {e}\n", exception=traceback.format_exc()) return change @@ -243,7 +242,7 @@ def main(): elif state == 'absent': result['changed'] = semanage_login_del(module, login, seuser, do_reload) else: - module.fail_json(msg='Invalid value of argument "state": {0}'.format(state)) + module.fail_json(msg=f'Invalid value of argument "state": {state}') module.exit_json(**result) diff --git a/plugins/modules/sendgrid.py b/plugins/modules/sendgrid.py index 26021c35c9..cb67f3ad5f 100644 --- a/plugins/modules/sendgrid.py +++ b/plugins/modules/sendgrid.py @@ -155,7 +155,7 @@ def post_sendgrid_api(module, username, password, from_address, to_addresses, to_addresses_api = '' for recipient in to_addresses: recipient = to_bytes(recipient, errors='surrogate_or_strict') - to_addresses_api += '&to[]=%s' % recipient + to_addresses_api += f'&to[]={recipient}' encoded_data += to_addresses_api headers = {'User-Agent': AGENT, @@ -194,7 +194,7 @@ def post_sendgrid_api(module, username, password, from_address, to_addresses, message.add_attachment(name, f) if from_name: - message.set_from('%s <%s.' % (from_name, from_address)) + message.set_from(f'{from_name} <{from_address}.') else: message.set_from(from_address) @@ -262,10 +262,10 @@ def main(): if not HAS_SENDGRID: if info['status'] != 200: - module.fail_json(msg="unable to send email through SendGrid API: %s" % info['msg']) + module.fail_json(msg=f"unable to send email through SendGrid API: {info['msg']}") else: if response != 200: - module.fail_json(msg="unable to send email through SendGrid API: %s" % info['message']) + module.fail_json(msg=f"unable to send email through SendGrid API: {info['message']}") module.exit_json(msg=subject, changed=False) diff --git a/plugins/modules/seport.py b/plugins/modules/seport.py index 7e3a2690d2..5f03d65e2c 100644 --- a/plugins/modules/seport.py +++ b/plugins/modules/seport.py @@ -128,7 +128,6 @@ except ImportError: HAVE_SEOBJECT = False from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native def get_runtime_status(ignore_selinux_state=False): @@ -229,7 +228,7 @@ def semanage_port_add(module, ports, proto, setype, do_reload, serange='s0', ses seport.modify(port, proto, serange, setype) except (ValueError, IOError, KeyError, OSError, RuntimeError) as e: - module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, to_native(e)), exception=traceback.format_exc()) + module.fail_json(msg=f"{e.__class__.__name__}: {e}\n", exception=traceback.format_exc()) return change @@ -270,7 +269,7 @@ def semanage_port_del(module, ports, proto, setype, do_reload, sestore='', local seport.delete(port, proto) except (ValueError, IOError, KeyError, OSError, RuntimeError) as e: - module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, to_native(e)), exception=traceback.format_exc()) + module.fail_json(msg=f"{e.__class__.__name__}: {e}\n", exception=traceback.format_exc()) return change @@ -319,7 +318,7 @@ def main(): elif state == 'absent': result['changed'] = semanage_port_del(module, ports, proto, setype, do_reload, local=local) else: - module.fail_json(msg='Invalid value of argument "state": {0}'.format(state)) + module.fail_json(msg=f'Invalid value of argument "state": {state}') module.exit_json(**result) diff --git a/plugins/modules/serverless.py b/plugins/modules/serverless.py index 0ea2eb3e1f..5f3572e022 100644 --- a/plugins/modules/serverless.py +++ b/plugins/modules/serverless.py @@ -138,7 +138,7 @@ def read_serverless_config(module): config = yaml.safe_load(sls_config.read()) return config except IOError as e: - module.fail_json(msg="Could not open serverless.yml in {0}. err: {1}".format(full_path, str(e))) + module.fail_json(msg=f"Could not open serverless.yml in {full_path}. err: {e}") def get_service_name(module, stage): @@ -147,9 +147,9 @@ def get_service_name(module, stage): module.fail_json(msg="Could not read `service` key from serverless.yml file") if stage: - return "{0}-{1}".format(config['service'], stage) + return f"{config['service']}-{stage}" - return "{0}-{1}".format(config['service'], config.get('stage', 'dev')) + return f"{config['service']}-{config.get('stage', 'dev')}" def main(): @@ -179,16 +179,16 @@ def main(): serverless_bin_path = module.params.get('serverless_bin_path') if serverless_bin_path is not None: - command = serverless_bin_path + " " + command = f"{serverless_bin_path} " else: - command = module.get_bin_path("serverless") + " " + command = f"{module.get_bin_path('serverless')} " if state == 'present': command += 'deploy ' elif state == 'absent': command += 'remove ' else: - module.fail_json(msg="State must either be 'present' or 'absent'. Received: {0}".format(state)) + module.fail_json(msg=f"State must either be 'present' or 'absent'. Received: {state}") if state == 'present': if not deploy: @@ -197,19 +197,19 @@ def main(): command += '--force ' if region: - command += '--region {0} '.format(region) + command += f'--region {region} ' if stage: - command += '--stage {0} '.format(stage) + command += f'--stage {stage} ' if verbose: command += '--verbose ' rc, out, err = module.run_command(command, cwd=service_path) if rc != 0: - if state == 'absent' and "-{0}' does not exist".format(stage) in out: + if state == 'absent' and f"-{stage}' does not exist" in out: module.exit_json(changed=False, state='absent', command=command, out=out, service_name=get_service_name(module, stage)) - module.fail_json(msg="Failure when executing Serverless command. Exited {0}.\nstdout: {1}\nstderr: {2}".format(rc, out, err)) + module.fail_json(msg=f"Failure when executing Serverless command. Exited {rc}.\nstdout: {out}\nstderr: {err}") # gather some facts about the deployment module.exit_json(changed=True, state='present', out=out, command=command,