How to use the genie.libs.parser.utils.common.Common 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 / iosxr / show_static_routing.py View on Github external
af_dict['table_id'] = table_id
                continue

            m = p2.match(line)

            if m:
                next_hop = ""

                if m.groupdict()['route']:
                    route = m.groupdict()['route'].strip()
                    index = 1
                else:
                    index += 1

                if m.groupdict()['interface'] and 'none' not in m.groupdict()['interface'].lower():
                    interface = Common.convert_intf_name(m.groupdict()['interface'].replace('_','/'))
                if m.groupdict()['nexthop'] and 'none' not in m.groupdict()['nexthop'].lower():
                    next_hop = m.groupdict()['nexthop']

                if m.groupdict()['metrics']:
                    metrics_value = m.groupdict()['metrics'].strip('[').strip(']').split('/')
                    metrics = int(metrics_value[4])
                    preference = int(metrics_value[2])

                if m.groupdict()['object'] and 'none' not in m.groupdict()['object'].lower() :
                    object = m.groupdict()['object']

                if m.groupdict()['explicit_path'] and 'none' not in m.groupdict()['explicit_path'].lower():
                    explicit_path = m.groupdict()['explicit_path']
                
                local_label = m.groupdict()['local_label']
                path_event = m.groupdict()['path_event']
github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxe / show_lldp.py View on Github external
# Total entries displayed: 4
            m = p1.match(line)
            if m:
                parsed_output['total_entries'] = int(m.groupdict()['entry'])
                continue

            # Device ID           Local Intf     Hold-time  Capability      Port ID
            # router               Gi1/0/52       117        R               Gi0/0/0
            # 10.10.191.107       Gi1/0/14       155        B,T             7038.eeff.572d
            # d89e.f3ff.58fe      Gi1/0/33       3070                       d89e.f3ff.58fe
            m = p2.match(line)
            if m:
                group = m.groupdict()

                intf = Common.convert_intf_name(group['interfaces'])
                device_dict = parsed_output.setdefault('interfaces', {}). \
                                          setdefault(intf, {}). \
                                          setdefault('port_id', {}). \
                                          setdefault(group['port_id'], {}).\
                                          setdefault('neighbors', {}). \
                                          setdefault(group['device_id'], {})

                device_dict['hold_time'] = int(group['hold_time'])

                if group['capabilities']:
                    capabilities = list(map(lambda x: x.strip(), group['capabilities'].split(',')))
                    device_dict['capabilities'] = capabilities


            continue
github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxr / show_spanning_tree.py View on Github external
vlan.update({k:int(v) for k, v in group.items()})
				continue

			# Transmit Hold count   6
			m = p6.match(line)
			if m:
				group = m.groupdict()
				vlan.update({k:int(v) for k, v in group.items()})
				continue

			# Gi0/7/0/0	128.1   20000	 DSGN FWD   32768 8cb6.4fff.6588 128.1
			m = p7.match(line)
			if m:
				group = m.groupdict()
				interfaces = vlan.setdefault('interface' , {}). \
					setdefault(Common.convert_intf_name(group['name']), {})
				interfaces.update({'name' : Common.convert_intf_name(group['name'])})
				interfaces.update({'cost' : int(group['cost'])})
				interfaces.update({'role' : group['role']})
				interfaces.update({'port_priority' : int(group['port_priority'])})
				interfaces.update({'port_num' : int(group['port_num'])})
				interfaces.update({'port_state' : group['port_state']})
				interfaces.update({
					'designated_bridge_priority':int(group['designated_bridge_priority'])})
				interfaces.update({
					'designated_bridge_address':group['designated_bridge_address']})
				interfaces.update({
					'designated_port_priority':int(group['designated_port_priority'])})
				interfaces.update({
					'designated_port_num':int(group['designated_port_num'])})
				continue
		return ret_dict
github CiscoTestAutomation / genieparser / src / genie / libs / parser / nxos / show_lag.py View on Github external
line = line.strip().replace('\xa0', ' ')
            else:
                continue

            # port-channel1
            m = p1.match(line)
            if m:
                port_channel = Common.convert_intf_name(m.group()).capitalize()
                intf_dict = parsed_dict.setdefault('interfaces', {}).setdefault(
                    port_channel, {})
                continue

            m = p2.match(line)
            if m:
                group = m.groupdict()
                interface = Common.convert_intf_name(group["interface"]).capitalize()
                member_dict = intf_dict.setdefault('members', {}).setdefault(interface,
                                                                             {})
                member_dict.update({'interface': interface})
                counter_dict = member_dict.setdefault('counters', {})
                counter_dict.update({'lacp_in_pkts': int(group['lacp_in_pkts'])})
                counter_dict.update({'lacp_out_pkts': int(group['lacp_out_pkts'])})
                counter_dict.update({'marker_resp_in_pkts': int(group['marker_in_pkts'])})
                counter_dict.update(
                    {'marker_resp_out_pkts': int(group['marker_out_pkts'])})
                counter_dict.update({'lacp_errors': int(group['lacp_pkts_errors'])})
                continue

        return parsed_dict
github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxr / show_lldp.py View on Github external
intf = Common.convert_intf_name(group['local_interface'])
                intf_dict = ret_dict.setdefault('interfaces', {}).setdefault(intf, {})
                continue
            
            # Chassis id: 001e.49ff.24f7
            m = p2.match(line)
            if m:
                group = m.groupdict()
                sub_dict.update({'chassis_id': group['chassis_id']})
                continue
            
            # Port id: Gi1/0/4
            m = p3.match(line)
            if m:
                group = m.groupdict()
                port_id = Common.convert_intf_name(group['port_id'])
                port_dict = intf_dict.setdefault('port_id', {}). \
                    setdefault(port_id, {})
                
                continue

            # Port Description: GigabitEthernet1/0/4
            # Port Description - not advertised
            # Port Description: to genie-3 genie 0/0/1/1 via genie3.genie 00-01
            # Port Description: 10G to bl2-genie port Ge8/8/8:GG8
            # Port Description: "10G link to Genie2 port Ge8/8/8/8/8"
            # Port Description: 10G link to genie3-genie port GEN 8/8/8/8 in BE 43 (with port 0/4/0/3)
            m = p4.match(line)
            if m:
                group = m.groupdict()
                sub_dict.setdefault('port_description', group['port_description'])
                continue
github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxe / show_interface.py View on Github external
if m:
                ret_dict[intf]['addresses_config_method'] = \
                    m.groupdict()['addr_conf_method']
                continue

            # Interface is unnumbered. Using address of Loopback0
            p19 =  re.compile(r'^Interface +is +unnumbered. +Using +address +of'
                               ' +(?P[\w\/\.]+)$')
            m = p19.match(line)
            if m:
                if 'ipv6' not in ret_dict[intf]:
                    ret_dict[intf]['ipv6'] = {}
                if 'unnumbered' not in ret_dict[intf]['ipv6']:
                    ret_dict[intf]['ipv6']['unnumbered'] = {}
                ret_dict[intf]['ipv6']['unnumbered']['interface_ref'] = \
                    Common.convert_intf_name(m.groupdict()['unnumbered_intf'])
                continue

            # No global unicast address is configured
            p20 =  re.compile(r'^No +global +unicast +address +is +configured$')
            m = p20.match(line)
            if m:
                if 'ipv6' not in ret_dict[intf]:
                    ret_dict[intf]['ipv6'] = {}

                ret_dict[intf]['ipv6']['enabled'] = False
                continue
        return ret_dict
github CiscoTestAutomation / genieparser / src / genie / libs / parser / iosxr / show_xconnect.py View on Github external
if m:
                group = m.groupdict()
                name_dict['status'] = str(group['status_group'])
                segment1_dict = name_dict.setdefault('segment1',{}) \
                    .setdefault(Common.convert_intf_name(group['segment_1'].strip()), {})
                continue
            
            # T-0-4-0-2  UR   10.154.219.98    4293089094
            m = p7.match(line)
            if m:
                group = m.groupdict()
                name_dict = group_dict.setdefault('name', {}) \
                        .setdefault(group['name'], {})
                name_dict['status'] = str(group['status_group'])
                segment1_dict = name_dict.setdefault('segment1',{}) \
                    .setdefault(Common.convert_intf_name(group['segment_1'].strip()), {})
                continue
        return ret_dict
github CiscoTestAutomation / genieparser / src / genie / libs / parser / nxos / show_fdb.py View on Github external
vlan = str(group['vlan'])
                vlan_dict = ret_dict.setdefault('mac_table', {})\
                .setdefault('vlans', {}).setdefault(vlan, {})
                vlan_dict.update({'vlan': str(vlan)})
                mac_address = str(group['mac_address'])
                mac_dict = vlan_dict.setdefault('mac_addresses', {})\
                .setdefault(mac_address,{})
                mac_dict.update({'mac_address': mac_address})
                if group['entry']:
                    mac_dict.update({'entry': str(group['entry']).strip()})
                if not str(group['drop']) == 'None':
                    intf_dict = mac_dict.setdefault('drop',{})
                    intf_dict.update({'drop': True})
                port = str(group['ports'])
                if not port == 'None':
                    converted_port = Common.convert_intf_name(group['ports'])
                    intf_dict = mac_dict.setdefault('interfaces',{})\
                    .setdefault(converted_port,{})
                    intf_dict.update({'interface': converted_port})
                mac_type = str(group['mac_type'])
                age = str(group['age'])
                secure = str(group['secure'])
                ntfy = str(group['ntfy'])
                intf_dict.update({'mac_type': str(group['mac_type'])})
                intf_dict.update({'age': str(group['age'])})                
                mac_dict.update({'secure': str(group['secure'])})
                mac_dict.update({'ntfy': str(group['ntfy'])})
                continue
                
        return ret_dict
github CiscoTestAutomation / genieparser / src / genie / libs / parser / nxos / show_nd.py View on Github external
m = p1.match(line)
            if m:
                group = m.groupdict()
                vrf = group.pop('vrf')
                continue

            m = p2.match(line)
            if m:
                group = m.groupdict()
                if group.get('neighbor'):
                    neighbor = group.pop('neighbor')

                if group.get('interface'):
                    interface_original = group.pop('interface')
                    interface = Common.convert_intf_name(interface_original)
                    interface_dict = result_dict.setdefault('interfaces', {}).setdefault(interface, {})
                    interface_dict.update({'interface': interface})

                    neighbor_dict = interface_dict.setdefault('neighbors',{}).setdefault(neighbor,{})

                    neighbor_dict.update({'ip': neighbor})
                    neighbor_dict.update({'link_layer_address': group.pop("link_layer_address")})
                    neighbor_dict.update({'neighbor_state': group.pop("neighbor_state").lower()})
                    neighbor_dict.update({'age': group.pop("age")})
                    neighbor_dict.update({'physical_interface': Common.convert_intf_name(group.pop("physical_interface"))})
                continue

        return result_dict
github CiscoTestAutomation / genieparser / src / genie / libs / parser / nxos / show_ipv6.py View on Github external
neighbor_dict['age'] = age
                neighbor_dict['mac_address'] = mac_address
                neighbor_dict['state'] = state
                continue

            # fe80::f816:3eff:fe82:6320
            m = p2.match(line)
            if m:
                ip = m.groupdict()['ip']
                ip_flag = 1
                continue

            #                 00:18:33  fa16.3e82.6320  STALE       Eth1/1      Eth1/1    
            m = p3.match(line)
            if m:
                interfaces = Common.convert_intf_name(m.groupdict()['interface'])
                interface = m.groupdict()['interface']
                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

                if ip_flag == 1:
                    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