cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1198
Views
15
Helpful
3
Replies

Python Error when referencing yang variable with multiple keys

BasharAziz
Level 1
Level 1

Hi All, 

 

I am trying to reference an xpath of service A in service B. In service B will first lookup for devicename(key) and prefix id(key)

the third key is static [public='true']:

 

Service A:

/services/test:test[devicename='ww']/prefixes[prefix='6000'][public='true']/ipv4Address 200.1.1.1
/services/test:test[devicename='ww']/prefixes[prefix='6000'][public='false']/ipv4Address 172.1.1.1

 

Service B:

vars.add('ipv4Address', f'{root.services.devicename[service.Service_B_devicename].prefixes[service.prefix][public == "true"].ipv4Address}')
template.apply('netaccessevc-prefix-ipv4-template', vars)
 
 I am getting this error:
 
errors: reason: Python cb_create error. badly formatted or nonexistent path (8): Bad key "6000" (wrong number of identifiers) at: /services/test/prefixes
2 Accepted Solutions

Accepted Solutions

vleijon
Cisco Employee
Cisco Employee
The syntax for multi-key lists in the python api is [(key1, key2)]. So slightly different from xpath.

View solution in original post

gmuloche
Cisco Employee
Cisco Employee

Hello,

 

Looks like you are trying to get the value of the leaf

root.services.devicename["ww"].prefixes[6000,"true"].ipv4Address 

 inside the variable for your templates.

 

Couple of points here:

* As @vleijon mentioned the correct way to reference the leaf should use the python syntax for multi key list (you can look it up there: https://developer.cisco.com/docs/nso/guides/#!python-api-overview/maagic-api - subsection List and List Elements - there is no anchor at this hierarchy level so cannot point you to it directly)

* You actually don't need the f string

 

From what I understand from your model, a possible resolution in service B would be:

 

vars.add('ipv4Address'root.services.devicename[service.Service_B_devicename].prefixes[service.prefix,"true"].ipv4Address)

which *SHOULD* put the value of the leaf ipv4Address for (6000, "true") inside the variable you are then using in your template.

View solution in original post

3 Replies 3

vleijon
Cisco Employee
Cisco Employee
The syntax for multi-key lists in the python api is [(key1, key2)]. So slightly different from xpath.

baziz1
Level 1
Level 1

prefixes Is a list with two keys: prefix and public.

prefix is will be selected in service B, while public is always true. 

gmuloche
Cisco Employee
Cisco Employee

Hello,

 

Looks like you are trying to get the value of the leaf

root.services.devicename["ww"].prefixes[6000,"true"].ipv4Address 

 inside the variable for your templates.

 

Couple of points here:

* As @vleijon mentioned the correct way to reference the leaf should use the python syntax for multi key list (you can look it up there: https://developer.cisco.com/docs/nso/guides/#!python-api-overview/maagic-api - subsection List and List Elements - there is no anchor at this hierarchy level so cannot point you to it directly)

* You actually don't need the f string

 

From what I understand from your model, a possible resolution in service B would be:

 

vars.add('ipv4Address'root.services.devicename[service.Service_B_devicename].prefixes[service.prefix,"true"].ipv4Address)

which *SHOULD* put the value of the leaf ipv4Address for (6000, "true") inside the variable you are then using in your template.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: