1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/plugins/modules/cloud/scaleway/scaleway_volume.py

177 lines
4.5 KiB
Python
Raw Normal View History

2020-03-09 10:11:07 +01:00
#!/usr/bin/python
#
# Scaleway volumes management module
#
# Copyright (C) 2018 Henryk Konsek Consulting (hekonsek@gmail.com).
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
---
module: scaleway_volume
short_description: Scaleway volumes management module
author: Henryk Konsek (@hekonsek)
description:
- This module manages volumes on Scaleway account
U(https://developer.scaleway.com)
extends_documentation_fragment:
- community.general.scaleway
options:
state:
Tidy up validate-modules ignores for cloud/scaleway modules (#1268) (#1274) * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_compute.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_lb.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_rule.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_sshkey.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_user_data.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume.py * Enabling validation-modules for cloud/scaleway modules * Reverted invalid-documentation validations in 2.9 (cherry picked from commit adbf624a42690edb44a82b81d95896e31cfba427) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
2020-11-12 08:48:07 +01:00
type: str
2020-03-09 10:11:07 +01:00
description:
- Indicate desired state of the volume.
default: present
choices:
- present
- absent
region:
Tidy up validate-modules ignores for cloud/scaleway modules (#1268) (#1274) * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_compute.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_lb.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_rule.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_sshkey.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_user_data.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume.py * Enabling validation-modules for cloud/scaleway modules * Reverted invalid-documentation validations in 2.9 (cherry picked from commit adbf624a42690edb44a82b81d95896e31cfba427) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
2020-11-12 08:48:07 +01:00
type: str
2020-03-09 10:11:07 +01:00
description:
- Scaleway region to use (for example par1).
required: true
choices:
- ams1
- EMEA-NL-EVS
- par1
- EMEA-FR-PAR1
- par2
- EMEA-FR-PAR2
- waw1
- EMEA-PL-WAW1
2020-03-09 10:11:07 +01:00
name:
Tidy up validate-modules ignores for cloud/scaleway modules (#1268) (#1274) * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_compute.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_lb.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_rule.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_sshkey.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_user_data.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume.py * Enabling validation-modules for cloud/scaleway modules * Reverted invalid-documentation validations in 2.9 (cherry picked from commit adbf624a42690edb44a82b81d95896e31cfba427) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
2020-11-12 08:48:07 +01:00
type: str
2020-03-09 10:11:07 +01:00
description:
- Name used to identify the volume.
required: true
organization:
Tidy up validate-modules ignores for cloud/scaleway modules (#1268) (#1274) * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_compute.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_lb.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_rule.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_sshkey.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_user_data.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume.py * Enabling validation-modules for cloud/scaleway modules * Reverted invalid-documentation validations in 2.9 (cherry picked from commit adbf624a42690edb44a82b81d95896e31cfba427) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
2020-11-12 08:48:07 +01:00
type: str
2020-03-09 10:11:07 +01:00
description:
- ScaleWay organization ID to which volume belongs.
size:
Tidy up validate-modules ignores for cloud/scaleway modules (#1268) (#1274) * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_compute.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_lb.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_rule.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_sshkey.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_user_data.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume.py * Enabling validation-modules for cloud/scaleway modules * Reverted invalid-documentation validations in 2.9 (cherry picked from commit adbf624a42690edb44a82b81d95896e31cfba427) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
2020-11-12 08:48:07 +01:00
type: int
2020-03-09 10:11:07 +01:00
description:
- Size of the volume in bytes.
volume_type:
Tidy up validate-modules ignores for cloud/scaleway modules (#1268) (#1274) * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_compute.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_lb.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_rule.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_sshkey.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_user_data.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume.py * Enabling validation-modules for cloud/scaleway modules * Reverted invalid-documentation validations in 2.9 (cherry picked from commit adbf624a42690edb44a82b81d95896e31cfba427) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
2020-11-12 08:48:07 +01:00
type: str
2020-03-09 10:11:07 +01:00
description:
- Type of the volume (for example 'l_ssd').
'''
EXAMPLES = '''
- name: Create 10GB volume
community.general.scaleway_volume:
name: my-volume
state: present
region: par1
organization: "{{ scw_org }}"
"size": 10000000000
volume_type: l_ssd
register: server_creation_check_task
2020-03-09 10:11:07 +01:00
- name: Make sure volume deleted
community.general.scaleway_volume:
name: my-volume
state: absent
region: par1
2020-03-09 10:11:07 +01:00
'''
RETURN = '''
data:
description: This is only present when C(state=present)
returned: when C(state=present)
type: dict
sample: {
"volume": {
"export_uri": null,
"id": "c675f420-cfeb-48ff-ba2a-9d2a4dbe3fcd",
"name": "volume-0-3",
"organization": "000a115d-2852-4b0a-9ce8-47f1134ba95a",
"server": null,
"size": 10000000000,
"volume_type": "l_ssd"
}
}
'''
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):
state = module.params['state']
name = module.params['name']
organization = module.params['organization']
size = module.params['size']
volume_type = module.params['volume_type']
account_api = Scaleway(module)
response = account_api.get('volumes')
status_code = response.status_code
volumes_json = response.json
if not response.ok:
module.fail_json(msg='Error getting volume [{0}: {1}]'.format(
status_code, response.json['message']))
volumeByName = None
for volume in volumes_json['volumes']:
if volume['organization'] == organization and volume['name'] == name:
volumeByName = volume
if state in ('present',):
if volumeByName is not None:
module.exit_json(changed=False)
payload = {'name': name, 'organization': organization, 'size': size, 'volume_type': volume_type}
response = account_api.post('/volumes', payload)
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))
elif state in ('absent',):
if volumeByName is None:
module.exit_json(changed=False)
if module.check_mode:
module.exit_json(changed=True)
response = account_api.delete('/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))
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'),
organization=dict(),
volume_type=dict(),
Tidy up validate-modules ignores for cloud/scaleway modules (#1268) (#1274) * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_compute.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_image_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_ip.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_lb.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_security_group_rule.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_server_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_snapshot_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_sshkey.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_user_data.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_facts.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume_info.py * fixed validation-modules for plugins/modules/cloud/scaleway/scaleway_volume.py * Enabling validation-modules for cloud/scaleway modules * Reverted invalid-documentation validations in 2.9 (cherry picked from commit adbf624a42690edb44a82b81d95896e31cfba427) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
2020-11-12 08:48:07 +01:00
region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())),
2020-03-09 10:11:07 +01:00
))
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
core(module)
if __name__ == '__main__':
main()