Debian Codegraph @

ansible_collections/community/vmware/plugins/modules/vmware_host_acceptance_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2018, Abhijeet Kasurde <[email protected]>
5 # Copyright: (c) 2023, Mario Lenz <[email protected]>
6 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
7 # SPDX-License-Identifier: GPL-3.0-or-later
8
9 from __future__ import absolute_import, division, print_function
10 __metaclass__ = type
11
12
13 DOCUMENTATION = r'''
14 ---
15 module: vmware_host_acceptance_info
16 short_description: Gather host acceptance level of ESXi hosts
17 description:
18 - This module can be used to gather the host acceptance level of ESXi hosts.
19 - The host acceptance level controls the acceptance level of each VIB on a ESXi host.
20 author:
21 - Abhijeet Kasurde (@Akasurde)
22 - Mario Lenz (@mariolenz)
23 options:
24 cluster_name:
25 description:
26 - Name of the cluster.
27 - Acceptance level of all ESXi host system in the given cluster will be gathered.
28 - If O(esxi_hostname) is not given, this parameter is required.
29 type: str
30 esxi_hostname:
31 description:
32 - ESXi hostname.
33 - Acceptance level of this ESXi host system will be gathered.
34 - If O(cluster_name) is not given, this parameter is required.
35 type: str
36 extends_documentation_fragment:
37 - vmware.vmware.base_options
38
39 '''
40
41 EXAMPLES = r'''
42 - name: Get acceptance level from the given ESXi Host
43 community.vmware.vmware_host_acceptance_info:
44 hostname: '{{ vcenter_hostname }}'
45 username: '{{ vcenter_username }}'
46 password: '{{ vcenter_password }}'
47 esxi_hostname: '{{ esxi_hostname }}'
48 delegate_to: localhost
49 register: host_acceptance_level
50 '''
51
52 RETURN = r'''
53 host_acceptance_info:
54 description:
55 - dict with hostname as key and dict with acceptance level facts, error as value
56 returned: facts
57 type: dict
58 sample: { "facts": { "localhost.localdomain": { "error": "NA", "level": "vmware_certified" }}}
59 '''
60
61 try:
62 from pyVmomi import vim
63 except ImportError:
64 pass
65 from ansible.module_utils.basic import AnsibleModule
66 from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi
67 from ansible_collections.vmware.vmware.plugins.module_utils.argument_spec import base_argument_spec
68 from ansible.module_utils.common.text.converters import to_native
69
70
71 class VMwareAccpetanceManager(PyVmomi):
72 def __init__(self, module):
73 super(VMwareAccpetanceManager, self).__init__(module)
74 cluster_name = self.params.get('cluster_name', None)
75 esxi_host_name = self.params.get('esxi_hostname', None)
76 self.hosts = self.get_all_host_objs(cluster_name=cluster_name, esxi_host_name=esxi_host_name)
77 self.hosts_facts = {}
78
79 def gather_acceptance_info(self):
80 for host in self.hosts:
81 self.hosts_facts[host.name] = dict(level='', error='NA')
82 host_image_config_mgr = host.configManager.imageConfigManager
83 if host_image_config_mgr:
84 try:
85 self.hosts_facts[host.name]['level'] = host_image_config_mgr.HostImageConfigGetAcceptance()
86 except vim.fault.HostConfigFault as e:
87 self.hosts_facts[host.name]['error'] = to_native(e.msg)
88 self.module.exit_json(changed=False, host_acceptance_info=self.hosts_facts)
89
90
91 def main():
92 argument_spec = base_argument_spec()
93 argument_spec.update(
94 cluster_name=dict(type='str', required=False),
95 esxi_hostname=dict(type='str', required=False),
96 )
97
98 module = AnsibleModule(
99 argument_spec=argument_spec,
100 required_one_of=[
101 ['cluster_name', 'esxi_hostname'],
102 ],
103 supports_check_mode=True
104 )
105
106 vmware_host_accept_config = VMwareAccpetanceManager(module)
107 vmware_host_accept_config.gather_acceptance_info()
108
109
110 if __name__ == "__main__":
111 main()