Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASMNET-2183 RVR NMN Support #466

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updates to nmn_rvr vlan
  • Loading branch information
lukebates123 authored and rustydb committed Nov 14, 2024
commit 4c31b45d64ab5bddfd9aeaff121d26b09d1db8b7
1 change: 0 additions & 1 deletion canu/generate/network/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
)
from canu.style import Style
from canu.utils.cache import cache_directory
from canu.utils.validate_node_list import validate_node_list
from canu.validate.paddle.paddle import node_model_from_paddle
from canu.validate.shcd.shcd import node_model_from_shcd, shcd_to_sheets

Expand Down
118 changes: 86 additions & 32 deletions canu/generate/switch/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,23 +577,47 @@ def add_custom_config(custom_config, switch_config, host, switch_os, custom_file
return custom_config_merge


def get_rack_vlans(sls_variables, rack_vlans, destination_rack_list, switch_name):
"""Get list of VLANs based on rack."""
rack_vlans_list = []
for cabinets in sls_variables[rack_vlans]:
ip_address = netaddr.IPNetwork(cabinets["CIDR"])
is_primary = switch_is_primary(switch_name)
sls_rack_int = int(re.search(r"\d+", cabinets["Name"])[0])

if sls_rack_int in destination_rack_list:
cabinet_info = cabinets.copy()
cabinet_info["PREFIX_LENGTH"] = ip_address.prefixlen
cabinet_info["IP"] = (
str(ip_address[2]) if is_primary[0] else str(ip_address[3])
)
rack_vlans_list.append(cabinet_info)
def vlan_check(dictionary):
"""Check VLANs in a nested dictionary for correct range and duplicates."""
vlan_list = []

def search_keys(current_dict):
for key, value in current_dict.items():
if isinstance(value, dict):
search_keys(value)
elif isinstance(value, list):
for item in value:
if isinstance(item, dict):
search_keys(item)
elif isinstance(key, str) and "vlan" in key.lower() and value is not None:
vlan_list.append(value)

search_keys(dictionary)

def has_duplicates(lst):
seen = set()
duplicates = set()
for item in lst:
if item in seen:
duplicates.add(item)
else:
seen.add(item)
return list(duplicates)

def range_check(lst):
vlan_range = []
for vlan in lst:
if (
vlan is not None and 1 <= vlan <= 4040
): # 4040 is max VLAN aruba allows to be configured
continue
else:
vlan_range.append(vlan)
return vlan_range

return rack_vlans_list
dupe_vlan = has_duplicates(vlan_list)
range_vlan = range_check(vlan_list)
return dupe_vlan, range_vlan


def generate_switch_config(
Expand Down Expand Up @@ -711,10 +735,14 @@ def generate_switch_config(
)
exit(1)
river_nmn = None
black_hole_vlan_1 = 4001
black_hole_vlan_2 = 4002
if custom_config:
custom_config_file = os.path.basename(custom_config)
custom_config = load_yaml(custom_config)
river_nmn = validate_node_list(custom_config.get("river_nmn"))
black_hole_vlan_1 = custom_config.get("black_hole_vlan_1")
black_hole_vlan_2 = custom_config.get("black_hole_vlan_2")

is_primary, primary, secondary = switch_is_primary(switch_name)

Expand Down Expand Up @@ -773,9 +801,6 @@ def vsx_mac(switch_name):
)
sys.exit(1)

black_hole_vlan_1 = 4900
black_hole_vlan_2 = 4901

variables = {
"HOSTNAME": switch_name,
"CSM_VERSION": csm,
Expand Down Expand Up @@ -857,8 +882,6 @@ def vsx_mac(switch_name):
"CMN_IP_GATEWAY": sls_variables["CMN_IP_GATEWAY"],
"CMN_IP_PRIMARY": sls_variables["CMN_IP_PRIMARY"],
"CMN_IP_SECONDARY": sls_variables["CMN_IP_SECONDARY"],
"NMN_MTN_CABINETS": sls_variables["NMN_MTN_CABINETS"],
"HMN_MTN_CABINETS": sls_variables["HMN_MTN_CABINETS"],
"LEAF_BMC_VLANS": leaf_bmc_vlan,
"SPINE_LEAF_VLANS": spine_leaf_vlan,
"NATIVE_VLAN": native_vlan,
Expand Down Expand Up @@ -1040,6 +1063,23 @@ def vsx_mac(switch_name):
ip = str(ip_address[3])
variables["HMN_MTN_VLANS"][-1]["IP"] = ip

dupe_vlans, vlan_range = vlan_check(variables)

if len(dupe_vlans) > 0:
click.secho(
f"Error: Duplicate VLANs detected: {', '.join(map(str, dupe_vlans))}.
Verify the VLANs in SLS and custom_configuration.yaml.",
fg="red",
)
sys.exit(1)

if len(vlan_range) > 0:
click.secho(
f"Error: VLANs out of range: {', '.join(map(str, vlan_range))}. VLANs must be within the range 1-4040.",
fg="red",
)
sys.exit(1)

switch_config = template.render(
variables=variables,
cabling=cabling,
Expand Down Expand Up @@ -1211,12 +1251,18 @@ def preserve_port(
return port["lag"]


def get_vlan_id(destination_rack_int, sls_variables, cabinet_key):
def get_vlan_id_by_cabinet(destination_rack_int, sls_variables, cabinet_key):
"""Get the VLAN based on the cabinet."""
for cabinets in sls_variables[cabinet_key]:
sls_rack_int = int(re.search(r"\d+", cabinets["Name"])[0])
if cabinet_key not in sls_variables:
raise KeyError(
f"The cabinet_key '{cabinet_key}' is not found in sls_variables.",
)

for cabinet in sls_variables[cabinet_key]:
cabinet_name = cabinet.get("Name", "")
sls_rack_int = int(re.search(r"\d+", cabinet_name).group())
if destination_rack_int == sls_rack_int:
return cabinets["VlanID"]
return cabinet.get("VlanID")
return None # Return None if VLAN ID is not found


Expand Down Expand Up @@ -1356,9 +1402,11 @@ def get_switch_nodes(
new_node["config"]["LAG_NUMBER"] = preserve_port(preserve, source_port)
nodes.append(new_node)
elif shasta_name == "cec":
destination_rack_int = int(re.search(r"\d+", destination_rack)[0])
destination_rack_int = int(re.search(r"\d+", destination_rack)[0]),
vlan_key = "HMN_MTN_CABINETS"
hmn_mtn_vlan = get_vlan_id(destination_rack_int, sls_variables, vlan_key)
hmn_mtn_vlan = get_vlan_id_by_cabinet(
destination_rack_int, sls_variables, vlan_key
)
new_node = {
"subtype": "cec",
"slot": None,
Expand All @@ -1378,12 +1426,12 @@ def get_switch_nodes(
vlan_key_hmn = "HMN_MTN_CABINETS"
vlan_key_nmn = "NMN_MTN_CABINETS"
destination_rack_int = int(re.search(r"\d+", destination_rack)[0])
hmn_mtn_vlan = get_vlan_id(
hmn_mtn_vlan = get_vlan_id_by_cabinet(
destination_rack_int,
sls_variables,
vlan_key_hmn,
)
nmn_mtn_vlan = get_vlan_id(
nmn_mtn_vlan = get_vlan_id_by_cabinet(
destination_rack_int,
sls_variables,
vlan_key_nmn,
Expand All @@ -1410,7 +1458,9 @@ def get_switch_nodes(
elif shasta_name in {"uan", "login", "viz", "lmem"}:
vlan_key = "NMN_RVR_CABINETS"
destination_rack_int = int(re.search(r"\d+", destination_rack)[0])
nmn_rvr_vlan = get_vlan_id(destination_rack_int, sls_variables, vlan_key)
nmn_rvr_vlan = get_vlan_id_by_cabinet(
destination_rack_int, sls_variables, vlan_key,
)
primary_port_uan = get_primary_port(
nodes_by_name,
switch_name,
Expand Down Expand Up @@ -1455,7 +1505,9 @@ def get_switch_nodes(
}:
vlan_key = "NMN_RVR_CABINETS"
destination_rack_int = int(re.search(r"\d+", destination_rack)[0])
nmn_rvr_vlan = get_vlan_id(destination_rack_int, sls_variables, vlan_key)
nmn_rvr_vlan = get_vlan_id_by_cabinet(
destination_rack_int, sls_variables, vlan_key,
)
new_node = {
"subtype": "river_ncn_node_4_port_1g_ocp",
"slot": destination_slot,
Expand Down Expand Up @@ -1494,7 +1546,9 @@ def get_switch_nodes(
elif shasta_name == "cn":
vlan_key = "NMN_RVR_CABINETS"
destination_rack_int = int(re.search(r"\d+", destination_rack)[0])
nmn_rvr_vlan = get_vlan_id(destination_rack_int, sls_variables, vlan_key)
nmn_rvr_vlan = get_vlan_id_by_cabinet(
destination_rack_int, sls_variables, vlan_key,
)
new_node = {
"subtype": "compute",
"slot": destination_slot,
Expand Down
4 changes: 1 addition & 3 deletions canu/utils/validate_node_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ def validate_node_list(value):
""".

Args:
ctx: click
param: click paramater
value: node list

Returns:
nodes: list of nodes.

Raises:
BadParameter: If the node list is invalid.
Exception: If the node list is invalid.
"""
if value is None:
return []
Expand Down