Skip to content

Commit 859dd52

Browse files
authored
Merge pull request #344 from CiscoDevNet/dcnm-fabric-issue-343
dcnm_fabric: Fix for issue 343
2 parents 43d5ca5 + 95c7f62 commit 859dd52

File tree

2 files changed

+89
-6
lines changed

2 files changed

+89
-6
lines changed

plugins/module_utils/fabric/create.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
import json
2424
import logging
2525

26-
from ansible_collections.cisco.dcnm.plugins.module_utils.common.api.v1.lan_fabric.rest.control.fabrics.fabrics import \
27-
EpFabricCreate
28-
from ansible_collections.cisco.dcnm.plugins.module_utils.fabric.common import \
29-
FabricCommon
30-
from ansible_collections.cisco.dcnm.plugins.module_utils.fabric.fabric_types import \
31-
FabricTypes
26+
from ansible_collections.cisco.dcnm.plugins.module_utils.common.api.v1.lan_fabric.rest.control.fabrics.fabrics import (
27+
EpFabricCreate,
28+
)
29+
from ansible_collections.cisco.dcnm.plugins.module_utils.fabric.common import (
30+
FabricCommon,
31+
)
32+
from ansible_collections.cisco.dcnm.plugins.module_utils.fabric.fabric_types import (
33+
FabricTypes,
34+
)
3235

3336

3437
class FabricCreateCommon(FabricCommon):
@@ -112,6 +115,38 @@ def _set_fabric_create_endpoint(self, payload):
112115
self.path = self.ep_fabric_create.path
113116
self.verb = self.ep_fabric_create.verb
114117

118+
def _add_ext_fabric_type_to_payload(self, payload: dict) -> dict:
119+
"""
120+
# Summary
121+
122+
If the payload contains an external fabric type (e.g ISN)
123+
and does not contain the EXT_FABRIC_TYPE key, add this
124+
key with the default value that NDFC GUI uses for displaying
125+
the fabric type.
126+
127+
# Raises
128+
129+
None
130+
"""
131+
method_name = inspect.stack()[0][3]
132+
133+
fabric_type = payload.get("FABRIC_TYPE")
134+
if fabric_type not in self.fabric_types.external_fabric_types:
135+
return payload
136+
if "EXT_FABRIC_TYPE" in payload:
137+
return payload
138+
value = self.fabric_types.fabric_type_to_ext_fabric_type_map.get(fabric_type)
139+
if value is None:
140+
return payload
141+
payload["EXT_FABRIC_TYPE"] = value
142+
143+
msg = f"{self.class_name}.{method_name}: "
144+
msg += "Added EXT_FABRIC_TYPE to payload. "
145+
msg += f"fabric_type: {fabric_type}, "
146+
msg += f"value: {value}"
147+
self.log.debug(msg)
148+
return payload
149+
115150
def _send_payloads(self):
116151
"""
117152
- If ``check_mode`` is ``False``, send the payloads
@@ -125,6 +160,8 @@ def _send_payloads(self):
125160
- This overrides the parent class method.
126161
"""
127162
for payload in self._payloads_to_commit:
163+
payload = self._add_ext_fabric_type_to_payload(payload)
164+
128165
try:
129166
self._set_fabric_create_endpoint(payload)
130167
except ValueError as error:

plugins/module_utils/fabric/fabric_types.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,28 @@ def _init_fabric_types(self) -> None:
8888
self._fabric_type_to_feature_name_map["VXLAN_EVPN"] = "vxlan"
8989
self._fabric_type_to_feature_name_map["VXLAN_EVPN_MSD"] = "vxlan"
9090

91+
# Map fabric type to the value that the controller GUI displays
92+
# in the Fabric Type column at NDFC -> Manage -> Fabrics
93+
# This is needed only for fabrics that use the External_Fabric
94+
# template, e.g. ISN, and will be inserted into the POST request
95+
# payload for external fabrics as (in the case of ISN fabric type):
96+
# "EXT_FABRIC_TYPE": "Multi-Site External Network"
97+
#
98+
# Exposed via property fabric_type_to_ext_fabric_type_map
99+
self._fabric_type_to_ext_fabric_type_map = {}
100+
self._fabric_type_to_ext_fabric_type_map["ISN"] = "Multi-Site External Network"
101+
91102
self._valid_fabric_types = sorted(self._fabric_type_to_template_name_map.keys())
92103

104+
# self._external_fabric_types is used in conjunction with
105+
# self._fabric_type_to_ext_fabric_type_map. This is used in (at least)
106+
# FabricCreateCommon() to determine if EXT_FABRIC_TYPE key needs to be
107+
# added to a payload.
108+
#
109+
# Exposed via property external_fabric_types
110+
self._external_fabric_types = set()
111+
self._external_fabric_types.add("ISN")
112+
93113
self._mandatory_parameters_all_fabrics = []
94114
self._mandatory_parameters_all_fabrics.append("FABRIC_NAME")
95115
self._mandatory_parameters_all_fabrics.append("FABRIC_TYPE")
@@ -128,6 +148,19 @@ def _init_properties(self) -> None:
128148
self._properties["template_name"] = None
129149
self._properties["valid_fabric_types"] = self._valid_fabric_types
130150

151+
@property
152+
def external_fabric_types(self):
153+
"""
154+
# Summary
155+
156+
set() containing all external fabric types e.g. ISN.
157+
158+
# Raises
159+
160+
None
161+
"""
162+
return self._external_fabric_types
163+
131164
@property
132165
def fabric_type(self):
133166
"""
@@ -150,6 +183,19 @@ def fabric_type(self, value):
150183
raise ValueError(msg)
151184
self._properties["fabric_type"] = value
152185

186+
@property
187+
def fabric_type_to_ext_fabric_type_map(self):
188+
"""
189+
# Summary
190+
191+
Returns a dictionary, keyed on fabric_type (e.g. "ISN"),
192+
whose value is a string that the NDFC GUI uses to describe the
193+
external fabric type. See the Fabric Type column at
194+
NDFC -> Manage -> Fabrics for an example of how this is used
195+
by the NDFC GUI.
196+
"""
197+
return self._fabric_type_to_ext_fabric_type_map
198+
153199
@property
154200
def feature_name(self):
155201
"""

0 commit comments

Comments
 (0)