Skip to content

Commit

Permalink
Merge pull request #442 from MUTHU-RAKESH-27/main
Browse files Browse the repository at this point in the history
Tested the L2 Handoff and L3 Handoff with SDA Transit
  • Loading branch information
madhansansel authored Oct 23, 2024
2 parents 76643af + 36afef3 commit 6651dc7
Showing 1 changed file with 81 additions and 19 deletions.
100 changes: 81 additions & 19 deletions plugins/modules/sda_fabric_devices_workflow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ def l2_handoff_exists(self, fabric_id, device_id, internal_vlan_id, interface_na

if not isinstance(all_l2_handoff_details, dict):
self.msg = "Failed to retrieve the L2 Handoff details - Response is not a dictionary"
self.log(self.msg, "CRITICAL")
self.log(str(self.msg), "CRITICAL")
self.status = "failed"
return self.check_return_status()

Expand All @@ -1477,10 +1477,12 @@ def l2_handoff_exists(self, fabric_id, device_id, internal_vlan_id, interface_na
)
break

l2_handoff_details = next(item for item in all_l2_handoff_details
if item.get("internalVlanId") == internal_vlan_id and
item.get("interfaceName") == interface_name)
l2_handoff_details = get_dict_result(all_l2_handoff_details, "internalVlanId", internal_vlan_id)
l2_handoff_details = None
for item in all_l2_handoff_details:
if item.get("internalVlanId") == internal_vlan_id and item.get("interfaceName") == interface_name:
l2_handoff_details = item
break

if l2_handoff_details:
self.log(
"The L2 handoff details with the internal VLAN Id: {details}"
Expand Down Expand Up @@ -1862,7 +1864,7 @@ def process_layer2_handoff(self, fabric_devices_info, layer2_handoff, fabric_sit
network_device_id,
internal_vlan_id,
interface_name)
fabric_devices_info.get("l2_handoff_ids").append(l2_handoff_id)
fabric_devices_info.get("l2_handoff_details").append(l2_handoff_id)

self.log("Successfully proccessed the L2 Handoff information.", "DEBUG")
return fabric_devices_info
Expand Down Expand Up @@ -2046,7 +2048,7 @@ def get_have_fabric_devices(self, fabric_devices):
fabric_devices_info = {
"exists": False,
"device_details": None,
"l2_handoff_ids": [],
"l2_handoff_details": [],
"sda_l3_handoff_details": None,
"ip_l3_handoff_details": [],
"id": None,
Expand Down Expand Up @@ -2605,6 +2607,57 @@ def validate_vlan_fields(self, internal_vlan_id, external_vlan_id, device_ip):

return None

def check_transit_type(self, transit_id):
"""
Check whether the given transit id is LISP/PUB SUB or LISP/BGP.
Parameters:
transit_id (str): The id of the transit network.
Returns:
is_transit_pub_sub (bool): Returns True, if the transit type is 'SDA_LISP_PUB_SUB_TRANSIT'. Else, False.
Description:
Calls the 'get_transit_networks' API by setting the 'id' and 'type' fields
with the given transit id and 'SDA_LISP_PUB_SUB_TRANSIT'.
If the response is valid, fetch the Id and return True, otherwise False.
"""

self.log("Fetching transit type for transit ID: '{id}'".format(id=transit_id), "DEBUG")
is_transit_pub_sub = False
try:
transit_details = self.dnac._exec(
family="sda",
function="get_transit_networks",
params={
"id": transit_id,
"type": "SDA_LISP_PUB_SUB_TRANSIT"
},
)

# If the SDK returns no response, then the transit doesnot exist with type 'SDA_LISP_PUB_SUB_TRANSIT'
transit_details = transit_details.get("response")
if not transit_details:
self.log(
"There is no transit network with the id '{id}' with transit type 'SDA_LISP_PUB_SUB_TRANSIT'."
.format(id=transit_id), "DEBUG"
)
return is_transit_pub_sub

self.log(
"Transit network found with ID: '{id}' and type 'SDA_LISP_PUB_SUB_TRANSIT'."
.format(id=transit_id), "DEBUG"
)
is_transit_pub_sub = True
except Exception as msg:
self.msg = (
"Exception occured while running the API 'get_transit_networks': {msg}"
.format(msg=msg)
)
self.log(self.msg, "CRITICAL")
self.status = "failed"
return self.check_return_status()

return is_transit_pub_sub

def get_l2_handoff_params(self, fabric_id, network_id, device_details, device_config_index):
"""
Get the L2 Handoff of the SDA fabric devices information from playbook.
Expand Down Expand Up @@ -2764,20 +2817,26 @@ def get_sda_l3_handoff_params(self, fabric_id, network_id, device_details, devic
"Transit ID for the transit name {name}: {id}"
.format(name=transit_name, id=transit_id)
)

is_transit_pub_sub = self.check_transit_type(transit_id)
self.log(
"The transit type is 'LISP/PUB SUB': {is_transit_pub_sub}"
.format(is_transit_pub_sub=is_transit_pub_sub)
)
connected_to_internet = layer3_handoff_sda_transit.get("connected_to_internet")
if not connected_to_internet:
if connected_to_internet is None:
if is_sda_l3_handoff_exists:
connected_to_internet = have_sda_l3_handoff.get("connectedToInternet")
else:
connected_to_internet = False

self.log(
"Connected to internet for device IP {device_ip}: {connected_to_internet}"
.format(device_ip=device_ip, connected_to_internet=connected_to_internet), "DEBUG"
)
self.log(
"Connected to internet for device IP {device_ip}: {connected_to_internet}"
.format(device_ip=device_ip, connected_to_internet=connected_to_internet), "DEBUG"
)

is_multicast_over_transit_enabled = layer3_handoff_sda_transit.get("is_multicast_over_transit_enabled")
if not is_multicast_over_transit_enabled:
if is_multicast_over_transit_enabled is None:
if is_sda_l3_handoff_exists:
is_multicast_over_transit_enabled = have_sda_l3_handoff.get("isMulticastOverTransitEnabled")
else:
Expand Down Expand Up @@ -2860,13 +2919,17 @@ def get_sda_l3_handoff_params(self, fabric_id, network_id, device_details, devic
return self.check_return_status()

sda_l3_handoff_info.update({
"interfaceName": transit_id,
"affinityIdPrime": affinity_id_prime,
"affinityIdDecider": affinity_id_decider,
"transitNetworkId": transit_id,
"connectedToInternet": connected_to_internet,
"isMulticastOverTransitEnabled": is_multicast_over_transit_enabled,
})

if is_transit_pub_sub:
sda_l3_handoff_info.update({
"affinityIdPrime": affinity_id_prime,
"affinityIdDecider": affinity_id_decider,
"isMulticastOverTransitEnabled": is_multicast_over_transit_enabled,
})

self.log(
"Successfully retrieved L3 handoff parameters for device IP: {device_ip}"
.format(device_ip=device_ip)
Expand Down Expand Up @@ -4003,8 +4066,7 @@ def delete_l2_handoff(self, have_l2_handoff, device_ip,
"Non-existing L2 Handoffs: {non_existing_list}"
.format(non_existing_list=non_existing_l2_handoff), "DEBUG"
)
for item in delete_l2_handoff:
id = item.get("id")
for id in delete_l2_handoff:
try:
payload = {"id": id}
task_name = "delete_fabric_device_layer2_handoff_by_id"
Expand Down

0 comments on commit 6651dc7

Please sign in to comment.