Debian Codegraph @

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