Debian Codegraph @

ansible_collections/vmware/vmware_rest/plugins/modules/appliance_health_softwarepackages_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_softwarepackages_info
12 short_description: Get information on available software updates available in the
13 remote vSphere Update Manager repository
14 description: Get information on available software updates available in the remote
15 vSphere Update Manager repository. Red indicates that security updates are available.
16 Orange indicates that non-security updates are available. Green indicates that
17 there are no updates available. Gray indicates that there was an error retreiving
18 information on software updates.
19 options:
20 session_timeout:
21 description:
22 - 'Timeout settings for client session. '
23 - 'The maximal number of seconds for the whole operation including connection
24 establishment, request sending and response. '
25 - The default value is 300s.
26 type: float
27 version_added: 2.1.0
28 vcenter_hostname:
29 description:
30 - The hostname or IP address of the vSphere vCenter
31 - If the value is not specified in the task, the value of environment variable
32 C(VMWARE_HOST) will be used instead.
33 required: true
34 type: str
35 vcenter_password:
36 description:
37 - The vSphere vCenter password
38 - If the value is not specified in the task, the value of environment variable
39 C(VMWARE_PASSWORD) will be used instead.
40 required: true
41 type: str
42 vcenter_rest_log_file:
43 description:
44 - 'You can use this optional parameter to set the location of a log file. '
45 - 'This file will be used to record the HTTP REST interaction. '
46 - 'The file will be stored on the host that runs the module. '
47 - 'If the value is not specified in the task, the value of '
48 - environment variable C(VMWARE_REST_LOG_FILE) will be used instead.
49 type: str
50 vcenter_username:
51 description:
52 - The vSphere vCenter username
53 - If the value is not specified in the task, the value of environment variable
54 C(VMWARE_USER) will be used instead.
55 required: true
56 type: str
57 vcenter_validate_certs:
58 default: true
59 description:
60 - Allows connection when SSL certificates are not valid. Set to C(false) when
61 certificates are not trusted.
62 - If the value is not specified in the task, the value of environment variable
63 C(VMWARE_VALIDATE_CERTS) will be used instead.
64 type: bool
65 author:
66 - Ansible Cloud Team (@ansible-collections)
67 version_added: 2.0.0
68 requirements:
69 - vSphere 7.0.3 or greater
70 - python >= 3.6
71 - aiohttp
72 notes:
73 - Tested on vSphere 7.0.3
74 """
75
76 EXAMPLES = r"""
77 - name: Get the health of the software package manager
78 vmware.vmware_rest.appliance_health_softwarepackages_info:
79 register: result
80 """
81 RETURN = r"""
82 # content generated by the update_return_section callback# task: Get the health of the software package manager
83 value:
84 description: Get the health of the software package manager
85 returned: On success
86 sample: green
87 type: str
88 """
89
90
91 # This structure describes the format of the data expected by the end-points
92 PAYLOAD_FORMAT = {
93 "get": {"query": {}, "body": {}, "path": {}}
94 } # pylint: disable=line-too-long
95
96 from ansible.module_utils.basic import env_fallback
97 import os
98
99 if os.getenv("VMWARE_ENABLE_TURBO", False):
100 try:
101 from ansible_collections.cloud.common.plugins.module_utils.turbo.module import (
102 AnsibleTurboModule as AnsibleModule,
103 )
104
105 AnsibleModule.collection_name = "vmware.vmware_rest"
106 except ImportError:
107 from ansible.module_utils.basic import AnsibleModule
108 else:
109 from ansible.module_utils.basic import AnsibleModule
110
111 from ansible_collections.vmware.vmware_rest.plugins.module_utils.vmware_rest import (
112 gen_args,
113 open_session,
114 session_timeout,
115 update_changed_flag,
116 )
117
118
119 def prepare_argument_spec():
120 argument_spec = {
121 "vcenter_hostname": dict(
122 type="str",
123 required=True,
124 fallback=(env_fallback, ["VMWARE_HOST"]),
125 ),
126 "vcenter_username": dict(
127 type="str",
128 required=True,
129 fallback=(env_fallback, ["VMWARE_USER"]),
130 ),
131 "vcenter_password": dict(
132 type="str",
133 required=True,
134 no_log=True,
135 fallback=(env_fallback, ["VMWARE_PASSWORD"]),
136 ),
137 "vcenter_validate_certs": dict(
138 type="bool",
139 required=False,
140 default=True,
141 fallback=(env_fallback, ["VMWARE_VALIDATE_CERTS"]),
142 ),
143 "vcenter_rest_log_file": dict(
144 type="str",
145 required=False,
146 fallback=(env_fallback, ["VMWARE_REST_LOG_FILE"]),
147 ),
148 "session_timeout": dict(
149 type="float",
150 required=False,
151 fallback=(env_fallback, ["VMWARE_SESSION_TIMEOUT"]),
152 ),
153 }
154
155 return argument_spec
156
157
158 async def main():
159 required_if = list([])
160
161 module_args = prepare_argument_spec()
162 module = AnsibleModule(
163 argument_spec=module_args, required_if=required_if, supports_check_mode=True
164 )
165 if not module.params["vcenter_hostname"]:
166 module.fail_json("vcenter_hostname cannot be empty")
167 if not module.params["vcenter_username"]:
168 module.fail_json("vcenter_username cannot be empty")
169 if not module.params["vcenter_password"]:
170 module.fail_json("vcenter_password cannot be empty")
171 try:
172 session = await open_session(
173 vcenter_hostname=module.params["vcenter_hostname"],
174 vcenter_username=module.params["vcenter_username"],
175 vcenter_password=module.params["vcenter_password"],
176 validate_certs=module.params["vcenter_validate_certs"],
177 log_file=module.params["vcenter_rest_log_file"],
178 )
179 except Exception as err:
180 if hasattr(err, "get_message"):
181 module.fail_json(err.get_message())
182 else:
183 module.fail_json(str(err))
184 result = await entry_point(module, session)
185 module.exit_json(**result)
186
187
188 # template: info_no_list_module.j2
189 def build_url(params):
190 return (
191 "https://{vcenter_hostname}" "/api/appliance/health/software-packages"
192 ).format(**params)
193
194
195 async def entry_point(module, session):
196 return await _info(module.params, session)
197
198
199 async def _info(params, session):
200 payload_format = list(PAYLOAD_FORMAT.values())[0]
201 _in_query_parameters = payload_format["query"].keys()
202 _url = (
203 "https://{vcenter_hostname}" "/api/appliance/health/software-packages"
204 ).format(**params) + gen_args(params, _in_query_parameters)
205 async with session.get(_url, **session_timeout(params)) as resp:
206 try:
207 if resp.headers["Content-Type"] == "application/json":
208 _json = await resp.json()
209 except KeyError:
210 _json = {}
211 return await update_changed_flag(_json, resp.status, "get")
212
213
214 if __name__ == "__main__":
215 import asyncio
216
217 current_loop = asyncio.new_event_loop()
218 try:
219 asyncio.set_event_loop(current_loop)
220 current_loop.run_until_complete(main())
221 finally:
222 current_loop.close()