cancelar
Mostrando los resultados de 
Buscar en lugar de 
Quiere decir: 
cancel
899
Visitas
0
ÚTIL
3
Respuestas

Support for context manager

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

1 SOLUCIÓN ACEPTADA

Soluciones aceptadas

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

Ver la solución en mensaje original publicado

3 RESPUESTAS 3

einarnn
Cisco Employee
Cisco Employee

David,

Which "manager" class are you referring to?

Cheers,

Einar

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

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