Debian Codegraph @

ansible_collections/community/general/plugins/modules/scaleway_snapshot_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_snapshot_info
11 short_description: Gather information about the Scaleway snapshots available
12 description:
13 - Gather information about the Scaleway snapshot 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 snapshots information
51 community.general.scaleway_snapshot_info:
52 region: par1
53 register: result
54
55 - ansible.builtin.debug:
56 msg: "{{ result.scaleway_snapshot_info }}"
57 """
58
59 RETURN = r"""
60 scaleway_snapshot_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 "base_volume": {
71 "id": "68386fae-4f55-4fbf-aabb-953036a85872",
72 "name": "snapshot-87fc282d-f252-4262-adad-86979d9074cf-2018-04-26_12:42"
73 },
74 "creation_date": "2018-08-14T22:34:35.299461+00:00",
75 "id": "b61b4b03-a2e9-4da5-b5ea-e462ac0662d2",
76 "modification_date": "2018-08-14T22:34:54.520560+00:00",
77 "name": "snapshot-87fc282d-f252-4262-adad-86979d9074cf-2018-04-26_12:42 snapshot",
78 "organization": "3f709602-5e6c-4619-b80c-e841c89734af",
79 "size": 25000000000,
80 "state": "available",
81 "volume_type": "l_ssd"
82 }
83 ]
84 """
85
86 from ansible.module_utils.basic import AnsibleModule
87
88 from ansible_collections.community.general.plugins.module_utils._scaleway import (
89 SCALEWAY_LOCATION,
90 Scaleway,
91 ScalewayException,
92 scaleway_argument_spec,
93 )
94
95
96 class ScalewaySnapshotInfo(Scaleway):
97 def __init__(self, module):
98 super().__init__(module)
99 self.name = "snapshots"
100
101 region = module.params["region"]
102 self.module.params["api_url"] = SCALEWAY_LOCATION[region]["api_endpoint"]
103
104
105 def main():
106 argument_spec = scaleway_argument_spec()
107 argument_spec.update(
108 dict(
109 region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())),
110 )
111 )
112
113 module = AnsibleModule(
114 argument_spec=argument_spec,
115 supports_check_mode=True,
116 )
117
118 try:
119 module.exit_json(scaleway_snapshot_info=ScalewaySnapshotInfo(module).get_resources())
120 except ScalewayException as exc:
121 module.fail_json(msg=exc.message)
122
123
124 if __name__ == "__main__":
125 main()