Read Configuration using Table/Views

343 views
Skip to first unread message

Sotiris Ioannou

unread,
Aug 21, 2014, 3:53:41 PM8/21/14
to junos-p...@googlegroups.com
Hi, 

I'm trying to understand on how to read the configuration out of a Junos device using Tables/Views. I have been through the github and I have found the examples given  for the SRX https://github.com/Juniper/py-junos-eznc/blob/master/lib/jnpr/junos/cfgro/srx.yml.
The Table in the example uses get to retrieve a configuration stanza. I have created a VRF query table below that is in a position to retrieve all the VRF instance names and I can succesfully load all VRF instance names. 

VRF Query table/view
 
VRF:
 get: routing-instances/instance
 args_key: name
 view: VRFView

VRFView:
 fields:
  instance_name: name

I would like to be in a position to retrieve entire sections of the configuration and group per instance, PyEZ techwiki specifies that configuration can be retrieved using Table/View, is there an example? My understanding is that get only returns the value of the field specified in the table.

Is there a way I can achieve this without using dev.cli('command')?

Thanks, 

Sotiris

NitinKumar

unread,
Aug 22, 2014, 12:30:12 PM8/22/14
to Sotiris Ioannou, junos-p...@googlegroups.com
Hi Sotiris,

Please try out this way:

Yaml file content (change according to your need):
VRF:
  get: routing-instances/instance
  args_key: name
  view: VRFView

VRFView:
 fields:
  instance_name: name
  instance_type: instance-type
  rd_type: route-distinguisher/rd-type
  vrf_import: vrf-import
  vrf_export: vrf-export


Code:
tbl = VRF(dev)
tbl.get(values=True) #make sure to pass values=True
for item in tbl:
    print 'instance_name:', item.instance_name
    print 'instance_type:', item.instance_type
    print 'rd_type:', item.rd_type
    print 'vrf_import:', item.vrf_import
    print 'vrf_export:', item.vrf_export

Above code was meant for below xml(output of "show routing-instances | display xml"), hence according to your need do change the YAML file:
            <routing-instances>
                <instance>
                    <name>blue-vr</name>
                    <instance-type>vrf</instance-type>
                    <interface>
                        <name>fe-0/0/2.0</name>
                    </interface>
                    <route-distinguisher>
                        <rd-type>10.58.255.1:37</rd-type>
                    </route-distinguisher>
                    <vrf-import>test-policy</vrf-import>
                    <vrf-export>test-policy</vrf-export>
                </instance>
                <instance>
                    <name>red-vr</name>
                    <instance-type>vrf</instance-type>
                    <interface>
                        <name>fe-0/0/3.0</name>
                    </interface>
                    <route-distinguisher>
                        <rd-type>10.58.255.1:38</rd-type>
                    </route-distinguisher>
                    <vrf-import>test-policy</vrf-import>
                    <vrf-export>test-policy</vrf-export>
                </instance>
            </routing-instances>

Hope that helps!

Thanks
Nitin Kr

--
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 http://groups.google.com/group/junos-python-ez.
To view this discussion on the web visit https://groups.google.com/d/msgid/junos-python-ez/2b4c5384-ef6a-4c0e-b678-d9f1aab079cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sotiris Ioannou

unread,
Aug 23, 2014, 7:28:16 AM8/23/14
to junos-p...@googlegroups.com, sotiris...@gmail.com, nit...@juniper.net
Hi Nitin,

Thanks for your guidance on this. I failed to spot that in the help files. :)

 RESERVED :kvargs:
 |        'values' - True/False*, when set to True will cause all data item
 |        values to be retrieved, not just the name-keys.
 |      
 |        'key' - used to retrieve the contents of the table record, and not
 |        just the list of keys (default) [when namesonly=True]

Regards,

Sotiris
Reply all
Reply to author
Forward
0 new messages