Debian Codegraph @

ansible_collections/vmware/vmware_rest/plugins/modules/appliance_localaccounts_globalpolicy_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_localaccounts_globalpolicy_info
12 short_description: Get the global password policy.
13 description: Get the global password policy.
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: Get the global policy of the local accounts
73 vmware.vmware_rest.appliance_localaccounts_globalpolicy_info:
74 register: result
75 """
76 RETURN = r"""
77 # content generated by the update_return_section callback# task: Get the global policy of the local accounts
78 value:
79 description: Get the global policy of the local accounts
80 returned: On success
81 sample:
82 max_days: 90
83 min_days: 1
84 warn_days: 7
85 type: dict
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 (
189 "https://{vcenter_hostname}" "/api/appliance/local-accounts/global-policy"
190 ).format(**params)
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 = (
201 "https://{vcenter_hostname}" "/api/appliance/local-accounts/global-policy"
202 ).format(**params) + 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()