Debian Codegraph @

ansible_collections/community/proxmox/plugins/modules/proxmox_domain_info.py

raw
1 #!/usr/bin/python
2 #
3 # Copyright Tristan Le Guern (@tleguern) <tleguern at bouledef.eu>
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7
8 DOCUMENTATION = r"""
9 module: proxmox_domain_info
10 short_description: Retrieve information about one or more Proxmox VE domains
11 description:
12 - Retrieve information about one or more Proxmox VE domains.
13 options:
14 domain:
15 description:
16 - Restrict results to a specific authentication realm.
17 aliases: ['realm', 'name']
18 type: str
19 author: Tristan Le Guern (@tleguern)
20 extends_documentation_fragment:
21 - community.proxmox.proxmox.actiongroup_proxmox
22 - community.proxmox.proxmox.documentation
23 - community.proxmox.attributes
24 - community.proxmox.attributes.info_module
25 """
26
27
28 EXAMPLES = r"""
29 - name: List existing domains
30 community.proxmox.proxmox_domain_info:
31 register: proxmox_domains
32
33 - name: Retrieve information about the pve domain
34 community.proxmox.proxmox_domain_info:
35 domain: pve
36 register: proxmox_domain_pve
37 """
38
39
40 RETURN = r"""
41 proxmox_domains:
42 description: List of authentication domains.
43 returned: always, but can be empty
44 type: list
45 elements: dict
46 contains:
47 comment:
48 description: Short description of the realm.
49 returned: on success
50 type: str
51 realm:
52 description: Realm name.
53 returned: on success
54 type: str
55 type:
56 description: Realm type.
57 returned: on success
58 type: str
59 digest:
60 description: Realm hash.
61 returned: on success, can be absent
62 type: str
63 """
64
65
66 from ansible_collections.community.proxmox.plugins.module_utils.proxmox import (
67 ProxmoxAnsible,
68 create_proxmox_module,
69 )
70
71
72 def module_args():
73 return dict(
74 domain=dict(type="str", aliases=["realm", "name"]),
75 )
76
77
78 def module_options():
79 return {}
80
81
82 class ProxmoxDomainInfoAnsible(ProxmoxAnsible):
83 def get_domain(self, realm):
84 try:
85 domain = self.proxmox_api.access.domains.get(realm)
86 except Exception:
87 self.module.fail_json(msg=f"Domain '{realm}' does not exist")
88 domain["realm"] = realm
89 return domain
90
91 def get_domains(self):
92 domains = self.proxmox_api.access.domains.get()
93 return domains
94
95
96 def main():
97 module = create_proxmox_module(module_args(), **module_options())
98 proxmox = ProxmoxDomainInfoAnsible(module)
99
100 result = dict(changed=False)
101
102 domain = module.params["domain"]
103
104 if domain:
105 domains = [proxmox.get_domain(realm=domain)]
106 else:
107 domains = proxmox.get_domains()
108 result["proxmox_domains"] = domains
109
110 module.exit_json(**result)
111
112
113 if __name__ == "__main__":
114 main()