Debian Codegraph @

ansible_collections/vmware/vmware_rest/plugins/modules/appliance_access_consolecli_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_access_consolecli_info
12 short_description: Get enabled state of the console-based controlled CLI (TTY1).
13 description: Get enabled state of the console-based controlled CLI (TTY1).
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: Check if the Console CLI is enabled
77 vmware.vmware_rest.appliance_access_consolecli_info:
78 """
79 RETURN = r"""
80 # content generated by the update_return_section callback# task: Check if the Console CLI is enabled
81 value:
82 description: Check if the Console CLI is enabled
83 returned: On success
84 sample: 1
85 type: int
86 """
87
88
89 # This structure describes the format of the data expected by the end-points
90 PAYLOAD_FORMAT = {
91 "get": {"query": {}, "body": {}, "path": {}}
92 } # pylint: disable=line-too-long
93
94 from ansible.module_utils.basic import env_fallback
95 import os
96
97 if os.getenv("VMWARE_ENABLE_TURBO", False):
98 try:
99 from ansible_collections.cloud.common.plugins.module_utils.turbo.module import (
100 AnsibleTurboModule as AnsibleModule,
101 )
102
103 AnsibleModule.collection_name = "vmware.vmware_rest"
104 except ImportError:
105 from ansible.module_utils.basic import AnsibleModule
106 else:
107 from ansible.module_utils.basic import AnsibleModule
108
109 from ansible_collections.vmware.vmware_rest.plugins.module_utils.vmware_rest import (
110 gen_args,
111 open_session,
112 session_timeout,
113 update_changed_flag,
114 )
115
116
117 def prepare_argument_spec():
118 argument_spec = {
119 "vcenter_hostname": dict(
120 type="str",
121 required=True,
122 fallback=(env_fallback, ["VMWARE_HOST"]),
123 ),
124 "vcenter_username": dict(
125 type="str",
126 required=True,
127 fallback=(env_fallback, ["VMWARE_USER"]),
128 ),
129 "vcenter_password": dict(
130 type="str",
131 required=True,
132 no_log=True,
133 fallback=(env_fallback, ["VMWARE_PASSWORD"]),
134 ),
135 "vcenter_validate_certs": dict(
136 type="bool",
137 required=False,
138 default=True,
139 fallback=(env_fallback, ["VMWARE_VALIDATE_CERTS"]),
140 ),
141 "vcenter_rest_log_file": dict(
142 type="str",
143 required=False,
144 fallback=(env_fallback, ["VMWARE_REST_LOG_FILE"]),
145 ),
146 "session_timeout": dict(
147 type="float",
148 required=False,
149 fallback=(env_fallback, ["VMWARE_SESSION_TIMEOUT"]),
150 ),
151 }
152
153 return argument_spec
154
155
156 async def main():
157 required_if = list([])
158
159 module_args = prepare_argument_spec()
160 module = AnsibleModule(
161 argument_spec=module_args, required_if=required_if, supports_check_mode=True
162 )
163 if not module.params["vcenter_hostname"]:
164 module.fail_json("vcenter_hostname cannot be empty")
165 if not module.params["vcenter_username"]:
166 module.fail_json("vcenter_username cannot be empty")
167 if not module.params["vcenter_password"]:
168 module.fail_json("vcenter_password cannot be empty")
169 try:
170 session = await open_session(
171 vcenter_hostname=module.params["vcenter_hostname"],
172 vcenter_username=module.params["vcenter_username"],
173 vcenter_password=module.params["vcenter_password"],
174 validate_certs=module.params["vcenter_validate_certs"],
175 log_file=module.params["vcenter_rest_log_file"],
176 )
177 except Exception as err:
178 if hasattr(err, "get_message"):
179 module.fail_json(err.get_message())
180 else:
181 module.fail_json(str(err))
182 result = await entry_point(module, session)
183 module.exit_json(**result)
184
185
186 # template: info_no_list_module.j2
187 def build_url(params):
188 return ("https://{vcenter_hostname}" "/api/appliance/access/consolecli").format(
189 **params
190 )
191
192
193 async def entry_point(module, session):
194 return await _info(module.params, session)
195
196
197 async def _info(params, session):
198 payload_format = list(PAYLOAD_FORMAT.values())[0]
199 _in_query_parameters = payload_format["query"].keys()
200 _url = ("https://{vcenter_hostname}" "/api/appliance/access/consolecli").format(
201 **params
202 ) + gen_args(params, _in_query_parameters)
203 async with session.get(_url, **session_timeout(params)) as resp:
204 try:
205 if resp.headers["Content-Type"] == "application/json":
206 _json = await resp.json()
207 except KeyError:
208 _json = {}
209 return await update_changed_flag(_json, resp.status, "get")
210
211
212 if __name__ == "__main__":
213 import asyncio
214
215 current_loop = asyncio.new_event_loop()
216 try:
217 asyncio.set_event_loop(current_loop)
218 current_loop.run_until_complete(main())
219 finally:
220 current_loop.close()