cisco id is -- cisco extended id number is 16 """ # the parsergen requires a list[tuple] to determine how to process the # text. in every case, we need to only provide the interface name; and # then have parsergen extract all other attributes. The following code # sets up the dictionary that is then passed as a list of tuple items. MARKUP_LOOKUP = { f'{MARKUP_PREFIX}.{attr}': None for attr in ['ifname', 'present', 'type', 'vendor', 'part_number', 'serial_number'] } pg.extend_markup(MARKUP_CONTENT) def parse_interface_block(ifname, cli_text): lookup = copy(MARKUP_LOOKUP) lookup[f'{MARKUP_PREFIX}.ifname'] = ifname # the following call will create a parser that we can then invoke # notice that we use the device_os and device_output params here to # pass the original CLI text output multiple times through # parsergen. parser = pg.oper_fill(device_os=OS, device_output=cli_text, show_command=('SHOW_INTF_<NAME>_XCVRS', [], {
0.0.0.0 from 0.0.0.0 (4.4.4.4) Origin incomplete, metric 0, localpref 100, weight 32768, valid, redistributed, best, group-best Received Path ID 0, Local Path ID 0, version 4 MARKUP: XW<date>XWed Jul 12 15:23:42.143 EDT BGP instance 0: 'default' ========================= Address Family: XXX<[a-zA-Z0-9\s]+><address_family>XXXIPv4 Unicast ---------------------------- BGP routing table entry for XA<ip_address>X10.3.4.0/34 Versions: Process bRIB/RIB SendTblVer Speaker 4 4 Last Modified: Jul 9 08:46:14.166 for 3d06h Paths: (1 available, best #1) Not advertised to any peer Path #1: Received by speaker 0 Not advertised to any peer Local 0.0.0.0 from 0.0.0.0 (4.4.4.4) Origin incomplete, metric 0, localpref XN<localpref_number>X100, weight 32768, valid, redistributed, best, group-best Received Path ID 0, Local Path ID 0, version 4 ''' pg.extend_markup(dedent(marked_up_show_bgp_all_all_all_instance))
trunk.native_is_svlan: XN<trunk.native_is_svlan>X0 trunk.qinq_tunneling_etype: XH<trunk.qinq_tunneling_etype>X0x8100 trunk.mac_acc_ingress: XN<trunk.mac_acc_ingress>X0 trunk.mac_acc_egress: XN<trunk.mac_acc_egress>X0 trunk.filter_dot1q: XN<trunk.filter_dot1q>X0 trunk.filter_dot1ad: XN<trunk.filter_dot1ad>X0 trunk.filter_mac_relay: XN<trunk.filter_mac_relay>X0 sub.parent: XH<sub.parent>X0x00000100 sub.admin_up: XN<sub.admin_up>X0 EFP MATCH: XR<sub.efp_match>X(none) EFP REWRITE: XR<sub.efp_rewrite>X(none) Unicast MAC Addresses: XN<unicast_mac_addr>X0 ''' pg.extend_markup(marked_up_show_interface_xrvr_output) show_cmds = { 'iosxr': { 'SHOW_ARP': "show arp", }, 'ios': { 'SHOW_ARP': "show arp", }, 'iosxe': { 'SHOW_ARP': "show arp", }, 'nxos': { 'SHOW_ARP': "show {=ip} arp", }, 'aireos': {
from genie.conf import Genie from genie import parsergen from pprint import pprint #open marked up text file and read into variable f = open('markup.txt', 'r') markedupIOSX = f.read() #initiate testbed testbed = Genie.init('vagrant_multi_ios.yaml') uut = testbed.devices.iosxe1 uut.connect() #extend parsergen markup with text file indicating elements to parse parsergen.extend_markup(markedupIOSX) #identify which parsed element to check as true attrValPairsToCheck = [ ('nve.intf.encap', 'Vxlan'), ] #parsergen will connect to device and issue show nve interface nve1 #Will check for elements to be parsed and create a dictionary pgfill = parsergen.oper_fill(device=uut, show_command=\ ('show_nve_interface', [], {'ifname':'nve1'}), attrvalpairs=attrValPairsToCheck, refresh_cache=True, regex_tag_fill_pattern='nve\.intf') result = pgfill.parse()
Tx 33 output packets 1 unicast packets 29 multicast packets 3 broadcast packets 6527 bytes MARKUP: XW<if_name>Xmgmt0 is XR<line_protocol>Xup admin state is XR<admin_state>Xup Hardware: XW<hardware>XEthernet, address: XM<mac_address>X5254.0070.0dff (bia XM<bia_address>X5254.0070.0dff) Internet Address is XXX<[0-9\.]+><ip_address>XXX10.10.10.5/24 MTU XN<mtu>X1500 bytes, BW XN<bw>X0 Kbit, DLY XN<dly>X10 usec reliability XXX<[0-9/]+><reliability>XXX255/255, txload XXX<[0-9/]+><txload>XXX1/255, rxload XXX<[0-9/]+><rxload>XXX1/255 Encapsulation XW<encapsulation>XARPA, medium is broadcast Port mode is XR<port_mode>Xrouted XW<duplex>Xauto-duplex, XW<speed>Xauto-speed Auto-Negotiation is turned XR<auto_negotiation>Xon Auto-mdix is turned XR<auto_mdix>Xoff EtherType is XH<ether_type>X0x0000 1 minute input rate XN<input_bits_sec_60>X112 bits/sec, XN<input_packets_sec_60>X0 packets/sec 1 minute output rate XN<output_bits_sec_60>X24 bits/sec, XN<output_packets_sec_60>X0 packets/sec Rx XN<input_packets>X71 input packets XN<rx.unicast>X2 unicast packets XN<rx.multicast>X68 multicast packets XN<rx.broadcast>X1 broadcast packets XN<rx.bytes>X22451 bytes Tx XN<output_packets>X33 output packets XN<tx.unicast>X1 unicast packets XN<tx.multicast>X29 multicast packets ''' extend_markup(marked_up_output)