How to use the genie.libs.parser.utils.common.Common.convert_intf_name function in genie

To help you get started, we’ve selected a few genie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxe / show_vlan.py View on Github external
p5 = re.compile(r'^\s*(?P[0-9a-zA-Z]+)? +(?P\d+)'
                             ' +(?P[\w\-]+)( +(?P[\w\/, ]+))?')
            m = p5.match(line)

            if m:
                if m.groupdict()['primary'] and m.groupdict()['primary'].lower() != "none":
                    primary = m.groupdict()['primary']
                else:
                    primary = ""
                secondary = m.groupdict()['secondary']

                private_vlan_type = m.groupdict()['type']
                if m.groupdict()['interfaces']:
                    private_vlan_interfaces = \
                        [Common.convert_intf_name(i) for i in m.groupdict()['interfaces'].split(',')]

                if 'vlans' not in vlan_dict:
                    vlan_dict['vlans'] = {}
                if m.groupdict()['primary'] and m.groupdict()['primary'].lower() != "none":
                    if primary not in vlan_dict['vlans']:
                        vlan_dict['vlans'][primary] = {}
                    if 'private_vlan' not in vlan_dict['vlans'][primary]:
                        vlan_dict['vlans'][primary]['private_vlan'] = {}
                if primary:
                    vlan_dict['vlans'][primary]['private_vlan']['primary'] = True
                    if 'association' in vlan_dict['vlans'][primary]['private_vlan']:
                        vlan_dict['vlans'][primary]['private_vlan']['association'] = \
                            vlan_dict['vlans'][primary]['private_vlan']['association'] + [secondary]
                    else:
                        vlan_dict['vlans'][primary]['private_vlan']['association'] = secondary.split()
github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxe / show_lag.py View on Github external
activity = 'auto' if 'a' in flags.lower() else None
                if activity:
                    intf_dict.update({'activity': activity})
                oper_status = 'up' if flags in ['RU', 'SU'] else 'down'
                intf_dict.update({'oper_status': oper_status})

                if group.get('ports'):
                    ports = group.pop('ports').split()

                    # port_channel
                    eth_list = []

                    port_dict = intf_dict.setdefault('members', {})
                    for port in ports:
                        port_value = port.split('(')
                        interface = Common.convert_intf_name(port_value[0])
                        state = port_value[1].replace(')','')
                        eth_list.append(interface)

                        port_item = port_dict.setdefault(interface, {})
                        port_item.update({'interface': interface})
                        port_item.update({'flags': state})
                        port_item.update({'bundled': True if state in ['bndl','P'] else False})

                        # port_channel
                        port_item.setdefault('port_channel', {}).update({'port_channel_member': True,
                                                                         'port_channel_int': name})

                    # port_channel
                    if eth_list:
                        port_dict = intf_dict.setdefault('port_channel', {})
                        port_dict['port_channel_member'] = True
github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxe / show_spanning_tree.py View on Github external
ret_dict['bpduguard_timeout_recovery'] = int(m.groupdict()['interval'])
                continue
            
            # channel-misconfig (STP)      Disabled
            m = p2.match(line)
            if m:
                group = m.groupdict()
                status_dict = ret_dict.setdefault('timer_status', {})
                status_dict[group['name'].strip()] = False if 'disabled' in group['status'].lower() else True
                continue

            # Fa2/4                bpduguard          273
            m = p3.match(line)
            if m:
                group = m.groupdict()
                intf = Common.convert_intf_name(group.pop('interface'))
                intf_dict = ret_dict.setdefault('interfaces', {}).setdefault(intf, {})
                intf_dict['interface'] = intf
                intf_dict['time_left'] = int(group.pop('time_left'))
                intf_dict.update({k:v for k,v in group.items()})
                continue

        return ret_dict
github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxr / show_eigrp.py View on Github external
continue

            # 1   Link Local Address:     Gi0/0/0/1.390     11 01:42:44    9   200  0  14
            # 0   Link Local Address:     Gi0/0/0/0.390     12 02:31:47    4   200  0  9
            result = r3.match(line)
            if result:

                group = result.groupdict()

                if not vrf:
                    vrf = 'default'

                if not eigrp_instance:
                    eigrp_instance = ''

                eigrp_interface = Common.convert_intf_name\
                    (intf=group['eigrp_interface'])

                peer_handle = int(group['peer_handle'])
                hold = int(group['hold'])
                uptime = group['uptime']
                srtt = float(group['srtt'])/1000
                rto = int(group['rto'])
                q_cnt = int(group['q_cnt'])
                last_seq_number = int(group['last_seq_number'])
                continue

            # fe80::5c00:ff:fe02:7
            # fe80::5c00:ff:fe02:7
            result = r4.match(line)
            if result:
github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxe / show_dot1x.py View on Github external
ret_dict = {}

        # initial regexp pattern
        p1 = re.compile(r'^(?P[\w\-\/]+) +(?P\w+) +'
                         '(?P\w+\.\w+\.\w+) +(?P\w+)$')
        p2 = re.compile(r'^((?P\w+) +)?(?P\w+\.\w+\.\w+) +(?P\w+)$')

        for line in out.splitlines():
            line = line.strip()
            line = line.replace('\t', '    ')
            
            # Fa1                   AUTH             000d.bcff.afcc           UNAUTHORIZED
            m = p1.match(line)
            if m:
                group = m.groupdict()
                intf = Common.convert_intf_name(group['intf'])
                intf_dict = ret_dict.setdefault('interfaces', {}).setdefault(intf, {})
                intf_dict['interface'] = intf

                client = group['client']
                client_dict = intf_dict.setdefault('clients', {}).setdefault(client, {})
                client_dict['client'] = client
                client_dict['status'] = group['status'].lower()
                client_dict['pae'] = 'authenticator' if 'auth' in group['pae'].lower() else 'supplicant'
                continue

            #                                        fa16.3eff.0ce0           AUTHORIZED
            #                       AUTH             000d.bcff.afcc           UNAUTHORIZED
            m = p2.match(line)
            if m:
                group = m.groupdict()
                pae = group['pae']
github CiscoTestAutomation / genieparser / src / genie / libs / parser / nxos / show_vxlan.py View on Github external
group = m.groupdict()
                topo_id = int(group.pop('topo_id'))
                mac_addr = group.pop('mac_addr')
                topo_dict = result_dict.setdefault('topology', {}).setdefault('topo_id', {}).setdefault(topo_id,{}).\
                                        setdefault('mac',{}).setdefault(mac_addr,{})

                flags = group.pop('flags')
                if flags.endswith(','):
                    flags = flags[:-1]

                topo_dict.update({'flags':  flags.lower()})
                topo_dict.update({'prod_type':  group.pop('prod_type').lower()})
                topo_dict.update({'seq_num': int(group.pop('seq_num'))})
                topo_dict.update({'mac_addr': mac_addr})
                try:
                    next_hop1 = Common.convert_intf_name(group.pop('next_hop1'))
                except:
                    next_hop1 = group.pop('next_hop1')
                topo_dict.update({'next_hop1': next_hop1})

                continue

            m1 = ""
            if p2.match(line):
                m1 = p2.match(line)
            if p4.match(line):
                m1 = p4.match(line)
            if m1:
                group = m1.groupdict()
                topo_dict.update({k:v.lower() for k,v in group.items() })
                continue
github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxr / show_lag.py View on Github external
continue

            # Destination address:  Not Configured
            p13_7 = re.compile(r'^Destination +address: *(?P[\w\s\.]+)$')
            m = p13_7.match(line)
            if m:
                group = m.groupdict()
                bfd_dict.update({'destination_address': group['destination_address']})
                continue

            # Port                  Device           State        Port ID         B/W, kbps
            # Gi0/0/0/0             Local            Active       0x000a, 0x0001     1000000
            m = p14.match(line)
            if m:
                group = m.groupdict()
                interface = Common.convert_intf_name(group.pop('interface'))
                bw_kbps = int(group.pop('bw_kbps'))
                port_dict = bundle_dict.setdefault('port', {}).setdefault(interface, {})
                port_dict.update({'interface': interface})
                port_dict.update({'bw_kbps': bw_kbps})
                port_dict.update({k : v for k, v in group.items()})
                interface_flag = True
                continue

            # Link is Active
            # Link is Standby due to maximum-active links configuration
            if interface_flag:
                interface_flag = False
                m = p15.match(line)
                if m:
                    group = m.groupdict()
                    port_dict.update({'link_state': group['link_state']})
github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxr / show_mpls.py View on Github external
# GigabitEthernet0/0/0/0     No       No       No       Yes
        p1 = re.compile(r'^(?P\S+) +(?PNo|Yes) +'
                r'(?PNo|Yes) +(?PNo|Yes) +'
                r'(?PNo|Yes)$')

        ret_dict = {}

        for line in out.splitlines():
            line = line.strip()

            # GigabitEthernet0/0/0/0     No       No       No       Yes
            m = p1.match(line)
            if m:
                group = m.groupdict()
                interface = Common.convert_intf_name(group.get('interface'))
                ldp = group.get('ldp')
                tunnel = group.get('tunnel')
                static = group.get('static')
                enabled = group.get('enabled')
                interface_dict = ret_dict.setdefault('interfaces', {}). \
                    setdefault(interface, {})
                interface_dict.update({'ldp' : ldp})
                interface_dict.update({'tunnel': tunnel})
                interface_dict.update({'static': static})
                interface_dict.update({'enabled': enabled})
                continue

        return ret_dict
github CiscoTestAutomation / genieparser / src / genie / libs / parser / nxos / show_ipv6.py View on Github external
p3 = re.compile(r'^(?P([\w\:]+)) +(?P([\w\.]+)) +(?P(\w+)) +(?P(\S+)) +'
                         '(?P(\S+))$')

        for line in out.splitlines():

            line = line.strip()

            # ICMPv6 Adjacency Table for all VRFs 
            m = p0.match(line)
            if m:
                continue

            # 2010:2:3::2     00:15:02  fa16.3e82.6320  STALE       Eth1/1      Eth1/1    
            m = p1.match(line)
            if m:
                interfaces = Common.convert_intf_name(m.groupdict()['interface'])
                interface = m.groupdict()['interface']
                ip = m.groupdict()['ip']
                age = m.groupdict()['age']
                mac_address = m.groupdict()['mac_address']
                state = m.groupdict()['state']
                phy_interface = m.groupdict()['phy_interface']

                interface_dict = ret_dict.setdefault('interfaces', {}).setdefault(interfaces, {})
                interface_dict['interface'] = interface
                interface_dict['phy_interface'] = phy_interface

                neighbor_dict = interface_dict.setdefault('neighbors', {}).setdefault(ip, {})
                neighbor_dict['ip'] = ip
                neighbor_dict['age'] = age
                neighbor_dict['mac_address'] = mac_address
                neighbor_dict['state'] = state