06-14-2017 02:11 PM
Can we add a support for context manager so we can use 'with' statement to ensure every manager is closed properly?
Need dunder __enter__ and __exit__ added to the manager class.
Thanks,
David
Solved! Go to Solution.
06-15-2017 09:16 AM
I agree that this would be a good enhancement for the ServiceProvider classes. Feel free to raise an issue for this on github and we will address it Issues · CiscoDevNet/ydk-gen · GitHub
06-15-2017 07:21 AM
David,
Which "manager" class are you referring to?
Cheers,
Einar
06-15-2017 08:31 AM
Sorry I meant for the service provider.
Without a support for 'with' statement, we have to wrap the service provider in a try/finally block. Like
this..
sp_instance = NetconfServiceProvider(address='1.1.1.1', port=830, username='cisco', password='cisco', protocol='ssh')
try:
do something
finally:
sp_instance.close()
Many network engineers who may not necessarily have programming experience may forget to close the session, and that leaves netconf session opened on the router. If we do this enough we may exhaust session resources on the router/switch.
Can we add the dunder enter/exit method on the provider class so we can do this ...
with NetconfServiceProvider(....) as xr:
do something
and the exit method will always properly close the session.
Thanks,
David
06-15-2017 09:16 AM
I agree that this would be a good enhancement for the ServiceProvider classes. Feel free to raise an issue for this on github and we will address it Issues · CiscoDevNet/ydk-gen · GitHub
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