Skip to content

Commit ac5d44b

Browse files
Merge branch 'main' into feature/firewall
2 parents 11a3a19 + 80dc876 commit ac5d44b

19 files changed

+2083
-17
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- proxmox_template - Add 'import' to allowed content types of proxmox_template, so disk images and can be used as disk images on VM creation (https://github.com/ansible-collections/community.proxmox/pull/162).
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- proxmox_storage - fixed adding PBS-type storage by ensuring its parameters (server, datastore, etc.) are correctly sent to the Proxmox API (https://github.com/ansible-collections/community.proxmox/pull/171).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- proxmox_tasks_info - add source option to specify tasks to consider (https://github.com/ansible-collections/community.proxmox/pull/179)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- proxmox_storage - added `dir` and `zfspool` storage types (https://github.com/ansible-collections/community.proxmox/pull/184)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
bugfixes:
3+
- proxmox_kvm - remove limited choice for vga option in proxmox_kvm (https://github.com/ansible-collections/community.proxmox/pull/185)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- proxmox_kvm - update description of machine parameter in proxmox_kvm.py (https://github.com/ansible-collections/community.proxmox/pull/186)

meta/runtime.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ action_groups:
1414
- proxmox_backup_schedule
1515
- proxmox_cluster
1616
- proxmox_cluster_ha_resources
17+
- proxmox_cluster_ha_rules
1718
- proxmox_cluster_ha_groups
1819
- proxmox_cluster_join_info
1920
- proxmox_disk
2021
- proxmox_domain_info
22+
- proxmox_firewall
2123
- proxmox_group
2224
- proxmox_group_info
2325
- proxmox_kvm
@@ -35,4 +37,5 @@ action_groups:
3537
- proxmox_user
3638
- proxmox_user_info
3739
- proxmox_vm_info
38-
- proxmox_firewall
40+
- proxmox_zone
41+
- proxmox_zone_info
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# -*- coding: utf-8 -*-
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+
from __future__ import absolute_import, division, print_function
8+
9+
__metaclass__ = type
10+
11+
from typing import List, Dict
12+
13+
from ansible_collections.community.proxmox.plugins.module_utils.proxmox import (
14+
ansible_to_proxmox_bool,
15+
ProxmoxAnsible
16+
)
17+
18+
19+
class ProxmoxSdnAnsible(ProxmoxAnsible):
20+
"""Base Class for All Proxmox SDN Classes"""
21+
22+
def __init__(self, module):
23+
super(ProxmoxSdnAnsible, self).__init__(module)
24+
self.module = module
25+
26+
def get_global_sdn_lock(self) -> str:
27+
"""Acquire global SDN lock. Needed for any changes under SDN.
28+
29+
:return: lock-token
30+
"""
31+
try:
32+
return self.proxmox_api.cluster().sdn().lock().post()
33+
except Exception as e:
34+
self.module.fail_json(
35+
msg=f'Failed to acquire global sdn lock {e}'
36+
)
37+
38+
def apply_sdn_changes_and_release_lock(self, lock: str, release_lock: bool = True) -> None:
39+
"""Apply all SDN changes done under a lock token.
40+
41+
:param lock: Global SDN lock token
42+
:param release_lock: if True release lock after successfully applying changes
43+
"""
44+
lock_params = {
45+
'lock-token': lock,
46+
'release-lock': ansible_to_proxmox_bool(release_lock)
47+
}
48+
try:
49+
self.proxmox_api.cluster().sdn().put(**lock_params)
50+
except Exception as e:
51+
self.rollback_sdn_changes_and_release_lock(lock)
52+
self.module.fail_json(
53+
msg=f'Failed to apply sdn changes {e}. Rolling back all pending changes.'
54+
)
55+
56+
def rollback_sdn_changes_and_release_lock(self, lock: str, release_lock: bool = True) -> None:
57+
"""Rollback all changes done under a lock token.
58+
59+
:param lock: Global SDN lock token
60+
:param release_lock: if True release lock after successfully rolling back changes
61+
"""
62+
lock_params = {
63+
'lock-token': lock,
64+
'release-lock': ansible_to_proxmox_bool(release_lock)
65+
}
66+
try:
67+
self.proxmox_api.cluster().sdn().rollback().post(**lock_params)
68+
except Exception as e:
69+
self.module.fail_json(
70+
msg=f'Rollback attempt failed - {e}. Manually clear lock by deleting /etc/pve/sdn/.lock'
71+
)
72+
73+
def release_lock(self, lock: str, force: bool = False) -> None:
74+
"""Release Global SDN lock
75+
76+
:param lock: Global SDN lock token
77+
:param force: if true, allow releasing lock without providing the token
78+
"""
79+
lock_params = {
80+
'lock-token': lock,
81+
'force': ansible_to_proxmox_bool(force)
82+
}
83+
try:
84+
self.proxmox_api.cluster().sdn().lock().delete(**lock_params)
85+
except Exception as e:
86+
self.module.fail_json(
87+
msg=f'Failed to release lock - {e}. Manually clear lock by deleting /etc/pve/sdn/.lock'
88+
)
89+
90+
def get_zones(self, zone_type: str = None) -> List[Dict]:
91+
"""Get Proxmox SDN zones
92+
93+
:param zone_type: Filter zones based on type.
94+
:return: list of all zones and their properties.
95+
"""
96+
try:
97+
return self.proxmox_api.cluster().sdn().zones().get(type=zone_type)
98+
except Exception as e:
99+
self.module.fail_json(
100+
msg=f'Failed to retrieve zone information from cluster: {e}'
101+
)

0 commit comments

Comments
 (0)