취소
다음에 대한 결과 표시 
다음에 대한 검색 
다음을 의미합니까? 
cancel
2113
VIEWS
15
Helpful
3
답글

Python Error when referencing yang variable with multiple keys

BasharAziz
Level 2
Level 2

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 채택된 솔루션

채택된 솔루션

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

원본 게시물의 솔루션 보기

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.

원본 게시물의 솔루션 보기

3 응답 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
Community Member

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.