10-19-2017 09:13 AM - edited 03-01-2019 04:01 AM
I can't figure out how to create a key value pair via python maagic api.
I have an ciso ios-xr device and want to add a community-set. Like this:
community-set CS-CORE_REGION_ID-LOCAL
39651:1099
end-set
I have the community-set defined in ncs but without any value:
admin@ncs% show devices device sth0-ser0 config cisco-ios-xr:community-set CS-CORE_REGION_ID-LOCAL | display json
{
"data": {
"tailf-ncs:devices": {
"device": [
{
"name": "sth0-ser0",
"config": {
"tailf-ned-cisco-ios-xr:community-set": [
{
"name": "CS-CORE_REGION_ID-LOCAL"
}
]
}
}
]
}
}
}
[ok][2017-10-19 18:02:39]
I can create a new key "set" by:
for cs in root.devices.device[bng_id[0]["name"]].config.cisco_ios_xr__community_set:
if cs.name == "CS-CORE_REGION_ID-LOCAL":
rt_val = "39651:" + bng_id[0]["region_cs"]
cs.set.create
cs.set["value"].create
cs.set.value = rt_val
print(cs.set)
I get te following output error when running the script:
Traceback (most recent call last):
File "import-sp-data-itux-bng-ver1.py", line 153, in <module>
main()
File "import-sp-data-itux-bng-ver1.py", line 149, in main
set_sp_id(bng_id)
File "import-sp-data-itux-bng-ver1.py", line 75, in set_sp_id
cs.set["value"].create
File "/home/peter/ncs-4.4.2/src/ncs/pyapi/ncs/maagic.py", line 1037, in __getitem__
raise KeyError('%s not in %s' % (keystr, self._path))
KeyError: '{value} not in /ncs:devices/device{sth0-ser0}/config/cisco-ios-xr:community-set{CS-CORE_REGION_ID-LOCAL}/set'
Any idea what needs to be changed?
Solved! Go to Solution.
10-19-2017 11:15 PM
Thanks Fredrik, you guided me in the correct direction.
s = cs.set.create(rt_val)
Did the work.
10-19-2017 05:35 PM
Not sure about the YANG model here, but I have two ideas:
cs.set.value = rt_val
- OR -
s = cs.set.create()
s.value = rt_val
10-19-2017 11:15 PM
Thanks Fredrik, you guided me in the correct direction.
s = cs.set.create(rt_val)
Did the work.
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