Beispiel #1
0
def interface_list_validator(ctx, db, interface_list):
    for intf in interface_list.split(','):
        if not (clicommon.is_valid_port(db, str(intf))
                or clicommon.is_valid_portchannel(db, str(intf))):
            raise click.UsageError(
                "Invalid value for \"--interface-list\": {} is not a valid interface"
                .format(intf), ctx)
Beispiel #2
0
def interfaces_list_validator(db, interface_list, is_update):
    if is_update and (interface_list is None):
        return

    is_error = False
    interfaces_splited = interface_list.split(',')

    for intf in interfaces_splited:
        if intf.startswith('Ethernet'):
            if not clicommon.is_valid_port(db.cfgdb, intf):
                is_error = True
                break
        elif intf.startswith('PortChannel'):
            if not clicommon.is_valid_portchannel(db.cfgdb, intf):
                is_error = True
                break
        else:
            is_error = True
            break

    if is_error:
        exit_with_error(
            "Error: invalid value '{}', for '--interface-list' option".format(
                interface_list),
            fg="red")
Beispiel #3
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"})