05-07-2020 05:29 PM - edited 05-07-2020 05:30 PM
Hi Dev'ers,
I'm hoping you can help. I have a service model that's built with python code and I'm trying to pull the address address off the lo0.0 interface of a Juniper. My python code errors out on "commit dry-run" with the error:
Aborted: Python cb_create error. '{0} not in /ncs:devices/device{juniper-rtr}/config/junos:configuration/interfaces/interface{lo0}/unit{0}/family/inet/address'
I've verified that the {0} it's referencing is the address[0] seen below. Here's a snippet of the python code that's failing, marked with ****:
if "junos" in device_type: device_config = root.ncs__devices.ncs__device[member_name].ncs__config loopback = device_config.junos__configuration.interfaces.interface['lo0'] if loopback.unit['0'].family.inet.address: **** loopback_ip = loopback.unit['0'].family.inet.address[0].name ip, mask = loopback_ip.split('/') octets = ip.split('.') isis['lo0_v4'] = service.area_id + ".0000.0000." + octets[2].zfill(4) + "." + octets[3].zfill(4) + ".00"
Here's what Postman returns for "family inet", as you can see there are multiple IPs.
<inet xmlns="http://xml.juniper.net/xnm/1.1/xnm" xmlns:junos="http://xml.juniper.net/xnm/1.1/xnm" xmlns:ncs="http://tail-f.com/ns/ncs"> <address> <name>1.2.3.4/32</name> </address> <address> <name>127.0.0.1/32</name> </address> <address> <name>10.255.0.3/32</name> <primary/> <preferred/> </address> </inet>
These IPs are not known to the Python code, so the address(es) need to be referenced more generally. In fact, I prefer to pull *only* the "primary" IP, but am unable to do so. Does anyone know if this is possible? Thanks!
Solved! Go to Solution.
05-08-2020 01:41 PM
So, 'address' here is defined as a yang list with 'name' as the list key.
admin@ncs% show devices device j-0 config junos:configuration interfaces interface lo0 unit 0 family inet address | display xpath
/devices/device[name='j-0']/config/junos:configuration/interfaces/interface[name='lo0']/unit[name='0']/family/inet/address[name='192.168.1.1/32']
/devices/device[name='j-0']/config/junos:configuration/interfaces/interface[name='lo0']/unit[name='0']/family/inet/address[name='10.0.1.0/24']
[ok][2020-05-08 15:58:27]
In your case, using address[0] -> address[name=0] in which case it will not find that entry in the list.
Looping over the entries in the list will get the address of each entry,
Unfortunately, I am not familiar with what NSO300 presents.
05-08-2020 12:25 PM
I found that looping through them is effective. I think that, unless there's a way to access the list by address[0] (etc), it invalidates some of Cisco's documentation in NSO300 about how to access these entries.
Has anyone else run into this? Also, looking over the approach above, is this how folks are generally accessing and manipulating data before sending to the template?
05-08-2020 01:41 PM
So, 'address' here is defined as a yang list with 'name' as the list key.
admin@ncs% show devices device j-0 config junos:configuration interfaces interface lo0 unit 0 family inet address | display xpath
/devices/device[name='j-0']/config/junos:configuration/interfaces/interface[name='lo0']/unit[name='0']/family/inet/address[name='192.168.1.1/32']
/devices/device[name='j-0']/config/junos:configuration/interfaces/interface[name='lo0']/unit[name='0']/family/inet/address[name='10.0.1.0/24']
[ok][2020-05-08 15:58:27]
In your case, using address[0] -> address[name=0] in which case it will not find that entry in the list.
Looping over the entries in the list will get the address of each entry,
Unfortunately, I am not familiar with what NSO300 presents.
05-08-2020 03:33 PM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide