netutils/vlan.py
def vlanconfig_to_list(vlan_config):
    """Given an IOS-like vlan list of configurations, return the list of VLANs.

    Args:
        vlan_config (list): IOS-like vlan list of configurations.

    Returns:
        dict: Sorted string list of integers according to IOS-like vlan list rules

    Example:
        >>> vlan_config = '''switchport trunk allowed vlan 1025,1069-1072,1114,1173-1181,1501,1502'''
        >>> vlanconfig_to_list(vlan_config)
        [1025, 1069, 1070, 1071, 1072, 1114, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1501, 1502]
        >>>
    """
    # Check for invalid data within the vlan_config
    # example: switchport trunk allowed vlan 1025,1069-1072,BADDATA
    invalid_data = re.findall(r",?[^0-9\-],?$", vlan_config)
    # Regular VLANs that are not condensed and can be converted to integers
    vlans = list(map(int, re.findall(r"\d+", vlan_config)))

    # Fail if invalid data is found
    if invalid_data and vlans:
        raise ValueError(f"There were non-digits and dashes found in `{vlan_config}`.")
    if invalid_data:
        raise ValueError(f"No digits found in `{vlan_config}`")

    vlan_ranges = re.findall(r"\d+-\d+", vlan_config)
    for v_range in vlan_ranges:
        first, second = v_range.split("-")
        # Add one to first to prevent duplicates that already exist within vlans
        vlans.extend(list(range(*[int(first) + 1, int(second)])))

    vlans = sorted(vlans)
    if vlans[-1] > 4094:
        raise ValueError(f"Valid VLAN range is 1-4094, found {vlans[-1]}")
    return vlans
Given an IOS-like vlan list of configurations, return the list of VLANs.

    Args:
        vlan_config (list): IOS-like vlan list of configurations.

    Returns:
        dict: Sorted string list of integers according to IOS-like vlan list rules

    Example:
        >>> vlan_config = '''switchport trunk allowed vlan 1025,1069-1072,1114,1173-1181,1501,1502'''
        >>> vlanconfig_to_list(vlan_config)
        [1025, 1069, 1070, 1071, 1072, 1114, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1501, 1502]
        >>>
    
Given an IOS-like vlan list of configurations, return the list of VLANs.
Given an IOS - like vlan list of configurations return the list of VLANs .
def vlanconfig_to_list(vlan_config):
    invalid_data = re.findall(r",?[^0-9\-],?$", vlan_config)
    vlans = list(map(int, re.findall(r"\d+", vlan_config)))
    if invalid_data and vlans:
        raise ValueError(f"There were non-digits and dashes found in `{vlan_config}`.")
    if invalid_data:
        raise ValueError(f"No digits found in `{vlan_config}`")
    vlan_ranges = re.findall(r"\d+-\d+", vlan_config)
    for v_range in vlan_ranges:
        first, second = v_range.split("-")
        vlans.extend(list(range(*[int(first) + 1, int(second)])))
    vlans = sorted(vlans)
    if vlans[-1] > 4094:
        raise ValueError(f"Valid VLAN range is 1-4094, found {vlans[-1]}")
    return vlans
def vlanconfig_to_list ( vlan_config ) : invalid_data = re . findall ( r",?[^0-9\-],?$" , vlan_config ) vlans = list ( map ( int , re . findall ( r"\d+" , vlan_config ) ) ) if invalid_data and vlans : raise ValueError ( f"There were non-digits and dashes found in `{vlan_config}`." ) if invalid_data : raise ValueError ( f"No digits found in `{vlan_config}`" ) vlan_ranges = re . findall ( r"\d+-\d+" , vlan_config ) for v_range in vlan_ranges : first , second = v_range . split ( "-" ) vlans . extend ( list ( range ( * [ int ( first ) + 1 , int ( second ) ] ) ) ) vlans = sorted ( vlans ) if vlans [ - 1 ] > 4094 : raise ValueError ( f"Valid VLAN range is 1-4094, found {vlans[-1]}" ) return vlans
Given an IOS-like vlan list of configurations, return the list of VLANs.
Given an IOS - like vlan list of configurations return the list of VLANs .
"""Given an IOS-like vlan list of configurations, return the list of VLANs.

    Args:
        vlan_config (list): IOS-like vlan list of configurations.

    Returns:
        dict: Sorted string list of integers according to IOS-like vlan list rules

    Example:
        >>> vlan_config = '''switchport trunk allowed vlan 1025,1069-1072,1114,1173-1181,1501,1502'''
        >>> vlanconfig_to_list(vlan_config)
        [1025, 1069, 1070, 1071, 1072, 1114, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1501, 1502]
        >>>
    """ # Check for invalid data within the vlan_config # example: switchport trunk allowed vlan 1025,1069-1072,BADDATA # Regular VLANs that are not condensed and can be converted to integers # Fail if invalid data is found # Add one to first to prevent duplicates that already exist within vlans
Sorted string list of integers according to IOS-like vlan list rules
Sorted string list of integers according to IOS - like vlan list rules
dict
vlan_config
IOS-like vlan list of configurations.
IOS - like vlan list of configurations .
examples
None