Debian Codegraph @

ansible_collections/vmware/vmware_rest/plugins/modules/appliance_infraprofile_configs_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright: (c) 2021, Ansible Project
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # template: header.j2
6 # This module is autogenerated using the ansible.content_builder.
7 # See: https://github.com/ansible-community/ansible.content_builder
8
9
10 DOCUMENTATION = r"""
11 module: appliance_infraprofile_configs_info
12 short_description: List all the profiles which are registered.
13 description: List all the profiles which are registered.
14 options:
15 session_timeout:
16 description:
17 - 'Timeout settings for client session. '
18 - 'The maximal number of seconds for the whole operation including connection
19 establishment, request sending and response. '
20 - The default value is 300s.
21 type: float
22 version_added: 2.1.0
23 vcenter_hostname:
24 description:
25 - The hostname or IP address of the vSphere vCenter
26 - If the value is not specified in the task, the value of environment variable
27 C(VMWARE_HOST) will be used instead.
28 required: true
29 type: str
30 vcenter_password:
31 description:
32 - The vSphere vCenter password
33 - If the value is not specified in the task, the value of environment variable
34 C(VMWARE_PASSWORD) will be used instead.
35 required: true
36 type: str
37 vcenter_rest_log_file:
38 description:
39 - 'You can use this optional parameter to set the location of a log file. '
40 - 'This file will be used to record the HTTP REST interaction. '
41 - 'The file will be stored on the host that runs the module. '
42 - 'If the value is not specified in the task, the value of '
43 - environment variable C(VMWARE_REST_LOG_FILE) will be used instead.
44 type: str
45 vcenter_username:
46 description:
47 - The vSphere vCenter username
48 - If the value is not specified in the task, the value of environment variable
49 C(VMWARE_USER) will be used instead.
50 required: true
51 type: str
52 vcenter_validate_certs:
53 default: true
54 description:
55 - Allows connection when SSL certificates are not valid. Set to C(false) when
56 certificates are not trusted.
57 - If the value is not specified in the task, the value of environment variable
58 C(VMWARE_VALIDATE_CERTS) will be used instead.
59 type: bool
60 author:
61 - Ansible Cloud Team (@ansible-collections)
62 version_added: 2.0.0
63 requirements:
64 - vSphere 7.0.3 or greater
65 - python >= 3.6
66 - aiohttp
67 notes:
68 - Tested on vSphere 7.0.3
69 """
70
71 EXAMPLES = r"""
72 - name: List infraprofile configs
73 vmware.vmware_rest.appliance_infraprofile_configs_info:
74 register: result
75 """
76 RETURN = r"""
77 # content generated by the update_return_section callback# task: List infraprofile configs
78 value:
79 description: List infraprofile configs
80 returned: On success
81 sample:
82 - info: ApplianceManagement
83 name: ApplianceManagement
84 - info: ApplianceNetwork
85 name: ApplianceNetwork
86 - info: Authentication & Authorization Management
87 name: AuthManagement
88 type: list
89 """
90
91
92 # This structure describes the format of the data expected by the end-points
93 PAYLOAD_FORMAT = {
94 "list": {"query": {}, "body": {}, "path": {}}
95 } # pylint: disable=line-too-long
96
97 from ansible.module_utils.basic import env_fallback
98 import os
99
100 if os.getenv("VMWARE_ENABLE_TURBO", False):
101 try:
102 from ansible_collections.cloud.common.plugins.module_utils.turbo.module import (
103 AnsibleTurboModule as AnsibleModule,
104 )
105
106 AnsibleModule.collection_name = "vmware.vmware_rest"
107 except ImportError:
108 from ansible.module_utils.basic import AnsibleModule
109 else:
110 from ansible.module_utils.basic import AnsibleModule
111
112 from ansible_collections.vmware.vmware_rest.plugins.module_utils.vmware_rest import (
113 gen_args,
114 open_session,
115 session_timeout,
116 update_changed_flag,
117 )
118
119
120 def prepare_argument_spec():
121 argument_spec = {
122 "vcenter_hostname": dict(
123 type="str",
124 required=True,
125 fallback=(env_fallback, ["VMWARE_HOST"]),
126 ),
127 "vcenter_username": dict(
128 type="str",
129 required=True,
130 fallback=(env_fallback, ["VMWARE_USER"]),
131 ),
132 "vcenter_password": dict(
133 type="str",
134 required=True,
135 no_log=True,
136 fallback=(env_fallback, ["VMWARE_PASSWORD"]),
137 ),
138 "vcenter_validate_certs": dict(
139 type="bool",
140 required=False,
141 default=True,
142 fallback=(env_fallback, ["VMWARE_VALIDATE_CERTS"]),
143 ),
144 "vcenter_rest_log_file": dict(
145 type="str",
146 required=False,
147 fallback=(env_fallback, ["VMWARE_REST_LOG_FILE"]),
148 ),
149 "session_timeout": dict(
150 type="float",
151 required=False,
152 fallback=(env_fallback, ["VMWARE_SESSION_TIMEOUT"]),
153 ),
154 }
155
156 return argument_spec
157
158
159 async def main():
160 required_if = list([])
161
162 module_args = prepare_argument_spec()
163 module = AnsibleModule(
164 argument_spec=module_args, required_if=required_if, supports_check_mode=True
165 )
166 if not module.params["vcenter_hostname"]:
167 module.fail_json("vcenter_hostname cannot be empty")
168 if not module.params["vcenter_username"]:
169 module.fail_json("vcenter_username cannot be empty")
170 if not module.params["vcenter_password"]:
171 module.fail_json("vcenter_password cannot be empty")
172 try:
173 session = await open_session(
174 vcenter_hostname=module.params["vcenter_hostname"],
175 vcenter_username=module.params["vcenter_username"],
176 vcenter_password=module.params["vcenter_password"],
177 validate_certs=module.params["vcenter_validate_certs"],
178 log_file=module.params["vcenter_rest_log_file"],
179 )
180 except Exception as err:
181 if hasattr(err, "get_message"):
182 module.fail_json(err.get_message())
183 else:
184 module.fail_json(str(err))
185 result = await entry_point(module, session)
186 module.exit_json(**result)
187
188
189 # template: info_list_and_get_module.j2
190 def build_url(params):
191 import yarl
192
193 _in_query_parameters = PAYLOAD_FORMAT["list"]["query"].keys()
194 return yarl.URL(
195 ("https://{vcenter_hostname}" "/api/appliance/infraprofile/configs").format(
196 **params
197 )
198 + gen_args(params, _in_query_parameters),
199 encoded=True,
200 )
201
202
203 async def entry_point(module, session):
204 url = build_url(module.params)
205 async with session.get(url, **session_timeout(module.params)) as resp:
206 _json = await resp.json()
207
208 if "value" not in _json: # 7.0.2+
209 _json = {"value": _json}
210
211 return await update_changed_flag(_json, resp.status, "get")
212
213
214 if __name__ == "__main__":
215 import asyncio
216
217 current_loop = asyncio.new_event_loop()
218 try:
219 asyncio.set_event_loop(current_loop)
220 current_loop.run_until_complete(main())
221 finally:
222 current_loop.close()