Debian Codegraph @

ansible_collections/community/general/plugins/modules/scaleway_ip_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_ip_info
11 short_description: Gather information about the Scaleway IPs available
12 description:
13 - Gather information about the Scaleway IPs 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 IPs information
51 community.general.scaleway_ip_info:
52 region: par1
53 register: result
54
55 - ansible.builtin.debug:
56 msg: "{{ result.scaleway_ip_info }}"
57 """
58
59 RETURN = r"""
60 scaleway_ip_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 "address": "163.172.170.243",
71 "id": "ea081794-a581-8899-8451-386ddaf0a451",
72 "organization": "3f709602-5e6c-4619-b80c-e324324324af",
73 "reverse": null,
74 "server": {
75 "id": "12f19bc7-109c-4517-954c-e6b3d0311363",
76 "name": "scw-e0d158"
77 }
78 }
79 ]
80 """
81
82 from ansible.module_utils.basic import AnsibleModule
83
84 from ansible_collections.community.general.plugins.module_utils._scaleway import (
85 SCALEWAY_LOCATION,
86 Scaleway,
87 ScalewayException,
88 scaleway_argument_spec,
89 )
90
91
92 class ScalewayIpInfo(Scaleway):
93 def __init__(self, module):
94 super().__init__(module)
95 self.name = "ips"
96
97 region = module.params["region"]
98 self.module.params["api_url"] = SCALEWAY_LOCATION[region]["api_endpoint"]
99
100
101 def main():
102 argument_spec = scaleway_argument_spec()
103 argument_spec.update(
104 dict(
105 region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())),
106 )
107 )
108 module = AnsibleModule(
109 argument_spec=argument_spec,
110 supports_check_mode=True,
111 )
112
113 try:
114 module.exit_json(scaleway_ip_info=ScalewayIpInfo(module).get_resources())
115 except ScalewayException as exc:
116 module.fail_json(msg=exc.message)
117
118
119 if __name__ == "__main__":
120 main()