Debian Codegraph @

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