Ejemplo n.º 1
0
def nasip(ctx, nas_ip):
    """Specify RADIUS server global NAS-IP|IPV6-Address <IPAddress>"""
    if ctx.obj == 'default':
        del_table_key('RADIUS', 'global', 'nas_ip')
        return
    elif not nas_ip:
        click.echo('Not support empty argument')
        return

    if not clicommon.is_ipaddress(nas_ip):
        click.echo('Invalid ip address')
        return

    v6_invalid_list = [ipaddress.IPv6Address(unicode('0::0')), ipaddress.IPv6Address(unicode('0::1'))]
    net = ipaddress.ip_network(unicode(nas_ip), strict=False)
    if (net.version == 4):
        if nas_ip == "0.0.0.0":
            click.echo('enter non-zero ip address')
            return
        ip = ipaddress.IPv4Address(nas_ip)
        if ip.is_reserved:
            click.echo('Reserved ip is not valid')
            return
        if ip.is_multicast:
            click.echo('Multicast ip is not valid')
            return
    elif (net.version == 6):
        ip = ipaddress.IPv6Address(nas_ip)
        if (ip.is_multicast):
            click.echo('Multicast ip is not valid')
            return
        if (ip in v6_invalid_list):
            click.echo('Invalid ip address')
            return
    add_table_kv('RADIUS', 'global', 'nas_ip', nas_ip)
Ejemplo n.º 2
0
def add(address, timeout, key, auth_type, port, pri, use_mgmt_vrf):
    """Specify a TACACS+ server"""
    if not clicommon.is_ipaddress(address):
        click.echo('Invalid ip address')
        return

    config_db = ConfigDBConnector()
    config_db.connect()
    old_data = config_db.get_entry('TACPLUS_SERVER', address)
    if old_data != {}:
        click.echo('server %s already exists' % address)
    else:
        data = {
            'tcp_port': str(port),
            'priority': pri
        }
        if auth_type is not None:
            data['auth_type'] = auth_type
        if timeout is not None:
            data['timeout'] = str(timeout)
        if key is not None:
            data['passkey'] = key
        if use_mgmt_vrf :
            data['vrf'] = "mgmt"
        config_db.set_entry('TACPLUS_SERVER', address, data)
Ejemplo n.º 3
0
def del_vlan_dhcp_relay_destination(db, vid, dhcp_relay_destination_ip):
    """ Remove a destination IP address from the VLAN's DHCP relay """

    ctx = click.get_current_context()

    if not clicommon.is_ipaddress(dhcp_relay_destination_ip):
        ctx.fail('{} is invalid IP address'.format(dhcp_relay_destination_ip))

    vlan_name = 'Vlan{}'.format(vid)
    vlan = db.cfgdb.get_entry('VLAN', vlan_name)
    if len(vlan) == 0:
        ctx.fail("{} doesn't exist".format(vlan_name))

    dhcp_relay_dests = vlan.get('dhcp_servers', [])
    if not dhcp_relay_destination_ip in dhcp_relay_dests:
        ctx.fail("{} is not a DHCP relay destination for {}".format(
            dhcp_relay_destination_ip, vlan_name))

    dhcp_relay_dests.remove(dhcp_relay_destination_ip)
    if len(dhcp_relay_dests) == 0:
        del vlan['dhcp_servers']
    else:
        vlan['dhcp_servers'] = dhcp_relay_dests
    db.cfgdb.set_entry('VLAN', vlan_name, vlan)
    click.echo("Removed DHCP relay destination address {} from {}".format(
        dhcp_relay_destination_ip, vlan_name))
    try:
        click.echo("Restarting DHCP relay service...")
        clicommon.run_command("systemctl stop dhcp_relay", display_cmd=False)
        clicommon.run_command("systemctl reset-failed dhcp_relay",
                              display_cmd=False)
        clicommon.run_command("systemctl start dhcp_relay", display_cmd=False)
    except SystemExit as e:
        ctx.fail("Restart service dhcp_relay failed with error {}".format(e))
Ejemplo n.º 4
0
def delete(address):
    """Delete a TACACS+ server"""
    if not clicommon.is_ipaddress(address):
        click.echo('Invalid ip address')
        return

    config_db = ConfigDBConnector()
    config_db.connect()
    config_db.set_entry('TACPLUS_SERVER', address, None)
Ejemplo n.º 5
0
def remotemac(remote_vtep_ip, count):
    """Show MACs pointing to the remote VTEP"""

    if (remote_vtep_ip != 'all') and (clicommon.is_ipaddress(remote_vtep_ip) is
                                      False):
        click.echo("Remote VTEP IP {} invalid format".format(remote_vtep_ip))
        return

    header = ['VLAN', 'MAC', 'RemoteVTEP', 'VNI', 'Type']
    body = []
    db = SonicV2Connector(host='127.0.0.1')
    db.connect(db.APPL_DB)

    vxlan_keys = db.keys(db.APPL_DB, 'VXLAN_FDB_TABLE:*')

    if ((count is not None) and (remote_vtep_ip == 'all')):
        if not vxlan_keys:
            vxlan_count = 0
        else:
            vxlan_count = len(vxlan_keys)

        output = 'Total count : '
        output += ('%s \n' % (str(vxlan_count)))
        click.echo(output)
    else:
        num = 0
        if vxlan_keys is not None:
            for key in natsorted(vxlan_keys):
                key1 = key.split(':', 2)
                mac = key1.pop()
                vlan = key1.pop()
                vxlan_table = db.get_all(db.APPL_DB, key)
                if vxlan_table is None:
                    continue
                rmtip = vxlan_table['remote_vtep']
                if remote_vtep_ip != 'all' and rmtip != remote_vtep_ip:
                    continue
                if count is None:
                    body.append([
                        vlan, mac, rmtip, vxlan_table['vni'],
                        vxlan_table['type']
                    ])
                num += 1
        if count is None:
            click.echo(tabulate(body, header, tablefmt="grid"))
        output = 'Total count : '
        output += ('%s \n' % (str(num)))
        click.echo(output)
Ejemplo n.º 6
0
def remotevni(remote_vtep_ip, count):
    """Show Vlans extended to the remote VTEP"""

    if (remote_vtep_ip != 'all') and (clicommon.is_ipaddress(remote_vtep_ip) is
                                      False):
        click.echo("Remote VTEP IP {} invalid format".format(remote_vtep_ip))
        return

    header = ['VLAN', 'RemoteVTEP', 'VNI']
    body = []
    db = SonicV2Connector(host='127.0.0.1')
    db.connect(db.APPL_DB)

    if (remote_vtep_ip == 'all'):
        vxlan_keys = db.keys(db.APPL_DB, 'VXLAN_REMOTE_VNI_TABLE:*')
    else:
        vxlan_keys = db.keys(db.APPL_DB,
                             'VXLAN_REMOTE_VNI_TABLE:*' + remote_vtep_ip + '*')

    if count is not None:
        if not vxlan_keys:
            vxlan_count = 0
        else:
            vxlan_count = len(vxlan_keys)

        output = 'Total count : '
        output += ('%s \n' % (str(vxlan_count)))
        click.echo(output)
    else:
        num = 0
        if vxlan_keys is not None:
            for key in natsorted(vxlan_keys):
                key1 = key.split(':')
                rmtip = key1.pop()
                #if remote_vtep_ip != 'all' and rmtip != remote_vtep_ip:
                #   continue
                vxlan_table = db.get_all(db.APPL_DB, key)
                if vxlan_table is None:
                    continue
                body.append([key1.pop(), rmtip, vxlan_table['vni']])
                num += 1
        click.echo(tabulate(body, header, tablefmt="grid"))
        output = 'Total count : '
        output += ('%s \n' % (str(num)))
        click.echo(output)
Ejemplo n.º 7
0
def add_vxlan(db, vxlan_name, src_ip):
    """Add VXLAN"""
    ctx = click.get_current_context()

    if not clicommon.is_ipaddress(src_ip):
        ctx.fail("{} invalid src ip address".format(src_ip))

    vxlan_keys = db.cfgdb.get_keys('VXLAN_TUNNEL')
    if not vxlan_keys:
        vxlan_count = 0
    else:
        vxlan_count = len(vxlan_keys)

    if (vxlan_count > 0):
        ctx.fail("VTEP already configured.")

    fvs = {'src_ip': src_ip}
    db.cfgdb.set_entry('VXLAN_TUNNEL', vxlan_name, fvs)