09-15-2022 02:16 AM
Hello, I am trying to access nso service attributes with ncs_pycli to write a code in python.
This works and I can navigate to all services:
In [12]: for i in root.ncs__services:
...:
...: print(i)
...:
ncs:global-settings
ncs:properties
ncs:customer-service
ncs:service
ncs:logging
ncs:commit-queue-notifications
ncs:plan-notifications
device-provisioning:device-provisioning
leaf-sw:leaf-sw
sbc-vpn:sbc-vpn
vpn:vpn
ncs:check-sync
and for vpn service works as well, I can retrieve the vrf id:
In [4]: for i in root.ncs__services.vpn:
...:
...: print(i.vrf)
...:
...:
...:
555
sbc-vpn service is not recognized and I can not access any attribute, has the same service skeleton(python):
In [5]: for i in root.ncs__services.sbc-vpn:
...:
...: print(i.vrf-id)
...:
...:
...:
...:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.6/site-packages/ncs_pycli/ncs_pycli.py in <module>
----> 1 for i in root.ncs__services.sbc-vpn:
2
3 print(i.vrf-id)
4
5
~/nso-5.6.1/src/ncs/pyapi/ncs/maagic.py in __getattr__(self, name)
476 return child
477 else:
--> 478 super(Node, self).__getattribute__(name)
479
480 def __setattr__(self, name, value):
AttributeError: 'Container' object has no attribute 'sbc'
In [6]:
Solved! Go to Solution.
09-15-2022 03:38 AM
Hyphen is not a valid character in a python variable, so you need to use underscore in its place when you're using maagic:
for i in root.ncs__services.sbc_vpn:
print(i)
09-15-2022 03:38 AM
Hyphen is not a valid character in a python variable, so you need to use underscore in its place when you're using maagic:
for i in root.ncs__services.sbc_vpn:
print(i)
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