Debian Codegraph @

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