Skip to content

Commit 17f2b7c

Browse files
committed
[ignore] Moved get_site_interface_details from utils to mso.py and updated ndo_fabric_span_session task names
1 parent 7ec86ea commit 17f2b7c

File tree

5 files changed

+86
-89
lines changed

5 files changed

+86
-89
lines changed

plugins/module_utils/mso.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,28 @@ def verify_time_format(self, date_time):
16661666
except ValueError:
16671667
return self.fail_json(msg="ERROR: The time must be in 'YYYY-MM-DD HH:MM:SS' format.")
16681668

1669+
def get_site_interface_details(self, site_id=None, uuid=None, node=None, port=None):
1670+
if node and port:
1671+
path = "/sitephysifsummary/site/{0}?node={1}".format(site_id, node)
1672+
elif uuid:
1673+
path = "/sitephysifsummary/site/{0}?uuid={1}".format(site_id, uuid)
1674+
1675+
site_data = self.request(path, method="GET")
1676+
1677+
if uuid:
1678+
if site_data.get("spec", {}).get("monitoringTemplateInterfaces"):
1679+
return site_data.get("spec", {}).get("monitoringTemplateInterfaces", [])[0]
1680+
else:
1681+
self.fail_json(msg="The site port interface not found. Site ID: {0} and UUID: {1}".format(site_id, uuid))
1682+
elif node and port:
1683+
for interface in site_data.get("spec", {}).get("interfaces", []):
1684+
# To ensure consistency between the API response data and the input data by converting the node to a string
1685+
if interface.get("port") == port and str(interface.get("node")) == str(node):
1686+
return interface
1687+
self.fail_json(msg="The site port interface not found. Site ID: {0}, Node: {1} and Path: {2}".format(site_id, node, port))
1688+
1689+
return {}
1690+
16691691

16701692
def service_node_ref_str_to_dict(serviceNodeRefStr):
16711693
serviceNodeRefTokens = serviceNodeRefStr.split("/")

plugins/module_utils/schemas.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,22 @@ def get_template_from_schema(self, schema_name, schema_id, template_name, templa
3131
self.schemas_by_id[new_schema.id] = new_schema
3232
self.schemas_by_name[new_schema.schema_name] = new_schema
3333
return new_schema
34+
35+
def get_epg_uuid(self, epg_obj, epg_uuid):
36+
"""
37+
Returns the EPG UUID in a given schema, template and ANP.
38+
:param epg_obj: A dictionary containing the epg reference object. -> Dict
39+
:param epg_uuid: The EPG UUID to return if specified. -> Str
40+
:return: The EPG UUID if found, otherwise it fails the module. -> Str
41+
"""
42+
if epg_uuid:
43+
return epg_uuid
44+
schema = self.get_template_from_schema(
45+
epg_obj.get("schema"),
46+
epg_obj.get("schema_id"),
47+
epg_obj.get("template"),
48+
epg_obj.get("template_id"),
49+
)
50+
schema.set_template_anp(epg_obj.get("anp"), epg_obj.get("anp_uuid"), fail_module=True)
51+
schema.set_template_anp_epg(epg_obj.get("name"), fail_module=True)
52+
return schema.schema_objects.get("template_anp_epg").details.get("uuid")

plugins/module_utils/utils.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -164,47 +164,3 @@ def snake_to_camel(snake_str, upper_case_components=None):
164164
return camel_case_str
165165
else:
166166
return snake_str
167-
168-
169-
def get_epg_uuid(schemas, epg_obj, epg_uuid):
170-
"""
171-
Returns the EPG UUID in a given schema, template and ANP.
172-
:param schemas: The mso schemas object. -> MSOSchemas
173-
:param epg_obj: A dictionary containing the epg reference object. -> Dict
174-
:param epg_uuid: The EPG UUID to return if specified. -> Str
175-
:return: The EPG UUID if found, otherwise it fails the module. -> Str
176-
"""
177-
if epg_uuid:
178-
return epg_uuid
179-
schema = schemas.get_template_from_schema(
180-
epg_obj.get("schema"),
181-
epg_obj.get("schema_id"),
182-
epg_obj.get("template"),
183-
epg_obj.get("template_id"),
184-
)
185-
schema.set_template_anp(epg_obj.get("anp"), epg_obj.get("anp_uuid"), fail_module=True)
186-
schema.set_template_anp_epg(epg_obj.get("name"), fail_module=True)
187-
return schema.schema_objects.get("template_anp_epg").details.get("uuid")
188-
189-
190-
def get_site_interface_details(mso, site_id=None, uuid=None, node=None, port=None):
191-
if node and port:
192-
path = "/sitephysifsummary/site/{0}?node={1}".format(site_id, node)
193-
elif uuid:
194-
path = "/sitephysifsummary/site/{0}?uuid={1}".format(site_id, uuid)
195-
196-
site_data = mso.request(path, method="GET")
197-
198-
if uuid:
199-
if site_data.get("spec", {}).get("monitoringTemplateInterfaces"):
200-
return site_data.get("spec", {}).get("monitoringTemplateInterfaces", [])[0]
201-
else:
202-
mso.fail_json(msg="The site port interface not found. Site ID: {0} and UUID: {1}".format(site_id, uuid))
203-
elif node and port:
204-
for interface in site_data.get("spec", {}).get("interfaces", []):
205-
# To ensure consistency between the API response data and the input data by converting the node to a string
206-
if interface.get("port") == port and str(interface.get("node")) == str(node):
207-
return interface
208-
mso.fail_json(msg="The site port interface not found. Site ID: {0}, Node: {1} and Path: {2}".format(site_id, node, port))
209-
210-
return {}

plugins/modules/ndo_fabric_span_session.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
type: str
229229
template_id:
230230
description:
231-
- The ID of the that contains the destination port channel.
231+
- The ID of the template that contains the destination port channel.
232232
- This parameter or O(destination_port_channel.port_channel.template) is required.
233233
type: str
234234
state:
@@ -408,7 +408,7 @@
408408
from ansible_collections.cisco.mso.plugins.module_utils.templates import MSOTemplates
409409
from ansible_collections.cisco.mso.plugins.module_utils.template import MSOTemplate, KVPair
410410
from ansible_collections.cisco.mso.plugins.module_utils.constants import TARGET_DSCP_MAP, ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP
411-
from ansible_collections.cisco.mso.plugins.module_utils.utils import append_update_ops_data, get_site_interface_details, get_epg_uuid
411+
from ansible_collections.cisco.mso.plugins.module_utils.utils import append_update_ops_data
412412
import copy
413413

414414

@@ -521,7 +521,7 @@ def main():
521521

522522
mso_template = MSOTemplate(mso, "monitoring_tenant", template_name, template_id)
523523
mso_template.validate_template("monitoring")
524-
object_description = "SPAN Session "
524+
object_description = "SPAN Session"
525525
site_id = mso_template.template.get("monitoringTemplate").get("sites")[0].get("siteId")
526526

527527
match = None
@@ -553,7 +553,7 @@ def main():
553553
if destination_epg:
554554
mso_values["destination"] = dict(
555555
remote=dict(
556-
epgRef=get_epg_uuid(mso_schemas, destination_epg.get("epg"), destination_epg.get("epg_uuid")),
556+
epgRef=mso_schemas.get_epg_uuid(destination_epg.get("epg"), destination_epg.get("epg_uuid")),
557557
spanVersion=destination_epg.get("span_version"),
558558
enforceSpanVersion=destination_epg.get("enforce_span_version"),
559559
destIPAddress=destination_epg.get("destination_ip"),
@@ -572,7 +572,7 @@ def main():
572572
if destination_port_uuid is None:
573573
node = destination_port.get("port").get("node")
574574
interface_port = destination_port.get("port").get("path")
575-
destination_port_uuid = get_site_interface_details(mso, site_id=site_id, uuid=None, node=node, port=interface_port).get("uuid")
575+
destination_port_uuid = mso.get_site_interface_details(site_id=site_id, uuid=None, node=node, port=interface_port).get("uuid")
576576
mso_values["destination"] = dict(local=dict(accessInterface=destination_port_uuid), mtu=mtu)
577577

578578
if destination_port_channel:
@@ -671,7 +671,7 @@ def set_fabric_span_session_object_details(mso_template, site_id, span_session):
671671
if span_session:
672672
span_session.update({"templateId": mso_template.template_id, "templateName": mso_template.template_name})
673673
if span_session.get("destination", {}).get("local", {}).get("accessInterface"):
674-
interface = get_site_interface_details(mso_template.mso, site_id, span_session.get("destination").get("local").get("accessInterface"))
674+
interface = mso_template.mso.get_site_interface_details(site_id, span_session.get("destination").get("local").get("accessInterface"))
675675
interface.pop("uuid", None)
676676
span_session.get("destination").get("local").update(interface)
677677
else:

0 commit comments

Comments
 (0)