mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[Bug] Scaleway The volume is created systematically on par1 (#3964)
* [Bug] The volume is created systematically on par1 * add change log * added backward compatibility with organization * add documentation * change typo doc * Update changelogs/fragments/3964-scaleway_volume_add_region.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/cloud/scaleway/scaleway_volume.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/cloud/scaleway/scaleway_volume.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/cloud/scaleway/scaleway_volume.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/cloud/scaleway/scaleway_volume.py Co-authored-by: Rémy Léone <remy.leone@gmail.com> * optimization Co-authored-by: Romain SCHARFF <rscharff@plussimple.com> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Rémy Léone <remy.leone@gmail.com>
This commit is contained in:
parent
bb78d98f8f
commit
125516b957
2 changed files with 24 additions and 4 deletions
2
changelogs/fragments/3964-scaleway_volume_add_region.yml
Normal file
2
changelogs/fragments/3964-scaleway_volume_add_region.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- scaleway_volume - all volumes are systematically created on par1 (https://github.com/ansible-collections/community.general/pull/3964).
|
|
@ -51,6 +51,11 @@ options:
|
||||||
description:
|
description:
|
||||||
- Name used to identify the volume.
|
- Name used to identify the volume.
|
||||||
required: true
|
required: true
|
||||||
|
project:
|
||||||
|
type: str
|
||||||
|
description:
|
||||||
|
- Scaleway project ID to which volume belongs.
|
||||||
|
version_added: 4.3.0
|
||||||
organization:
|
organization:
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
|
@ -71,7 +76,7 @@ EXAMPLES = '''
|
||||||
name: my-volume
|
name: my-volume
|
||||||
state: present
|
state: present
|
||||||
region: par1
|
region: par1
|
||||||
organization: "{{ scw_org }}"
|
project: "{{ scw_org }}"
|
||||||
"size": 10000000000
|
"size": 10000000000
|
||||||
volume_type: l_ssd
|
volume_type: l_ssd
|
||||||
register: server_creation_check_task
|
register: server_creation_check_task
|
||||||
|
@ -93,7 +98,7 @@ data:
|
||||||
"export_uri": null,
|
"export_uri": null,
|
||||||
"id": "c675f420-cfeb-48ff-ba2a-9d2a4dbe3fcd",
|
"id": "c675f420-cfeb-48ff-ba2a-9d2a4dbe3fcd",
|
||||||
"name": "volume-0-3",
|
"name": "volume-0-3",
|
||||||
"organization": "000a115d-2852-4b0a-9ce8-47f1134ba95a",
|
"project": "000a115d-2852-4b0a-9ce8-47f1134ba95a",
|
||||||
"server": null,
|
"server": null,
|
||||||
"size": 10000000000,
|
"size": 10000000000,
|
||||||
"volume_type": "l_ssd"
|
"volume_type": "l_ssd"
|
||||||
|
@ -106,31 +111,37 @@ from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
def core(module):
|
def core(module):
|
||||||
|
region = module.params["region"]
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
name = module.params['name']
|
name = module.params['name']
|
||||||
organization = module.params['organization']
|
organization = module.params['organization']
|
||||||
|
project = module.params['project']
|
||||||
size = module.params['size']
|
size = module.params['size']
|
||||||
volume_type = module.params['volume_type']
|
volume_type = module.params['volume_type']
|
||||||
|
module.params['api_url'] = SCALEWAY_LOCATION[region]["api_endpoint"]
|
||||||
|
|
||||||
account_api = Scaleway(module)
|
account_api = Scaleway(module)
|
||||||
response = account_api.get('volumes')
|
response = account_api.get('volumes')
|
||||||
status_code = response.status_code
|
status_code = response.status_code
|
||||||
volumes_json = response.json
|
volumes_json = response.json
|
||||||
|
|
||||||
|
if project is None:
|
||||||
|
project = organization
|
||||||
|
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
module.fail_json(msg='Error getting volume [{0}: {1}]'.format(
|
module.fail_json(msg='Error getting volume [{0}: {1}]'.format(
|
||||||
status_code, response.json['message']))
|
status_code, response.json['message']))
|
||||||
|
|
||||||
volumeByName = None
|
volumeByName = None
|
||||||
for volume in volumes_json['volumes']:
|
for volume in volumes_json['volumes']:
|
||||||
if volume['organization'] == organization and volume['name'] == name:
|
if volume['project'] == project and volume['name'] == name:
|
||||||
volumeByName = volume
|
volumeByName = volume
|
||||||
|
|
||||||
if state in ('present',):
|
if state in ('present',):
|
||||||
if volumeByName is not None:
|
if volumeByName is not None:
|
||||||
module.exit_json(changed=False)
|
module.exit_json(changed=False)
|
||||||
|
|
||||||
payload = {'name': name, 'organization': organization, '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)
|
||||||
|
|
||||||
|
@ -161,6 +172,7 @@ def main():
|
||||||
state=dict(default='present', choices=['absent', 'present']),
|
state=dict(default='present', choices=['absent', 'present']),
|
||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
size=dict(type='int'),
|
size=dict(type='int'),
|
||||||
|
project=dict(),
|
||||||
organization=dict(),
|
organization=dict(),
|
||||||
volume_type=dict(),
|
volume_type=dict(),
|
||||||
region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())),
|
region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())),
|
||||||
|
@ -168,6 +180,12 @@ def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
|
mutually_exclusive=[
|
||||||
|
('organization', 'project'),
|
||||||
|
],
|
||||||
|
required_one_of=[
|
||||||
|
('organization', 'project'),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
core(module)
|
core(module)
|
||||||
|
|
Loading…
Reference in a new issue