Debian Codegraph @

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