@@ -247,7 +247,7 @@ def get_subnets(self, vnet_name):
247
247
try :
248
248
return self .proxmox_api .cluster ().sdn ().vnets (vnet_name ).subnets ().get ()
249
249
except Exception as e :
250
- self .module .fail_json (f'Failed to retrieve subnet isubnet_paramsnfo { e } ' )
250
+ self .module .fail_json (f'Failed to retrieve subnets { e } ' )
251
251
252
252
def update_subnet (self , ** subnet_params ):
253
253
new_subnet = copy .deepcopy (subnet_params )
@@ -357,15 +357,14 @@ def subnet_present(self, **subnet_params):
357
357
subnet_id = f"{ self .params ['zone' ]} -{ subnet_params ['subnet' ].replace ('/' , '-' )} "
358
358
359
359
try :
360
- vnet = getattr (self .proxmox_api .cluster ().sdn ().vnets (), vnet_name )
361
360
existing_subnets = self .get_subnets (vnet_name )
362
361
363
362
# Check if subnet already present
364
363
if subnet_id in [x ['subnet' ] for x in existing_subnets ]:
365
364
self .update_subnet (** subnet_params )
366
365
else :
367
366
subnet_params ['lock-token' ] = self .get_global_sdn_lock ()
368
- vnet .subnets ().post (** subnet_params )
367
+ self . proxmox_api . cluster (). sdn (). vnets ( vnet_name ) .subnets ().post (** subnet_params )
369
368
self .apply_sdn_changes_and_release_lock (lock = subnet_params ['lock-token' ])
370
369
self .module .exit_json (
371
370
changed = True , subnet = subnet_id , msg = f'Created new subnet { subnet_cidr } '
@@ -377,22 +376,21 @@ def subnet_present(self, **subnet_params):
377
376
)
378
377
379
378
def subnet_absent (self , ** subnet_params ):
380
- vnet_id = subnet_params ['vnet' ]
379
+ vnet_name = subnet_params ['vnet' ]
381
380
subnet_id = f"{ self .params ['zone' ]} -{ subnet_params ['subnet' ].replace ('/' , '-' )} "
382
381
383
382
params = {
384
383
'subnet' : subnet_id ,
385
- 'vnet' : vnet_id ,
384
+ 'vnet' : vnet_name ,
386
385
'lock-token' : None
387
386
}
388
387
388
+ existing_subnets = self .get_subnets (vnet_name )
389
389
try :
390
- vnet = getattr (self .proxmox_api .cluster ().sdn ().vnets (), vnet_id )
391
-
392
390
# Check if subnet already present
393
- if subnet_id in [x ['subnet' ] for x in vnet (). subnets (). get () ]:
391
+ if subnet_id in [x ['subnet' ] for x in existing_subnets ]:
394
392
params ['lock-token' ] = self .get_global_sdn_lock ()
395
- vnet ( ).subnets (subnet_id ).delete (** params )
393
+ self . proxmox_api . cluster (). sdn (). vnets ( vnet_name ).subnets (subnet_id ).delete (** params )
396
394
self .apply_sdn_changes_and_release_lock (lock = params ['lock-token' ])
397
395
self .module .exit_json (
398
396
changed = True , subnet = subnet_id , msg = f'Deleted subnet { subnet_id } '
0 commit comments