Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Hewlett Packard Enterprise Development LP
5 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
6 # SPDX-License-Identifier: GPL-3.0-or-later
7
8
9 from __future__ import absolute_import, division, print_function
10 __metaclass__ = type
11
12
13 DOCUMENTATION = r'''
14 ---
15 module: vmware_vsan_release_catalog
16 version_added: '3.7.0'
17 short_description: Uploads the vSAN Release Catalog
18 description:
19 - Manually upload the vSAN Release Catalog the the vCenter
20 - See https://kb.vmware.com/s/article/58891 for more details
21 author:
22 - Philipp Fruck (@p-fruck)
23 requirements:
24 - vSAN Management SDK, which needs to be downloaded from VMware and installed manually.
25 options:
26 source:
27 description:
28 - The path to the release catalog file
29 type: str
30 required: true
31 extends_documentation_fragment:
32 - vmware.vmware.base_options
33 '''
34
35 EXAMPLES = r'''
36 - name: Upload release catalog file to vCenter
37 community.vmware.vmware_vsan_release_catalog:
38 hostname: "{{ vcenter_hostname }}"
39 username: "{{ vcenter_username }}"
40 password: "{{ vcenter_password }}"
41 source: release_catalog.json
42 delegate_to: localhost
43 '''
44
45 RETURN = r'''#
46 '''
47
48 import traceback
49
50 VSANPYTHONSDK_IMP_ERR = None
51 try:
52 import vsanapiutils
53 HAS_VSANPYTHONSDK = True
54 except ImportError:
55 VSANPYTHONSDK_IMP_ERR = traceback.format_exc()
56 HAS_VSANPYTHONSDK = False
57
58 from ansible.module_utils.basic import AnsibleModule
59 from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi
60 from ansible_collections.vmware.vmware.plugins.module_utils.argument_spec import base_argument_spec
61
62
63 class VsanApi(PyVmomi):
64 def __init__(self, module):
65 super(VsanApi, self).__init__(module)
66
67 client_stub = self.si._GetStub()
68 ssl_context = client_stub.schemeArgs.get('context')
69 apiVersion = vsanapiutils.GetLatestVmodlVersion(module.params['hostname'])
70 vcMos = vsanapiutils.GetVsanVcMos(client_stub, context=ssl_context, version=apiVersion)
71 self.vsanVumSystem = vcMos['vsan-vum-system']
72
73 def upload_release_catalog(self, content):
74 self.vsanVumSystem.VsanVcUploadReleaseDb(db=content)
75
76
77 def main():
78 argument_spec = base_argument_spec()
79
80 argument_spec.update(dict(
81 source=dict(type='str', required=True)
82 ))
83
84 module = AnsibleModule(
85 argument_spec=argument_spec,
86 )
87
88 source = module.params['source']
89 api = VsanApi(module)
90
91 try:
92 with open(source, 'r') as f:
93 api.upload_release_catalog(f.read())
94 except Exception as e:
95 module.fail_json(msg=str(e))
96
97 module.exit_json(changed=True)
98
99
100 if __name__ == '__main__':
101 main()