1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-25 05:02:46 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -116,7 +116,11 @@ data:
}
"""
from ansible_collections.community.general.plugins.module_utils.scaleway import SCALEWAY_LOCATION, scaleway_argument_spec, Scaleway
from ansible_collections.community.general.plugins.module_utils.scaleway import (
SCALEWAY_LOCATION,
scaleway_argument_spec,
Scaleway,
)
from ansible.module_utils.basic import AnsibleModule
@ -148,17 +152,13 @@ def ip_attributes_should_be_changed(api, target_ip, wished_ip):
def payload_from_wished_ip(wished_ip):
return {
k: v
for k, v in wished_ip.items()
if k != 'id' and v is not None
}
return {k: v for k, v in wished_ip.items() if k != "id" and v is not None}
def present_strategy(api, wished_ip):
changed = False
response = api.get('ips')
response = api.get("ips")
if not response.ok:
api.module.fail_json(msg=f"Error getting IPs [{response.status_code}: {response.json['message']}]")
@ -171,8 +171,7 @@ def present_strategy(api, wished_ip):
return changed, {"status": "An IP would be created."}
# Create IP
creation_response = api.post('/ips',
data=payload_from_wished_ip(wished_ip))
creation_response = api.post("/ips", data=payload_from_wished_ip(wished_ip))
if not creation_response.ok:
msg = f"Error during ip creation: {creation_response.info['msg']}: '{creation_response.json['message']}' ({creation_response.json})"
@ -189,17 +188,18 @@ 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=f"ips/{target_ip['id']}",
data=patch_payload)
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=f"Error during IP attributes update: [{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"]
def absent_strategy(api, wished_ip):
response = api.get('ips')
response = api.get("ips")
changed = False
status_code = response.status_code
@ -219,21 +219,21 @@ def absent_strategy(api, wished_ip):
response = api.delete(f"/ips/{wished_ip['id']}")
if not response.ok:
api.module.fail_json(msg=f'Error deleting IP [{response.status_code}: {response.json}]')
api.module.fail_json(msg=f"Error deleting IP [{response.status_code}: {response.json}]")
return changed, response.json
def core(module):
wished_ip = {
"organization": module.params['organization'],
"organization": module.params["organization"],
"reverse": module.params["reverse"],
"id": module.params["id"],
"server": module.params["server"]
"server": module.params["server"],
}
region = module.params["region"]
module.params['api_url'] = SCALEWAY_LOCATION[region]["api_endpoint"]
module.params["api_url"] = SCALEWAY_LOCATION[region]["api_endpoint"]
api = Scaleway(module=module)
if module.params["state"] == "absent":
@ -245,14 +245,16 @@ def core(module):
def main():
argument_spec = scaleway_argument_spec()
argument_spec.update(dict(
state=dict(default='present', choices=['absent', 'present']),
organization=dict(required=True),
server=dict(),
reverse=dict(),
region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())),
id=dict()
))
argument_spec.update(
dict(
state=dict(default="present", choices=["absent", "present"]),
organization=dict(required=True),
server=dict(),
reverse=dict(),
region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())),
id=dict(),
)
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
@ -261,5 +263,5 @@ def main():
core(module)
if __name__ == '__main__':
if __name__ == "__main__":
main()