1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-22 03:39:08 +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

@ -118,22 +118,26 @@ 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
def core(module):
region = module.params["region"]
state = module.params['state']
name = module.params['name']
organization = module.params['organization']
project = module.params['project']
size = module.params['size']
volume_type = module.params['volume_type']
module.params['api_url'] = SCALEWAY_LOCATION[region]["api_endpoint"]
state = module.params["state"]
name = module.params["name"]
organization = module.params["organization"]
project = module.params["project"]
size = module.params["size"]
volume_type = module.params["volume_type"]
module.params["api_url"] = SCALEWAY_LOCATION[region]["api_endpoint"]
account_api = Scaleway(module)
response = account_api.get('volumes')
response = account_api.get("volumes")
status_code = response.status_code
volumes_json = response.json
@ -144,24 +148,24 @@ def core(module):
module.fail_json(msg=f"Error getting volume [{status_code}: {response.json['message']}]")
volumeByName = None
for volume in volumes_json['volumes']:
if volume['project'] == project and volume['name'] == name:
for volume in volumes_json["volumes"]:
if volume["project"] == project and volume["name"] == name:
volumeByName = volume
if state in ('present',):
if state in ("present",):
if volumeByName is not None:
module.exit_json(changed=False)
payload = {'name': name, 'project': project, 'size': size, 'volume_type': volume_type}
payload = {"name": name, "project": project, "size": size, "volume_type": volume_type}
response = account_api.post('/volumes', payload)
response = account_api.post("/volumes", payload)
if response.ok:
module.exit_json(changed=True, data=response.json)
module.fail_json(msg=f'Error creating volume [{response.status_code}: {response.json}]')
module.fail_json(msg=f"Error creating volume [{response.status_code}: {response.json}]")
elif state in ('absent',):
elif state in ("absent",):
if volumeByName is None:
module.exit_json(changed=False)
@ -172,33 +176,35 @@ def core(module):
if response.status_code == 204:
module.exit_json(changed=True, data=response.json)
module.fail_json(msg=f'Error deleting volume [{response.status_code}: {response.json}]')
module.fail_json(msg=f"Error deleting volume [{response.status_code}: {response.json}]")
def main():
argument_spec = scaleway_argument_spec()
argument_spec.update(dict(
state=dict(default='present', choices=['absent', 'present']),
name=dict(required=True),
size=dict(type='int'),
project=dict(),
organization=dict(),
volume_type=dict(),
region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())),
))
argument_spec.update(
dict(
state=dict(default="present", choices=["absent", "present"]),
name=dict(required=True),
size=dict(type="int"),
project=dict(),
organization=dict(),
volume_type=dict(),
region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())),
)
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
mutually_exclusive=[
('organization', 'project'),
("organization", "project"),
],
required_one_of=[
('organization', 'project'),
("organization", "project"),
],
)
core(module)
if __name__ == '__main__':
if __name__ == "__main__":
main()