Debian Codegraph @

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

raw
1 #!/usr/bin/python
2
3 # Copyright (c) 2025, Jana Hoch <[email protected]>
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_zone_info
10 short_description: Get Proxmox zone info.
11 description:
12 - List all available zones.
13 version_added: "1.4.0"
14 author: 'Jana Hoch <[email protected]> (!UNKNOWN)'
15 options:
16 type:
17 description:
18 - Filter zones on based on type.
19 type: str
20 choices:
21 - evpn
22 - faucet
23 - qinq
24 - simple
25 - vlan
26 - vxlan
27 extends_documentation_fragment:
28 - community.proxmox.proxmox.actiongroup_proxmox
29 - community.proxmox.proxmox.documentation
30 - community.proxmox.attributes
31 - community.proxmox.attributes.info_module
32 """
33
34 EXAMPLES = r"""
35 - name: Get all zones
36 community.proxmox.proxmox_zone_info:
37
38 - name: Get all simple zones
39 community.proxmox.proxmox_zone_info:
40 type: simple
41 register: zones
42 """
43
44 RETURN = r"""
45 zones:
46 description:
47 - List of zones.
48 - If type is passed it'll filter based on type
49 returned: on success
50 type: list
51 elements: dict
52 sample:
53 [
54 {
55 "digest": "e29dea494461aa699ab3bfb7264d95631c8d0e0d",
56 "type": "simple",
57 "zone": "ans1"
58 },
59 {
60 "bridge": "vmbr0",
61 "digest": "e29dea494461aa699ab3bfb7264d95631c8d0e0d",
62 "mtu": 1200,
63 "type": "vlan",
64 "zone": "ansible"
65 },
66 {
67 "bridge": "vmbr100",
68 "digest": "e29dea494461aa699ab3bfb7264d95631c8d0e0d",
69 "ipam": "pve",
70 "type": "vlan",
71 "zone": "lab"
72 },
73 {
74 "dhcp": "dnsmasq",
75 "digest": "e29dea494461aa699ab3bfb7264d95631c8d0e0d",
76 "ipam": "pve",
77 "type": "simple",
78 "zone": "test1"
79 },
80 {
81 "digest": "e29dea494461aa699ab3bfb7264d95631c8d0e0d",
82 "ipam": "pve",
83 "type": "simple",
84 "zone": "tsjsfv"
85 }
86 ]
87
88 """
89
90 from ansible_collections.community.proxmox.plugins.module_utils.proxmox import create_proxmox_module
91 from ansible_collections.community.proxmox.plugins.module_utils.proxmox_sdn import ProxmoxSdnAnsible
92
93
94 def module_args():
95 return dict(type=dict(type="str", choices=["evpn", "faucet", "qinq", "simple", "vlan", "vxlan"], required=False))
96
97
98 def module_options():
99 return {}
100
101
102 class ProxmoxZoneInfoAnsible(ProxmoxSdnAnsible):
103 def __init__(self, module):
104 super().__init__(module)
105 self.params = module.params
106
107 def run(self):
108 zones = self.get_zones(zone_type=self.params.get("type"))
109 self.module.exit_json(changed=False, zones=zones, msg="Successfully retrieved zone info.")
110
111
112 def main():
113 module = create_proxmox_module(module_args(), **module_options())
114 proxmox = ProxmoxZoneInfoAnsible(module)
115
116 try:
117 proxmox.run()
118 except Exception as e:
119 module.fail_json(msg=f"An error occurred: {e}")
120
121
122 if __name__ == "__main__":
123 main()