diff --git a/plugins/modules/dcnm_vrf.py b/plugins/modules/dcnm_vrf.py index 6133a0924..bf708d25b 100644 --- a/plugins/modules/dcnm_vrf.py +++ b/plugins/modules/dcnm_vrf.py @@ -3661,7 +3661,7 @@ def release_resources_by_id(self, id_list=None): verb = "DELETE" self.send_to_controller(action, verb, path, None, log_response=False) - def release_orphaned_resources(self, vrf, is_rollback=False): + def release_orphaned_resources(self, vrf_del_list, is_rollback=False): """ # Summary @@ -3677,6 +3677,8 @@ def release_orphaned_resources(self, vrf, is_rollback=False): - allocatedFlag is False - entityName == vrf - fabricName == self.fabric + - switchName is not None + - ipAddress is not None ```json [ @@ -3724,12 +3726,19 @@ def release_orphaned_resources(self, vrf, is_rollback=False): for item in resp["DATA"]: if "entityName" not in item: continue - if item["entityName"] != vrf: + if item["entityName"] not in vrf_del_list: continue if item.get("allocatedFlag") is not False: continue if item.get("id") is None: continue + # Resources with no ipAddress or switchName + # are invalid and of Fabric's scope and + # should not be attempted to be deleted here. + if not item.get("ipAddress"): + continue + if not item.get("switchName"): + continue msg = f"item {json.dumps(item, indent=4, sort_keys=True)}" self.log.debug(msg) @@ -3738,6 +3747,8 @@ def release_orphaned_resources(self, vrf, is_rollback=False): if len(delete_ids) == 0: return + msg = f"Releasing orphaned resources with IDs:{delete_ids}" + self.log.debug(msg) self.release_resources_by_id(delete_ids) def push_to_remote(self, is_rollback=False): @@ -3765,8 +3776,13 @@ def push_to_remote(self, is_rollback=False): self.log.debug(msg) self.push_diff_delete(is_rollback) + + vrf_del_list = [] for vrf_name in self.diff_delete: - self.release_orphaned_resources(vrf_name, is_rollback) + vrf_del_list.append(vrf_name) + if vrf_del_list: + msg += f"VRF(s) to be deleted: {vrf_del_list}." + self.release_orphaned_resources(vrf_del_list, is_rollback) self.push_diff_create(is_rollback) self.push_diff_attach(is_rollback)