Skip to content

Commit 9dc2ed0

Browse files
authored
Fix to override only specified interface types instead of all types of interfaces (#298)
1 parent 8574383 commit 9dc2ed0

File tree

8 files changed

+1717
-233
lines changed

8 files changed

+1717
-233
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ This collection is intended for use with the following release versions:
1414

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

17-
For collections that support Ansible 2.9, please ensure you update your `network_os` to use the
18-
fully qualified collection name (for example, `cisco.ios.ios`).
1917
Plugins and modules within a collection may be tested with only specific Ansible versions.
2018
A collection may contain metadata that identifies these versions.
2119
PEP440 is the schema used to describe the versions of Ansible.

docs/cisco.dcnm.dcnm_interface_module.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,33 @@ Parameters
24852485
<div>Name of the target fabric for interface operations</div>
24862486
</td>
24872487
</tr>
2488+
<tr>
2489+
<td colspan="3">
2490+
<div class="ansibleOptionAnchor" id="parameter-"></div>
2491+
<b>override_intf_types</b>
2492+
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
2493+
<div style="font-size: small">
2494+
<span style="color: purple">list</span>
2495+
/ <span style="color: purple">elements=string</span>
2496+
</div>
2497+
</td>
2498+
<td>
2499+
<ul style="margin: 0; padding: 0"><b>Choices:</b>
2500+
<li>pc</li>
2501+
<li>vpc</li>
2502+
<li>sub_int</li>
2503+
<li>lo</li>
2504+
<li>eth</li>
2505+
<li>svi</li>
2506+
<li>st_fex</li>
2507+
<li>aa_fex</li>
2508+
</ul>
2509+
<b>Default:</b><br/><div style="color: blue">[]</div>
2510+
</td>
2511+
<td>
2512+
<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>
2513+
</td>
2514+
</tr>
24882515
<tr>
24892516
<td colspan="3">
24902517
<div class="ansibleOptionAnchor" id="parameter-"></div>

plugins/modules/dcnm_interface.py

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@
6161
over this global flag.
6262
type: bool
6363
default: true
64+
override_intf_types:
65+
description:
66+
- A list of interface types which will be deleted/defaulted in overridden/deleted state. If this list is empty, then during
67+
overridden/deleted state, all interface types will be defaulted/deleted. If this list includes specific interface types,
68+
then only those interface types that are included in the list will be deleted/defaulted.
69+
type: list
70+
required: false
71+
elements: str
72+
choices: ["pc", "vpc", "sub_int", "lo", "eth", "svi", "st_fex", "aa_fex"]
73+
default: []
6474
config:
6575
description:
6676
- A dictionary of interface operations
@@ -3978,6 +3988,7 @@ def dcnm_intf_get_diff_overridden(self, cfg):
39783988
# the given switch may be part of a VPC pair. In that case we
39793989
# need to get interface information using one switch which returns interfaces
39803990
# from both the switches
3991+
39813992
if not any(
39823993
d.get("serialNo", None) == self.ip_sn[address]
39833994
for d in self.have_all
@@ -4006,6 +4017,27 @@ def dcnm_intf_get_diff_overridden(self, cfg):
40064017
sno = have["serialNo"]
40074018
fabric = have["fabricName"]
40084019

4020+
# Check if this interface type is to be overridden.
4021+
if self.module.params["override_intf_types"] != []:
4022+
# Check if it is SUBINTERFACE. For sub-interfaces ifType will be retuened as INTERFACE_ETHERNET. So
4023+
# for such interfaces, check if SUBINTERFACE is included in override list instead of have['ifType']
4024+
if (have["ifType"] == "INTERFACE_ETHERNET") and (
4025+
(str(have["isPhysical"]).lower() == "none")
4026+
or (str(have["isPhysical"]).lower() == "false")
4027+
):
4028+
# This is a SUBINTERFACE.
4029+
if (
4030+
"SUBINTERFACE"
4031+
not in self.module.params["override_intf_types"]
4032+
):
4033+
continue
4034+
else:
4035+
if (
4036+
have["ifType"]
4037+
not in self.module.params["override_intf_types"]
4038+
):
4039+
continue
4040+
40094041
if (have["ifType"] == "INTERFACE_ETHERNET") and (
40104042
(str(have["isPhysical"]).lower() != "none")
40114043
and (str(have["isPhysical"]).lower() == "true")
@@ -4217,8 +4249,11 @@ def dcnm_intf_get_diff_overridden(self, cfg):
42174249
delem["serialNumber"] = sno
42184250
delem["ifName"] = intf["ifName"]
42194251
delem["fabricName"] = self.fabric
4220-
self.diff_deploy.append(delem)
4221-
self.changed_dict[0]["deploy"].append(copy.deepcopy(delem))
4252+
4253+
# Deploy only if requested for
4254+
if str(deploy).lower() == "true":
4255+
self.diff_deploy.append(delem)
4256+
self.changed_dict[0]["deploy"].append(copy.deepcopy(delem))
42224257

42234258
self.dcnm_intf_compare_want_and_have("overridden")
42244259

@@ -4843,7 +4878,7 @@ def dcnm_intf_send_message_to_dcnm(self):
48434878
self.module.params["state"] == "deleted"
48444879
):
48454880
self.result["changed"] = (
4846-
delete or create or deploy or delete_deploy
4881+
delete or create or replace or deploy or delete_deploy
48474882
)
48484883
else:
48494884
if delete or create or replace or deploy or delete_deploy:
@@ -4865,6 +4900,7 @@ def dcnm_intf_update_inventory_data(self):
48654900
"""
48664901

48674902
inv_data = get_fabric_inventory_details(self.module, self.fabric)
4903+
48684904
self.inventory_data.update(inv_data)
48694905

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

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

4977+
# Transalte override_intf_types to proper types that can be directly used in overridden state.
4978+
4979+
for if_type in self.module.params["override_intf_types"][:]:
4980+
self.module.params["override_intf_types"].append(
4981+
self.int_types[if_type]
4982+
)
4983+
self.module.params["override_intf_types"].remove(if_type)
49414984
for cfg in config:
49424985
index = 0
49434986
if cfg.get("switch", None) is None:
@@ -4972,6 +5015,22 @@ def main():
49725015
default="merged",
49735016
choices=["merged", "replaced", "overridden", "deleted", "query"],
49745017
),
5018+
override_intf_types=dict(
5019+
required=False,
5020+
type="list",
5021+
elements="str",
5022+
choices=[
5023+
"pc",
5024+
"vpc",
5025+
"sub_int",
5026+
"lo",
5027+
"eth",
5028+
"svi",
5029+
"st_fex",
5030+
"aa_fex",
5031+
],
5032+
default=[],
5033+
),
49755034
check_deploy=dict(type="bool", default=False),
49765035
)
49775036

0 commit comments

Comments
 (0)