Parsing the logical address family from show interface XML output

147 views
Skip to first unread message

Gavin McKee

unread,
Jan 18, 2016, 11:44:59 AM1/18/16
to Junos Python EZ
Hi,

I'm having an issue with my YAML file definition when parsing out the address families, can someone please advise.  My YAML file is shown below and some sample output in XML.  You can see that the Python call to show the items in the route table shows that the object AddressFamily contains 0 items.  I'm a little confused where I'm going wrong here, I've read must of the articles on how to do this - any help is greatly appreciated.


>>> from jnpr.junos.factory import loadyaml

>>> from jnpr.junos import Device

>>> from pprint import pprint as pp

>>> 

>>> globals().update(loadyaml('/home/*****/Documents/workspace/Test/interface.yml'))

>>> 

>>> 

>>> dir()

['Device', 'InterfaceTable', 'InterfaceView', '_AddressFamilyTable', '_AddressFamilyView', '_LogicalInterfaceTable', '_LogicalInterfaceView', '__builtins__', '__doc__', '__name__', '__package__', 'loadyaml', 'pp']

>>> dev = Device(host='R1',port=22,user='******',password='********)

>>> 

>>> dev.open()

Device(R1)

>>> 

>>> int_table = InterfaceTable(dev).get()

>>> 

>>> int = int_table['ge-0/0/1']

>>> 

>>> int_ifl = int.ifl

>>> 

>>> int_ifl.items()

[('ge-0/0/1.0', [('encapsulation', 'ENET2'), ('name', 'ge-0/0/1.0'), ('family', _AddressFamilyTable:R1: 0 items)])]




---
InterfaceTable:
  rpc: get-interface-information
  args:
    interface_name: '[fgx]e*'
  args_key: interface_name
  item: physical-interface
  view: InterfaceView

InterfaceView:
  fields:
   name: name
   admin-status: admin-status
   oper-status: oper-status
   description: description
   mtu: mtu
   source-filtering: source-filtering
   ifl: _LogicalInterfaceTable

_LogicalInterfaceTable:
   item: logical-interface
   view: _LogicalInterfaceView

_LogicalInterfaceView:
   fields:
    name: name
    encapsulation: encapsulation
    family: _AddressFamilyTable

_AddressFamilyTable:
  item: logical-interface/address-family
  view: _AddressFamilyView

_AddressFamilyView:
  name: address-family-name
  

The XML is as follows

gmckee@R1> show interfaces ge-0/0/1| display xml 

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.1X46/junos">

    <interface-information xmlns="http://xml.juniper.net/junos/12.1X46/junos-interface" junos:style="normal">

        <physical-interface>

            <name>ge-0/0/1</name>

            <admin-status junos:format="Enabled">up</admin-status>

            <oper-status>up</oper-status>

            <local-index>134</local-index>

            <snmp-index>507</snmp-index>

            <description>Link to R2 ge-0/0/1</description>

            <link-level-type>Ethernet</link-level-type>

            <mtu>1514</mtu>

            <source-filtering>disabled</source-filtering>

            <link-mode>Full-duplex</link-mode>

            <speed>1000mbps</speed>

            <bpdu-error>none</bpdu-error>

            <l2pt-error>none</l2pt-error>

            <loopback>disabled</loopback>

            <if-flow-control>enabled</if-flow-control>

            <if-auto-negotiation>enabled</if-auto-negotiation>

            <if-remote-fault>online</if-remote-fault>

            <if-device-flags>

                <ifdf-present/>

                <ifdf-running/>

            </if-device-flags>

            <if-config-flags>

                <iff-snmp-traps/>

                <internal-flags>0x4000</internal-flags>

            </if-config-flags>

            <if-media-flags>

                <ifmf-none/>

            </if-media-flags>

            <physical-interface-cos-information>

                <physical-interface-cos-hw-max-queues>8</physical-interface-cos-hw-max-queues>

                <physical-interface-cos-use-max-queues>8</physical-interface-cos-use-max-queues>

            </physical-interface-cos-information>

            <current-physical-address>08:00:27:c3:34:11</current-physical-address>

            <hardware-physical-address>08:00:27:c3:34:11</hardware-physical-address>

            <interface-flapped junos:seconds="573873">2016-01-11 14:40:31 UTC (6d 15:24 ago)</interface-flapped>

            <traffic-statistics junos:style="brief">

                <input-bps>200</input-bps>

                <input-pps>0</input-pps>

                <output-bps>952</output-bps>

                <output-pps>0</output-pps>

            </traffic-statistics>

            <active-alarms>

                <interface-alarms>

                    <alarm-not-present/>

                </interface-alarms>

            </active-alarms>

            <active-defects>

                <interface-alarms>

                    <alarm-not-present/>

                </interface-alarms>

            </active-defects>

            <interface-transmit-statistics>Disabled</interface-transmit-statistics>

            <logical-interface>

                <name>ge-0/0/1.0</name>

                <local-index>77</local-index>

                <snmp-index>518</snmp-index>

                <if-config-flags>

                    <iff-snmp-traps/>   

                    <internal-flags>0x4000</internal-flags>

                </if-config-flags>

                <encapsulation>ENET2</encapsulation>

                <traffic-statistics junos:style="brief">

                    <input-packets>146094</input-packets>

                    <output-packets>128250</output-packets>

                </traffic-statistics>

                <filter-information>

                </filter-information>

                <logical-interface-zone-name>Null</logical-interface-zone-name>

                <allowed-host-inbound-traffic>

                </allowed-host-inbound-traffic>

                <address-family>

                    <address-family-name>inet</address-family-name>

                    <mtu>1500</mtu>

                    <address-family-flags>

                        <ifff-sendbcast-pkt-to-re/>

                    </address-family-flags>

                    <interface-address>

                        <ifa-flags>

                            <ifaf-current-preferred/>

                            <ifaf-current-primary/>

                        </ifa-flags>

                        <ifa-destination>192.168.86.28/30</ifa-destination>

                        <ifa-local>192.168.86.30</ifa-local>

                        <ifa-broadcast>192.168.86.31</ifa-broadcast>

                    </interface-address>

                </address-family>

                <address-family>

                    <address-family-name>mpls</address-family-name>

                    <mtu>1488</mtu>

                    <maximum-labels>3</maximum-labels>

                    <address-family-flags>

                        <internal-flags>0x10000000</internal-flags>

                    </address-family-flags>

                </address-family>

            </logical-interface>

        </physical-interface>

    </interface-information>

    <cli>

        <banner></banner>

    </cli>

</rpc-reply>


Gavin McKee

unread,
Jan 18, 2016, 3:15:45 PM1/18/16
to Junos Python EZ
    fields: 

Ganesh Nalawade

unread,
Jan 18, 2016, 11:33:35 PM1/18/16
to Gavin McKee, Junos Python EZ
Hi Gavin,

Minor changes are required in your yml file.
1) Specify key value in '_AddressFamilyTable' as default key is not 'name' in this case.
2) 'fields' tag is missing in '_AddressFamilyView'

I have modify your yml file as below. Please let me know if it works for you.
  key: address-family-name
item: address-family
view: _AddressFamilyView

_AddressFamilyView:
fields:
    name: address-family-name 


>>> int_table = InterfaceTable(dev).get()
>>> int =
int_table['ge-0/0/1'
]
>>> int_ifl = int.ifl[
'ge-0/0/1.0']
>>> int_family = int_ifl.family
>>> int_family.items()
[('inet', [('name', 'inet')]), ('mpls', [('name', 'mpls')])]

Regards,
Ganesh

--
You received this message because you are subscribed to the Google Groups "Junos Python EZ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to junos-python-...@googlegroups.com.
Visit this group at https://groups.google.com/group/junos-python-ez.
To view this discussion on the web visit https://groups.google.com/d/msgid/junos-python-ez/bb5d1528-8f0d-4fa9-9035-ae96a45ffffe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gavin McKee

unread,
Jan 19, 2016, 9:00:12 AM1/19/16
to Junos Python EZ
Hi Ganesh,

Thanks for the fix that works great.  Could you help me understand extracting the interface address tags and flags from the XML.  I think this should help me close the loop on parsing out many nested values.  I'm unsure if I should use groups, sub tables etc.

Thanks

Gav 


On Monday, 18 January 2016 11:44:59 UTC-5, Gavin McKee wrote:
Reply all
Reply to author
Forward
0 new messages