Skip to content

Commit 1f15a9d

Browse files
JanaHochThulium-Drake
authored andcommitted
proxmox_subnet: Added method to delete subnet
1 parent 1d875a7 commit 1f15a9d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

plugins/modules/proxmox_subnet.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def get_ansible_module():
5858
required_if=[
5959
('state', 'present', ['subnet', 'type', 'vnet']),
6060
('state', 'update', ['zone', 'vnet', 'subnet']),
61+
('state', 'absent', ['zone', 'vnet', 'subnet']),
6162
]
6263
)
6364

@@ -86,6 +87,8 @@ def run(self):
8687
self.subnet_present(**subnet_params)
8788
elif state == 'update':
8889
self.subnet_update(**subnet_params)
90+
elif state == 'absent':
91+
self.subnet_absent(**subnet_params)
8992

9093
def get_dhcp_range(self):
9194
if self.params.get('dhcp_range') is None:
@@ -137,6 +140,31 @@ def subnet_update(self, **subnet_params):
137140
msg=f'Failed to update subnet. Rolling back all changes. : {e}'
138141
)
139142

143+
def subnet_absent(self, **subnet_params):
144+
vnet_id = subnet_params['vnet']
145+
lock = subnet_params['lock-token']
146+
subnet_id = f"{self.params['zone']}-{subnet_params['subnet'].replace('/', '-')}"
147+
148+
params = {
149+
'subnet': subnet_id,
150+
'vnet': vnet_id,
151+
'lock-token': lock
152+
}
153+
154+
try:
155+
vnet = getattr(self.proxmox_api.cluster().sdn().vnets(), vnet_id)
156+
subnet = getattr(vnet().subnets(), subnet_id)
157+
subnet.delete(**params)
158+
self.apply_sdn_changes_and_release_lock(lock=lock)
159+
self.module.exit_json(
160+
changed=True, subnet=subnet_id, msg=f'Deleted subnet {subnet_id}'
161+
)
162+
except Exception as e:
163+
self.rollback_sdn_changes_and_release_lock(lock=lock)
164+
self.module.fail_json(
165+
msg=f'Failed to delete subnet. Rolling back all changes. : {e}'
166+
)
167+
140168

141169
def main():
142170
module = get_ansible_module()

0 commit comments

Comments
 (0)