Debian Codegraph @

ansible_collections/vmware/vmware_rest/plugins/modules/appliance_vmon_service_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_vmon_service_info
12 short_description: Returns the state of a service.
13 description: Returns the state of a service.
14 options:
15 service:
16 description:
17 - identifier of the service whose state is being queried.
18 - The parameter must be the id of a resource returned by M(vmware.vmware_rest.appliance_vmon_service).
19 Required with I(state=['get'])
20 type: str
21 session_timeout:
22 description:
23 - 'Timeout settings for client session. '
24 - 'The maximal number of seconds for the whole operation including connection
25 establishment, request sending and response. '
26 - The default value is 300s.
27 type: float
28 version_added: 2.1.0
29 vcenter_hostname:
30 description:
31 - The hostname or IP address of the vSphere vCenter
32 - If the value is not specified in the task, the value of environment variable
33 C(VMWARE_HOST) will be used instead.
34 required: true
35 type: str
36 vcenter_password:
37 description:
38 - The vSphere vCenter password
39 - If the value is not specified in the task, the value of environment variable
40 C(VMWARE_PASSWORD) will be used instead.
41 required: true
42 type: str
43 vcenter_rest_log_file:
44 description:
45 - 'You can use this optional parameter to set the location of a log file. '
46 - 'This file will be used to record the HTTP REST interaction. '
47 - 'The file will be stored on the host that runs the module. '
48 - 'If the value is not specified in the task, the value of '
49 - environment variable C(VMWARE_REST_LOG_FILE) will be used instead.
50 type: str
51 vcenter_username:
52 description:
53 - The vSphere vCenter username
54 - If the value is not specified in the task, the value of environment variable
55 C(VMWARE_USER) will be used instead.
56 required: true
57 type: str
58 vcenter_validate_certs:
59 default: true
60 description:
61 - Allows connection when SSL certificates are not valid. Set to C(false) when
62 certificates are not trusted.
63 - If the value is not specified in the task, the value of environment variable
64 C(VMWARE_VALIDATE_CERTS) will be used instead.
65 type: bool
66 author:
67 - Ansible Cloud Team (@ansible-collections)
68 version_added: 2.0.0
69 requirements:
70 - vSphere 7.0.3 or greater
71 - python >= 3.6
72 - aiohttp
73 notes:
74 - Tested on vSphere 7.0.3
75 """
76
77 EXAMPLES = r"""
78 - name: Get information about a VMON service
79 vmware.vmware_rest.appliance_vmon_service_info:
80 service: vpxd
81 register: result
82 """
83 RETURN = r"""
84 # content generated by the update_return_section callback# task: Get information about a VMON service
85 value:
86 description: Get information about a VMON service
87 returned: On success
88 sample:
89 - key: analytics
90 value:
91 description_key: cis.analytics.ServiceDescription
92 health: HEALTHY
93 health_messages: []
94 name_key: cis.analytics.ServiceName
95 startup_type: AUTOMATIC
96 state: STARTED
97 - key: applmgmt
98 value:
99 description_key: cis.applmgmt.ServiceDescription
100 health: HEALTHY
101 health_messages: []
102 name_key: cis.applmgmt.ServiceName
103 startup_type: AUTOMATIC
104 state: STARTED
105 - key: certificateauthority
106 value:
107 description_key: cis.certificateauthority.ServiceDescription
108 health: HEALTHY
109 health_messages:
110 - args:
111 - GREEN
112 default_message: Health is GREEN
113 id: certificateathority.health.statuscode
114 name_key: cis.certificateauthority.ServiceName
115 startup_type: AUTOMATIC
116 state: STARTED
117 - key: certificatemanagement
118 value:
119 description_key: cis.certificatemanagement.ServiceDescription
120 health: HEALTHY
121 health_messages:
122 - args:
123 - GREEN
124 default_message: Health is GREEN
125 id: certificatemanagement.health.statuscode
126 name_key: cis.certificatemanagement.ServiceName
127 startup_type: AUTOMATIC
128 state: STARTED
129 - key: cis-license
130 value:
131 description_key: cis.cis-license.ServiceDescription
132 health: HEALTHY
133 health_messages:
134 - args: []
135 default_message: The License Service is operational.
136 id: cis.license.health.ok
137 name_key: cis.cis-license.ServiceName
138 startup_type: AUTOMATIC
139 state: STARTED
140 - key: content-library
141 value:
142 description_key: cis.content-library.ServiceDescription
143 health: HEALTHY
144 health_messages:
145 - args: []
146 default_message: Database server connection is GREEN.
147 id: com.vmware.vdcs.vsphere-cs-lib.db_health_green
148 name_key: cis.content-library.ServiceName
149 startup_type: AUTOMATIC
150 state: STARTED
151 - key: eam
152 value:
153 description_key: cis.eam.ServiceDescription
154 health: HEALTHY
155 health_messages:
156 - args: []
157 default_message: ''
158 id: cis.eam.statusOK
159 name_key: cis.eam.ServiceName
160 startup_type: AUTOMATIC
161 state: STARTED
162 - key: envoy
163 value:
164 description_key: cis.envoy.ServiceDescription
165 health: HEALTHY
166 health_messages: []
167 name_key: cis.envoy.ServiceName
168 startup_type: AUTOMATIC
169 state: STARTED
170 - key: hvc
171 value:
172 description_key: cis.hvc.ServiceDescription
173 health: HEALTHY
174 health_messages:
175 - args:
176 - GREEN
177 default_message: Health is GREEN
178 id: hvc.health.statuscode
179 name_key: cis.hvc.ServiceName
180 startup_type: AUTOMATIC
181 state: STARTED
182 - key: imagebuilder
183 value:
184 description_key: cis.imagebuilder.ServiceDescription
185 name_key: cis.imagebuilder.ServiceName
186 startup_type: MANUAL
187 state: STOPPED
188 - key: infraprofile
189 value:
190 description_key: cis.infraprofile.ServiceDescription
191 health: HEALTHY
192 health_messages:
193 - args:
194 - GREEN
195 default_message: Health is GREEN
196 id: infraprofile.health.statuscode
197 name_key: cis.infraprofile.ServiceName
198 startup_type: AUTOMATIC
199 state: STARTED
200 - key: lookupsvc
201 value:
202 description_key: cis.lookupsvc.ServiceDescription
203 health: HEALTHY
204 health_messages: []
205 name_key: cis.lookupsvc.ServiceName
206 startup_type: AUTOMATIC
207 state: STARTED
208 - key: netdumper
209 value:
210 description_key: cis.netdumper.ServiceDescription
211 name_key: cis.netdumper.ServiceName
212 startup_type: MANUAL
213 state: STOPPED
214 - key: observability-vapi
215 value:
216 description_key: cis.observability-vapi.ServiceDescription
217 health: HEALTHY
218 health_messages:
219 - args:
220 - GREEN
221 default_message: Health is GREEN
222 id: observability.health.statuscode
223 name_key: cis.observability-vapi.ServiceName
224 startup_type: AUTOMATIC
225 state: STARTED
226 - key: perfcharts
227 value:
228 description_key: cis.perfcharts.ServiceDescription
229 health: HEALTHY_WITH_WARNINGS
230 health_messages:
231 - args: []
232 default_message: health.statsReoptInitalizer.illegalStateEx
233 id: health.statsReoptInitalizer.illegalStateEx
234 name_key: cis.perfcharts.ServiceName
235 startup_type: AUTOMATIC
236 state: STARTED
237 - key: pschealth
238 value:
239 description_key: cis.pschealth.ServiceDescription
240 health: HEALTHY
241 health_messages: []
242 name_key: cis.pschealth.ServiceName
243 startup_type: AUTOMATIC
244 state: STARTED
245 - key: rbd
246 value:
247 description_key: cis.rbd.ServiceDescription
248 name_key: cis.rbd.ServiceName
249 startup_type: MANUAL
250 state: STOPPED
251 - key: rhttpproxy
252 value:
253 description_key: cis.rhttpproxy.ServiceDescription
254 health: HEALTHY
255 health_messages: []
256 name_key: cis.rhttpproxy.ServiceName
257 startup_type: AUTOMATIC
258 state: STARTED
259 - key: sca
260 value:
261 description_key: cis.sca.ServiceDescription
262 health: HEALTHY
263 health_messages: []
264 name_key: cis.sca.ServiceName
265 startup_type: AUTOMATIC
266 state: STARTED
267 - key: sps
268 value:
269 description_key: cis.sps.ServiceDescription
270 health: HEALTHY
271 health_messages: []
272 name_key: cis.sps.ServiceName
273 startup_type: AUTOMATIC
274 state: STARTED
275 - key: statsmonitor
276 value:
277 description_key: cis.statsmonitor.ServiceDescription
278 health: HEALTHY
279 health_messages:
280 - args: []
281 default_message: Appliance monitoring service is healthy.
282 id: com.vmware.applmgmt.mon.health.healthy
283 name_key: cis.statsmonitor.ServiceName
284 startup_type: AUTOMATIC
285 state: STARTED
286 - key: sts
287 value:
288 description_key: cis.sts.ServiceDescription
289 health: HEALTHY
290 health_messages: []
291 name_key: cis.sts.ServiceName
292 startup_type: AUTOMATIC
293 state: STARTED
294 - key: topologysvc
295 value:
296 description_key: cis.topologysvc.ServiceDescription
297 health: HEALTHY
298 health_messages:
299 - args:
300 - GREEN
301 default_message: Health is GREEN
302 id: topologysvc.health.statuscode
303 name_key: cis.topologysvc.ServiceName
304 startup_type: AUTOMATIC
305 state: STARTED
306 - key: trustmanagement
307 value:
308 description_key: cis.trustmanagement.ServiceDescription
309 health: HEALTHY
310 health_messages:
311 - args:
312 - GREEN
313 default_message: Health is GREEN
314 id: trustmanagement.health.statuscode
315 name_key: cis.trustmanagement.ServiceName
316 startup_type: AUTOMATIC
317 state: STARTED
318 - key: updatemgr
319 value:
320 description_key: cis.updatemgr.ServiceDescription
321 health: HEALTHY
322 health_messages: []
323 name_key: cis.updatemgr.ServiceName
324 startup_type: AUTOMATIC
325 state: STARTED
326 - key: vapi-endpoint
327 value:
328 description_key: cis.vapi-endpoint.ServiceDescription
329 health: HEALTHY
330 health_messages:
331 - args:
332 - 2022-11-23T20:10:44UTC
333 - 2022-11-23T20:10:46UTC
334 default_message: Configuration health status is created between 2022-11-23T20:10:44UTC
335 and 2022-11-23T20:10:46UTC.
336 id: com.vmware.vapi.endpoint.healthStatusProducedTimes
337 name_key: cis.vapi-endpoint.ServiceName
338 startup_type: AUTOMATIC
339 state: STARTED
340 - key: vcha
341 value:
342 description_key: cis.vcha.ServiceDescription
343 name_key: cis.vcha.ServiceName
344 startup_type: DISABLED
345 state: STOPPED
346 - key: vlcm
347 value:
348 description_key: cis.vlcm.ServiceDescription
349 health: HEALTHY
350 health_messages: []
351 name_key: cis.vlcm.ServiceName
352 startup_type: AUTOMATIC
353 state: STARTED
354 - key: vmcam
355 value:
356 description_key: cis.vmcam.ServiceDescription
357 name_key: cis.vmcam.ServiceName
358 startup_type: MANUAL
359 state: STOPPED
360 - key: vmonapi
361 value:
362 description_key: cis.vmonapi.ServiceDescription
363 health: HEALTHY
364 health_messages: []
365 name_key: cis.vmonapi.ServiceName
366 startup_type: AUTOMATIC
367 state: STARTED
368 - key: vmware-postgres-archiver
369 value:
370 description_key: cis.vmware-postgres-archiver.ServiceDescription
371 health: HEALTHY
372 health_messages:
373 - args: []
374 default_message: VMware Archiver service is healthy.
375 id: cis.vmware-postgres-archiver.health.healthy
376 name_key: cis.vmware-postgres-archiver.ServiceName
377 startup_type: AUTOMATIC
378 state: STARTED
379 - key: vmware-vpostgres
380 value:
381 description_key: cis.vmware-vpostgres.ServiceDescription
382 health: HEALTHY
383 health_messages:
384 - args: []
385 default_message: Service vmware-vpostgres is healthy.
386 id: cis.vmware-vpostgres.health.healthy
387 name_key: cis.vmware-vpostgres.ServiceName
388 startup_type: AUTOMATIC
389 state: STARTED
390 - key: vpxd
391 value:
392 description_key: cis.vpxd.ServiceDescription
393 health: HEALTHY
394 health_messages:
395 - args:
396 - vCenter Server
397 - GREEN
398 default_message: '{0} health is {1}'
399 id: vc.health.statuscode
400 - args:
401 - VirtualCenter Database
402 - GREEN
403 default_message: '{0} health is {1}'
404 id: vc.health.statuscode
405 name_key: cis.vpxd.ServiceName
406 startup_type: AUTOMATIC
407 state: STARTED
408 - key: vpxd-svcs
409 value:
410 description_key: cis.vpxd-svcs.ServiceDescription
411 health: HEALTHY
412 health_messages:
413 - args: []
414 default_message: Tagging service is in a healthy state
415 id: cis.tagging.health.status
416 name_key: cis.vpxd-svcs.ServiceName
417 startup_type: AUTOMATIC
418 state: STARTED
419 - key: vsan-health
420 value:
421 description_key: cis.vsan-health.ServiceDescription
422 health: HEALTHY
423 health_messages: []
424 name_key: cis.vsan-health.ServiceName
425 startup_type: AUTOMATIC
426 state: STARTED
427 - key: vsm
428 value:
429 description_key: cis.vsm.ServiceDescription
430 health: HEALTHY
431 health_messages: []
432 name_key: cis.vsm.ServiceName
433 startup_type: AUTOMATIC
434 state: STARTED
435 - key: vsphere-ui
436 value:
437 description_key: cis.vsphere-ui.ServiceDescription
438 name_key: cis.vsphere-ui.ServiceName
439 startup_type: AUTOMATIC
440 state: STOPPED
441 - key: vstats
442 value:
443 description_key: cis.vstats.ServiceDescription
444 health: HEALTHY
445 health_messages: []
446 name_key: cis.vstats.ServiceName
447 startup_type: AUTOMATIC
448 state: STARTED
449 - key: vtsdb
450 value:
451 description_key: cis.vtsdb.ServiceDescription
452 health: HEALTHY
453 health_messages:
454 - args: []
455 default_message: Service vtsdb is healthy.
456 id: cis.vtsdb.health.healthy
457 name_key: cis.vtsdb.ServiceName
458 startup_type: AUTOMATIC
459 state: STARTED
460 - key: wcp
461 value:
462 description_key: cis.wcp.ServiceDescription
463 health: HEALTHY
464 health_messages: []
465 name_key: cis.wcp.ServiceName
466 startup_type: AUTOMATIC
467 state: STARTED
468 type: list
469 """
470
471
472 # This structure describes the format of the data expected by the end-points
473 PAYLOAD_FORMAT = {
474 "get": {"query": {}, "body": {}, "path": {"service": "service"}}
475 } # pylint: disable=line-too-long
476
477 from ansible.module_utils.basic import env_fallback
478 import os
479
480 if os.getenv("VMWARE_ENABLE_TURBO", False):
481 try:
482 from ansible_collections.cloud.common.plugins.module_utils.turbo.module import (
483 AnsibleTurboModule as AnsibleModule,
484 )
485
486 AnsibleModule.collection_name = "vmware.vmware_rest"
487 except ImportError:
488 from ansible.module_utils.basic import AnsibleModule
489 else:
490 from ansible.module_utils.basic import AnsibleModule
491
492 from ansible_collections.vmware.vmware_rest.plugins.module_utils.vmware_rest import (
493 gen_args,
494 open_session,
495 session_timeout,
496 update_changed_flag,
497 )
498
499
500 def prepare_argument_spec():
501 argument_spec = {
502 "vcenter_hostname": dict(
503 type="str",
504 required=True,
505 fallback=(env_fallback, ["VMWARE_HOST"]),
506 ),
507 "vcenter_username": dict(
508 type="str",
509 required=True,
510 fallback=(env_fallback, ["VMWARE_USER"]),
511 ),
512 "vcenter_password": dict(
513 type="str",
514 required=True,
515 no_log=True,
516 fallback=(env_fallback, ["VMWARE_PASSWORD"]),
517 ),
518 "vcenter_validate_certs": dict(
519 type="bool",
520 required=False,
521 default=True,
522 fallback=(env_fallback, ["VMWARE_VALIDATE_CERTS"]),
523 ),
524 "vcenter_rest_log_file": dict(
525 type="str",
526 required=False,
527 fallback=(env_fallback, ["VMWARE_REST_LOG_FILE"]),
528 ),
529 "session_timeout": dict(
530 type="float",
531 required=False,
532 fallback=(env_fallback, ["VMWARE_SESSION_TIMEOUT"]),
533 ),
534 }
535
536 argument_spec["service"] = {"type": "str"}
537
538 return argument_spec
539
540
541 async def main():
542 required_if = list([])
543
544 module_args = prepare_argument_spec()
545 module = AnsibleModule(
546 argument_spec=module_args, required_if=required_if, supports_check_mode=True
547 )
548 if not module.params["vcenter_hostname"]:
549 module.fail_json("vcenter_hostname cannot be empty")
550 if not module.params["vcenter_username"]:
551 module.fail_json("vcenter_username cannot be empty")
552 if not module.params["vcenter_password"]:
553 module.fail_json("vcenter_password cannot be empty")
554 try:
555 session = await open_session(
556 vcenter_hostname=module.params["vcenter_hostname"],
557 vcenter_username=module.params["vcenter_username"],
558 vcenter_password=module.params["vcenter_password"],
559 validate_certs=module.params["vcenter_validate_certs"],
560 log_file=module.params["vcenter_rest_log_file"],
561 )
562 except Exception as err:
563 if hasattr(err, "get_message"):
564 module.fail_json(err.get_message())
565 else:
566 module.fail_json(str(err))
567 result = await entry_point(module, session)
568 module.exit_json(**result)
569
570
571 # template: info_no_list_module.j2
572 def build_url(params):
573 return ("https://{vcenter_hostname}" "/rest/appliance/vmon/service").format(
574 **params
575 )
576
577
578 async def entry_point(module, session):
579 return await _info(module.params, session)
580
581
582 async def _info(params, session):
583 payload_format = list(PAYLOAD_FORMAT.values())[0]
584 _in_query_parameters = payload_format["query"].keys()
585 _url = ("https://{vcenter_hostname}" "/rest/appliance/vmon/service").format(
586 **params
587 ) + gen_args(params, _in_query_parameters)
588 async with session.get(_url, **session_timeout(params)) as resp:
589 try:
590 if resp.headers["Content-Type"] == "application/json":
591 _json = await resp.json()
592 except KeyError:
593 _json = {}
594 return await update_changed_flag(_json, resp.status, "get")
595
596
597 if __name__ == "__main__":
598 import asyncio
599
600 current_loop = asyncio.new_event_loop()
601 try:
602 asyncio.set_event_loop(current_loop)
603 current_loop.run_until_complete(main())
604 finally:
605 current_loop.close()