Debian Codegraph @

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