Skip to content

Commit

Permalink
Fix to override only specified interface types instead of all types o…
Browse files Browse the repository at this point in the history
…f interfaces (#298)
  • Loading branch information
mmudigon committed Jul 30, 2024
1 parent 8574383 commit 9dc2ed0
Show file tree
Hide file tree
Showing 8 changed files with 1,717 additions and 233 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ This collection is intended for use with the following release versions:

This collection has been tested against following Ansible versions: **>=2.9.10**.

For collections that support Ansible 2.9, please ensure you update your `network_os` to use the
fully qualified collection name (for example, `cisco.ios.ios`).
Plugins and modules within a collection may be tested with only specific Ansible versions.
A collection may contain metadata that identifies these versions.
PEP440 is the schema used to describe the versions of Ansible.
Expand Down
27 changes: 27 additions & 0 deletions docs/cisco.dcnm.dcnm_interface_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,33 @@ Parameters
<div>Name of the target fabric for interface operations</div>
</td>
</tr>
<tr>
<td colspan="3">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>override_intf_types</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">list</span>
/ <span style="color: purple">elements=string</span>
</div>
</td>
<td>
<ul style="margin: 0; padding: 0"><b>Choices:</b>
<li>pc</li>
<li>vpc</li>
<li>sub_int</li>
<li>lo</li>
<li>eth</li>
<li>svi</li>
<li>st_fex</li>
<li>aa_fex</li>
</ul>
<b>Default:</b><br/><div style="color: blue">[]</div>
</td>
<td>
<div>A list of interface types which will be deleted/defaulted in overridden/deleted state. If this list is empty, then during overridden/deleted state, all interface types will be defaulted/deleted. If this list includes specific interface types, then only those interface types that are included in the list will be deleted/defaulted.</div>
</td>
</tr>
<tr>
<td colspan="3">
<div class="ansibleOptionAnchor" id="parameter-"></div>
Expand Down
65 changes: 62 additions & 3 deletions plugins/modules/dcnm_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@
over this global flag.
type: bool
default: true
override_intf_types:
description:
- A list of interface types which will be deleted/defaulted in overridden/deleted state. If this list is empty, then during
overridden/deleted state, all interface types will be defaulted/deleted. If this list includes specific interface types,
then only those interface types that are included in the list will be deleted/defaulted.
type: list
required: false
elements: str
choices: ["pc", "vpc", "sub_int", "lo", "eth", "svi", "st_fex", "aa_fex"]
default: []
config:
description:
- A dictionary of interface operations
Expand Down Expand Up @@ -3978,6 +3988,7 @@ def dcnm_intf_get_diff_overridden(self, cfg):
# the given switch may be part of a VPC pair. In that case we
# need to get interface information using one switch which returns interfaces
# from both the switches

if not any(
d.get("serialNo", None) == self.ip_sn[address]
for d in self.have_all
Expand Down Expand Up @@ -4006,6 +4017,27 @@ def dcnm_intf_get_diff_overridden(self, cfg):
sno = have["serialNo"]
fabric = have["fabricName"]

# Check if this interface type is to be overridden.
if self.module.params["override_intf_types"] != []:
# Check if it is SUBINTERFACE. For sub-interfaces ifType will be retuened as INTERFACE_ETHERNET. So
# for such interfaces, check if SUBINTERFACE is included in override list instead of have['ifType']
if (have["ifType"] == "INTERFACE_ETHERNET") and (
(str(have["isPhysical"]).lower() == "none")
or (str(have["isPhysical"]).lower() == "false")
):
# This is a SUBINTERFACE.
if (
"SUBINTERFACE"
not in self.module.params["override_intf_types"]
):
continue
else:
if (
have["ifType"]
not in self.module.params["override_intf_types"]
):
continue

if (have["ifType"] == "INTERFACE_ETHERNET") and (
(str(have["isPhysical"]).lower() != "none")
and (str(have["isPhysical"]).lower() == "true")
Expand Down Expand Up @@ -4217,8 +4249,11 @@ def dcnm_intf_get_diff_overridden(self, cfg):
delem["serialNumber"] = sno
delem["ifName"] = intf["ifName"]
delem["fabricName"] = self.fabric
self.diff_deploy.append(delem)
self.changed_dict[0]["deploy"].append(copy.deepcopy(delem))

# Deploy only if requested for
if str(deploy).lower() == "true":
self.diff_deploy.append(delem)
self.changed_dict[0]["deploy"].append(copy.deepcopy(delem))

self.dcnm_intf_compare_want_and_have("overridden")

Expand Down Expand Up @@ -4843,7 +4878,7 @@ def dcnm_intf_send_message_to_dcnm(self):
self.module.params["state"] == "deleted"
):
self.result["changed"] = (
delete or create or deploy or delete_deploy
delete or create or replace or deploy or delete_deploy
)
else:
if delete or create or replace or deploy or delete_deploy:
Expand All @@ -4865,6 +4900,7 @@ def dcnm_intf_update_inventory_data(self):
"""

inv_data = get_fabric_inventory_details(self.module, self.fabric)

self.inventory_data.update(inv_data)

if self.module.params["state"] != "query":
Expand Down Expand Up @@ -4938,6 +4974,13 @@ def dcnm_intf_update_inventory_data(self):

def dcnm_translate_playbook_info(self, config, ip_sn, hn_sn):

# Transalte override_intf_types to proper types that can be directly used in overridden state.

for if_type in self.module.params["override_intf_types"][:]:
self.module.params["override_intf_types"].append(
self.int_types[if_type]
)
self.module.params["override_intf_types"].remove(if_type)
for cfg in config:
index = 0
if cfg.get("switch", None) is None:
Expand Down Expand Up @@ -4972,6 +5015,22 @@ def main():
default="merged",
choices=["merged", "replaced", "overridden", "deleted", "query"],
),
override_intf_types=dict(
required=False,
type="list",
elements="str",
choices=[
"pc",
"vpc",
"sub_int",
"lo",
"eth",
"svi",
"st_fex",
"aa_fex",
],
default=[],
),
check_deploy=dict(type="bool", default=False),
)

Expand Down
Loading

0 comments on commit 9dc2ed0

Please sign in to comment.