Debian Codegraph @

ansible_collections/community/general/plugins/modules/scaleway_security_group_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_security_group_info
11 short_description: Gather information about the Scaleway security groups available
12 description:
13 - Gather information about the Scaleway security groups available.
14 author:
15 - "Yanis Guenane (@Spredzy)"
16 - "Remy Leone (@remyleone)"
17
18 attributes:
19 action_group:
20 version_added: 11.3.0
21
22 options:
23 region:
24 type: str
25 description:
26 - Scaleway region to use (for example C(par1)).
27 required: true
28 choices:
29 - ams1
30 - EMEA-NL-EVS
31 - ams2
32 - ams3
33 - par1
34 - EMEA-FR-PAR1
35 - par2
36 - EMEA-FR-PAR2
37 - par3
38 - waw1
39 - EMEA-PL-WAW1
40 - waw2
41 - waw3
42 extends_documentation_fragment:
43 - community.general._scaleway
44 - community.general._attributes
45 - community.general._scaleway.actiongroup_scaleway
46 - community.general._attributes.info_module
47 """
48
49 EXAMPLES = r"""
50 - name: Gather Scaleway security groups information
51 community.general.scaleway_security_group_info:
52 region: par1
53 register: result
54
55 - ansible.builtin.debug:
56 msg: "{{ result.scaleway_security_group_info }}"
57 """
58
59 RETURN = r"""
60 scaleway_security_group_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 "description": "test-ams",
71 "enable_default_security": true,
72 "id": "7fcde327-8bed-43a6-95c4-6dfbc56d8b51",
73 "name": "test-ams",
74 "organization": "3f709602-5e6c-4619-b80c-e841c89734af",
75 "organization_default": false,
76 "servers": [
77 {
78 "id": "12f19bc7-108c-4517-954c-e6b3d0311363",
79 "name": "scw-e0d158"
80 }
81 ]
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 ScalewaySecurityGroupInfo(Scaleway):
97 def __init__(self, module):
98 super().__init__(module)
99 self.name = "security_groups"
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 module = AnsibleModule(
113 argument_spec=argument_spec,
114 supports_check_mode=True,
115 )
116
117 try:
118 module.exit_json(scaleway_security_group_info=ScalewaySecurityGroupInfo(module).get_resources())
119 except ScalewayException as exc:
120 module.fail_json(msg=exc.message)
121
122
123 if __name__ == "__main__":
124 main()