Exemplo n.º 1
0
def tunnel():
    """Show vxlan tunnel information"""
    config_db = ConfigDBConnector()
    config_db.connect()
    header = ['vxlan tunnel name', 'source ip', 'destination ip', 'tunnel map name', 'tunnel map mapping(vni -> vlan)']

    # Fetching data from config_db for VXLAN TUNNEL
    vxlan_data = config_db.get_table('VXLAN_TUNNEL')
    vxlan_keys = natsorted(list(vxlan_data.keys()))

    table = []
    for k in vxlan_keys:
        r = []
        r.append(k)
        r.append(vxlan_data[k].get('src_ip'))
        r.append(vxlan_data[k].get('dst_ip'))
        vxlan_map_keys = config_db.keys(config_db.CONFIG_DB,
                                        'VXLAN_TUNNEL_MAP{}{}{}*'.format(config_db.KEY_SEPARATOR, k, config_db.KEY_SEPARATOR))
        if vxlan_map_keys:
            vxlan_map_mapping = config_db.get_all(config_db.CONFIG_DB, vxlan_map_keys[0])
            r.append(vxlan_map_keys[0].split(config_db.KEY_SEPARATOR, 2)[2])
            r.append("{} -> {}".format(vxlan_map_mapping.get('vni'), vxlan_map_mapping.get('vlan')))
        table.append(r)

    click.echo(tabulate(table, header))
Exemplo n.º 2
0
def vlanvnimap(count):
    """Show VLAN VNI Mapping Information"""

    header = ['VLAN', 'VNI']
    body = []

    config_db = ConfigDBConnector()
    config_db.connect()

    if count is not None:
      vxlan_keys = config_db.keys('CONFIG_DB', "VXLAN_TUNNEL_MAP|*")

      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:
       vxlan_table = config_db.get_table('VXLAN_TUNNEL_MAP')
       vxlan_keys = vxlan_table.keys()
       num=0
       if vxlan_keys is not None:
         for key in natsorted(vxlan_keys):
             body.append([vxlan_table[key]['vlan'], vxlan_table[key]['vni']])
             num += 1
       click.echo(tabulate(body, header, tablefmt="grid"))
       output = 'Total count : '
       output += ('%s \n' % (str(num)))
       click.echo(output)
Exemplo n.º 3
0
def interface():
    """Show VXLAN VTEP Information"""

    config_db = ConfigDBConnector()
    config_db.connect()

    # Fetching VTEP keys from config DB
    click.secho('VTEP Information:\n', bold=True, underline=True)
    vxlan_table = config_db.get_table('VXLAN_TUNNEL')
    vxlan_keys = vxlan_table.keys()
    vtep_sip = '0.0.0.0'
    if vxlan_keys is not None:
      for key in natsorted(vxlan_keys):
          key1 = key.split('|',1)
          vtepname = key1.pop();
          if 'src_ip' in vxlan_table[key]:
            vtep_sip = vxlan_table[key]['src_ip']
          if vtep_sip is not '0.0.0.0':
             output = '\tVTEP Name : ' + vtepname + ', SIP  : ' + vxlan_table[key]['src_ip']
          else:
             output = '\tVTEP Name : ' + vtepname 

          click.echo(output)

    if vtep_sip is not '0.0.0.0':
       vxlan_table = config_db.get_table('VXLAN_EVPN_NVO')
       vxlan_keys = vxlan_table.keys()
       if vxlan_keys is not None:
         for key in natsorted(vxlan_keys):
             key1 = key.split('|',1)
             vtepname = key1.pop();
             output = '\tNVO Name  : ' + vtepname + ',  VTEP : ' + vxlan_table[key]['source_vtep']
             click.echo(output)

       vxlan_keys = config_db.keys('CONFIG_DB', "LOOPBACK_INTERFACE|*")
       loopback = 'Not Configured'
       if vxlan_keys is not None:
         for key in natsorted(vxlan_keys):
             key1 = key.split('|',2)
             if len(key1) == 3 and key1[2] == vtep_sip+'/32':
                loopback = key1[1]
                break
         output = '\tSource interface  : ' + loopback 
         if vtep_sip != '0.0.0.0':
            click.echo(output)