Exemplo n.º 1
0
def del_vxlan_map_range(db, vxlan_name, vlan_start, vlan_end, vni_start):
    """Del Range of vlan-vni mappings"""
    ctx = click.get_current_context()
    if clicommon.is_vlanid_in_range(vlan_start) is False:
        ctx.fail(" Invalid Vlan Id , Valid Range : 1 to 4094 ")
    if clicommon.is_vlanid_in_range(vlan_end) is False:
        ctx.fail(" Invalid Vlan Id , Valid Range : 1 to 4094 ")
    if (vlan_start > vlan_end):
        ctx.fail("vlan_end should be greater or equal to vlan_start")
    if clicommon.vni_id_is_valid(vni_start) is False:
        ctx.fail(
            "Invalid VNI {}. Valid range [1 to 16777215].".format(vni_start))
    if clicommon.vni_id_is_valid(vni_start + vlan_end - vlan_start) is False:
        ctx.fail("Invalid VNI End {}. Valid range [1 to 16777215].".format(
            vni_start))

    if len(db.cfgdb.get_entry('VXLAN_TUNNEL', vxlan_name)) == 0:
        ctx.fail("VTEP {} not configured".format(vxlan_name))

    vlan_end = vlan_end + 1
    for vid in range(vlan_start, vlan_end):
        vlan_name = 'Vlan{}'.format(vid)
        vnid = vni_start + vid - vlan_start
        vni_name = '{}'.format(vnid)
        if clicommon.is_vni_vrf_mapped(db, vni_name) is False:
            print("Skipping Vlan {} VNI {} mapped delete. ".format(
                vlan_name, vni_name))
            continue

        mapname = vxlan_name + '|' + 'map_' + vni_name + '_' + vlan_name
        db.cfgdb.set_entry('VXLAN_TUNNEL_MAP', mapname, None)
Exemplo n.º 2
0
def del_vlan(db, vid):
    """Delete VLAN"""

    log.log_info("'vlan del {}' executing...".format(vid))

    ctx = click.get_current_context()

    if not clicommon.is_vlanid_in_range(vid):
        ctx.fail("Invalid VLAN ID {} (1-4094)".format(vid))

    vlan = 'Vlan{}'.format(vid)
    if clicommon.check_if_vlanid_exist(db.cfgdb, vlan) == False:
        ctx.fail("{} does not exist".format(vlan))

    intf_table = db.cfgdb.get_table('VLAN_INTERFACE')
    for intf_key in intf_table:
        if ((type(intf_key) is str and intf_key == 'Vlan{}'.format(vid)) or
            (type(intf_key) is tuple and intf_key[0] == 'Vlan{}'.format(vid))):
            ctx.fail(
                "{} can not be removed. First remove IP addresses assigned to this VLAN"
                .format(vlan))

    keys = [(k, v) for k, v in db.cfgdb.get_table('VLAN_MEMBER')
            if k == 'Vlan{}'.format(vid)]

    if keys:
        ctx.fail(
            "VLAN ID {} can not be removed. First remove all members assigned to this VLAN."
            .format(vid))

    db.cfgdb.set_entry('VLAN', 'Vlan{}'.format(vid), None)
Exemplo n.º 3
0
def del_vlan_member(db, vid, port):
    """Delete VLAN member"""

    ctx = click.get_current_context()

    log.log_info("'vlan member del {} {}' executing...".format(vid, port))

    if not clicommon.is_vlanid_in_range(vid):
        ctx.fail("Invalid VLAN ID {} (1-4094)".format(vid))

    vlan = 'Vlan{}'.format(vid)
    if clicommon.check_if_vlanid_exist(db.cfgdb, vlan) == False:
        ctx.fail("{} does not exist".format(vlan))

    if clicommon.get_interface_naming_mode() == "alias":
        alias = port
        iface_alias_converter = clicommon.InterfaceAliasConverter(db)
        port = iface_alias_converter.alias_to_name(alias)
        if port is None:
            ctx.fail("cannot find port name for alias {}".format(alias))

    if not clicommon.is_port_vlan_member(db.cfgdb, port, vlan):
        ctx.fail("{} is not a member of {}".format(port, vlan))

    db.cfgdb.set_entry('VLAN_MEMBER', (vlan, port), None)
Exemplo n.º 4
0
def del_vxlan_map(db, vxlan_name, vlan, vni):
    """Del VLAN-VNI map entry"""
    ctx = click.get_current_context()

    if not vlan.isdigit():
        ctx.fail("Invalid vlan {}. Only valid vlan is accepted".format(vni))
    if clicommon.is_vlanid_in_range(int(vlan)) is False:
        ctx.fail(" Invalid Vlan Id , Valid Range : 1 to 4094 ")
    if not vni.isdigit():
        ctx.fail("Invalid VNI {}. Only valid VNI is accepted".format(vni))
    if clicommon.vni_id_is_valid(int(vni)) is False:
        ctx.fail("Invalid VNI {}. Valid range [1 to 16777215].".format(vni))

    if len(db.cfgdb.get_entry('VXLAN_TUNNEL', vxlan_name)) == 0:
        ctx.fail("VTEP {} not configured".format(vxlan_name))
    found = 0
    vrf_table = db.cfgdb.get_table('VRF')
    vrf_keys = vrf_table.keys()
    if vrf_keys is not None:
        for vrf_key in vrf_keys:
            if ('vni' in vrf_table[vrf_key]
                    and vrf_table[vrf_key]['vni'] == vni):
                found = 1
                break

    if (found == 1):
        ctx.fail("VNI mapped to vrf {}, Please remove VRF VNI mapping".format(
            vrf_key))

    mapname = vxlan_name + '|' + 'map_' + vni + '_' + vlan
    db.cfgdb.set_entry('VXLAN_TUNNEL_MAP', mapname, None)
    mapname = vxlan_name + '|' + 'map_' + vni + '_Vlan' + vlan
    db.cfgdb.set_entry('VXLAN_TUNNEL_MAP', mapname, None)
Exemplo n.º 5
0
def add_vxlan_map(db, vxlan_name, vlan, vni):
    """Add VLAN-VNI map entry"""
    ctx = click.get_current_context()

    if not vlan.isdigit():
        ctx.fail("Invalid vlan {}. Only valid vlan is accepted".format(vni))
    if clicommon.is_vlanid_in_range(int(vlan)) is False:
        ctx.fail(" Invalid Vlan Id , Valid Range : 1 to 4094 ")
    if not vni.isdigit():
        ctx.fail("Invalid VNI {}. Only valid VNI is accepted".format(vni))
    if clicommon.vni_id_is_valid(int(vni)) is False:
        ctx.fail("Invalid VNI {}. Valid range [1 to 16777215].".format(vni))

    vlan_name = "Vlan" + vlan

    if len(db.cfgdb.get_entry('VXLAN_TUNNEL', vxlan_name)) == 0:
        ctx.fail("VTEP {} not configured".format(vxlan_name))

    if len(db.cfgdb.get_entry('VLAN', vlan_name)) == 0:
        ctx.fail("{} not configured".format(vlan_name))

    vxlan_table = db.cfgdb.get_table('VXLAN_TUNNEL_MAP')
    vxlan_keys = vxlan_table.keys()
    if vxlan_keys is not None:
        for key in vxlan_keys:
            if (vxlan_table[key]['vlan'] == vlan_name):
                ctx.fail(" Vlan Id already mapped ")
            if (vxlan_table[key]['vni'] == vni):
                ctx.fail(" VNI Id already mapped ")

    fvs = {'vni': vni, 'vlan': vlan_name}
    mapname = vxlan_name + '|' + 'map_' + vni + '_' + vlan_name
    db.cfgdb.set_entry('VXLAN_TUNNEL_MAP', mapname, fvs)
Exemplo n.º 6
0
def add_vxlan_map_range(db, vxlan_name, vlan_start, vlan_end, vni_start):
    """Add Range of vlan-vni mappings"""
    ctx = click.get_current_context()
    if clicommon.is_vlanid_in_range(vlan_start) is False:
        ctx.fail(" Invalid Vlan Id , Valid Range : 1 to 4094 ")
    if clicommon.is_vlanid_in_range(vlan_end) is False:
        ctx.fail(" Invalid Vlan Id , Valid Range : 1 to 4094 ")
    if (vlan_start > vlan_end):
        ctx.fail("vlan_end should be greater or equal to vlan_start")
    if clicommon.vni_id_is_valid(vni_start) is False:
        ctx.fail(
            "Invalid VNI {}. Valid range [1 to 16777215].".format(vni_start))
    if clicommon.vni_id_is_valid(vni_start + vlan_end - vlan_start) is False:
        ctx.fail("Invalid VNI End {}. Valid range [1 to 16777215].".format(
            vni_start))

    if len(db.cfgdb.get_entry('VXLAN_TUNNEL', vxlan_name)) == 0:
        ctx.fail("VTEP {} not configured".format(vxlan_name))
    vlan_end = vlan_end + 1
    vxlan_table = db.cfgdb.get_table('VXLAN_TUNNEL_MAP')
    vxlan_keys = vxlan_table.keys()

    for vid in range(vlan_start, vlan_end):
        vlan_name = 'Vlan{}'.format(vid)
        vnid = vni_start + vid - vlan_start
        vni_name = '{}'.format(vnid)
        match_found = 'no'
        if len(db.cfgdb.get_entry('VLAN', vlan_name)) == 0:
            click.echo("{} not configured".format(vlan_name))
            continue
        if vxlan_keys is not None:
            for key in vxlan_keys:
                if (vxlan_table[key]['vlan'] == vlan_name):
                    print(vlan_name + " already mapped")
                    match_found = 'yes'
                    break
                if (vxlan_table[key]['vni'] == vni_name):
                    print("VNI:" + vni_name + " already mapped ")
                    match_found = 'yes'
                    break
        if (match_found == 'yes'):
            continue
        fvs = {'vni': vni_name, 'vlan': vlan_name}
        mapname = vxlan_name + '|' + 'map_' + vni_name + '_' + vlan_name
        db.cfgdb.set_entry('VXLAN_TUNNEL_MAP', mapname, fvs)
Exemplo n.º 7
0
def add_vlan(db, vid):
    """Add VLAN"""

    ctx = click.get_current_context()

    if not clicommon.is_vlanid_in_range(vid):
        ctx.fail("Invalid VLAN ID {} (1-4094)".format(vid))

    vlan = 'Vlan{}'.format(vid)
    if clicommon.check_if_vlanid_exist(db.cfgdb, vlan):
        ctx.fail("{} already exists".format(vlan))

    db.cfgdb.set_entry('VLAN', vlan, {'vlanid': vid})
Exemplo n.º 8
0
def add_vlan_member(db, vid, port, untagged):
    """Add VLAN member"""

    ctx = click.get_current_context()

    log.log_info("'vlan member add {} {}' executing...".format(vid, port))

    if not clicommon.is_vlanid_in_range(vid):
        ctx.fail("Invalid VLAN ID {} (1-4094)".format(vid))

    vlan = 'Vlan{}'.format(vid)
    if clicommon.check_if_vlanid_exist(db.cfgdb, vlan) == False:
        ctx.fail("{} does not exist".format(vlan))

    if clicommon.get_interface_naming_mode() == "alias":
        alias = port
        iface_alias_converter = clicommon.InterfaceAliasConverter(db)
        port = iface_alias_converter.alias_to_name(alias)
        if port is None:
            ctx.fail("cannot find port name for alias {}".format(alias))

    if clicommon.is_port_mirror_dst_port(db.cfgdb, port):
        ctx.fail("{} is configured as mirror destination port".format(port))

    if clicommon.is_port_vlan_member(db.cfgdb, port, vlan):
        ctx.fail("{} is already a member of {}".format(port, vlan))

    if clicommon.is_valid_port(db.cfgdb, port):
        is_port = True
    elif clicommon.is_valid_portchannel(db.cfgdb, port):
        is_port = False
    else:
        ctx.fail("{} does not exist".format(port))

    if (is_port and clicommon.is_port_router_interface(db.cfgdb, port)) or \
       (not is_port and clicommon.is_pc_router_interface(db.cfgdb, port)):
        ctx.fail("{} is a router interface!".format(port))

    portchannel_member_table = db.cfgdb.get_table('PORTCHANNEL_MEMBER')

    if (is_port and clicommon.interface_is_in_portchannel(
            portchannel_member_table, port)):
        ctx.fail("{} is part of portchannel!".format(port))

    if (clicommon.interface_is_untagged_member(db.cfgdb, port) and untagged):
        ctx.fail("{} is already untagged member!".format(port))

    db.cfgdb.set_entry('VLAN_MEMBER', (vlan, port),
                       {'tagging_mode': "untagged" if untagged else "tagged"})
Exemplo n.º 9
0
def del_vlan(db, vid):
    """Delete VLAN"""

    log.log_info("'vlan del {}' executing...".format(vid))

    ctx = click.get_current_context()

    if not clicommon.is_vlanid_in_range(vid):
        ctx.fail("Invalid VLAN ID {} (1-4094)".format(vid))

    vlan = 'Vlan{}'.format(vid)
    if clicommon.check_if_vlanid_exist(db.cfgdb, vlan) == False:
        ctx.fail("{} does not exist".format(vlan))

    keys = [ (k, v) for k, v in db.cfgdb.get_table('VLAN_MEMBER') if k == 'Vlan{}'.format(vid) ]
    for k in keys:
        db.cfgdb.set_entry('VLAN_MEMBER', k, None)
    db.cfgdb.set_entry('VLAN', 'Vlan{}'.format(vid), None)