Debian Codegraph @

ansible_collections/community/general/plugins/modules/scaleway_volume_info.py

raw
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2018, Yanis Guenane <[email protected]>
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7 from __future__ import annotations
8
9 DOCUMENTATION = r"""
10 module: scaleway_volume_info
11 short_description: Gather information about the Scaleway volumes available
12 description:
13 - Gather information about the Scaleway volumes available.
14 author:
15 - "Yanis Guenane (@Spredzy)"
16 - "Remy Leone (@remyleone)"
17 extends_documentation_fragment:
18 - community.general._scaleway
19 - community.general._attributes
20 - community.general._scaleway.actiongroup_scaleway
21 - community.general._attributes.info_module
22
23 attributes:
24 action_group:
25 version_added: 11.3.0
26
27 options:
28 region:
29 type: str
30 description:
31 - Scaleway region to use (for example C(par1)).
32 required: true
33 choices:
34 - ams1
35 - EMEA-NL-EVS
36 - ams2
37 - ams3
38 - par1
39 - EMEA-FR-PAR1
40 - par2
41 - EMEA-FR-PAR2
42 - par3
43 - waw1
44 - EMEA-PL-WAW1
45 - waw2
46 - waw3
47 """
48
49 EXAMPLES = r"""
50 - name: Gather Scaleway volumes information
51 community.general.scaleway_volume_info:
52 region: par1
53 register: result
54
55 - ansible.builtin.debug:
56 msg: "{{ result.scaleway_volume_info }}"
57 """
58
59 RETURN = r"""
60 scaleway_volume_info:
61 description:
62 - Response from Scaleway API.
63 - 'For more details please refer to: U(https://developers.scaleway.com/en/products/instance/api/).'
64 returned: success
65 type: list
66 elements: dict
67 sample:
68 [
69 {
70 "creation_date": "2018-08-14T20:56:24.949660+00:00",
71 "export_uri": null,
72 "id": "b8d51a06-daeb-4fef-9539-a8aea016c1ba",
73 "modification_date": "2018-08-14T20:56:24.949660+00:00",
74 "name": "test-volume",
75 "organization": "3f709602-5e6c-4619-b80c-e841c89734af",
76 "server": null,
77 "size": 50000000000,
78 "state": "available",
79 "volume_type": "l_ssd"
80 }
81 ]
82 """
83
84 from ansible.module_utils.basic import AnsibleModule
85
86 from ansible_collections.community.general.plugins.module_utils._scaleway import (
87 SCALEWAY_LOCATION,
88 Scaleway,
89 ScalewayException,
90 scaleway_argument_spec,
91 )
92
93
94 class ScalewayVolumeInfo(Scaleway):
95 def __init__(self, module):
96 super().__init__(module)
97 self.name = "volumes"
98
99 region = module.params["region"]
100 self.module.params["api_url"] = SCALEWAY_LOCATION[region]["api_endpoint"]
101
102
103 def main():
104 argument_spec = scaleway_argument_spec()
105 argument_spec.update(
106 dict(
107 region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())),
108 )
109 )
110
111 module = AnsibleModule(
112 argument_spec=argument_spec,
113 supports_check_mode=True,
114 )
115
116 try:
117 module.exit_json(scaleway_volume_info=ScalewayVolumeInfo(module).get_resources())
118 except ScalewayException as exc:
119 module.fail_json(msg=exc.message)
120
121
122 if __name__ == "__main__":
123 main()