03-20-2025 09:01 AM - editado 03-20-2025 09:03 AM
Hello experts
I’m trying to get configuration with python netmiko from IOS_XR devices in production environment,
the following code works for me in my labs, but not in production devices, the devices have big config (111.000 lines of config)
I’m not sure if there are a way configure the scrip to wait until it gets the right config,
time.sleep(60) options doesn’t work.
thanks.
try:
with ConnectHandler(**datos) as net_connect:
print("Ejecutando comandos ...")
output = net_connect.send_command("sh running-config formal interface | i description ")
#time.sleep(60)
# Imprimir el resultado
print("Resultado del comando:")
print(output)
# Cerrar la conexión
net_connect.disconnect()
except:
print(f'{item} NO_CONECTA')
el 03-20-2025 09:40 AM
what is the error you getting, try with expect
el 03-20-2025 09:48 AM
There is a couple of optional buttons/knobs to tweak here from what i reacall. You can set the net_connect.timeout to equal say 300, which would allow you more connection before the timeout, also increase your delay_factor, as this multiplies the default wait time, giving your device more time to respond. A couple which have read about but not tried is max_loops, which should increases the number of attempts to get complete output and the read_timeout, that gives more time for each read operation.
In all cases, you might need to adjust the numbers here for your use case, its a little trial and error. Following this, you could try this which would give you more control over the reading process for super large outputs.
output = ""
command = "sh running-config formal interface | i description"
net_connect.write_channel(f"{command}\n")
time.sleep(2) # Give initial time for command to start
# Keep reading until prompt is found
while True:
new_data = net_connect.read_channel()
output += new_data
if net_connect.check_config_mode() or net_connect.base_prompt in new_data:
break
time.sleep(1) # Small pause between reads
el 03-20-2025 10:37 AM
Hi guys
thank you for your help, the information was very useful.
I used the option, read_timeout=60
it worked for me.
regards.
output = net_connect.send_command(
"sh running-config formal interface | i description",
read_timeout=60
)
Descubra y salve sus notas favoritas. Vuelva a encontrar las respuestas de los expertos, guías paso a paso, temas recientes y mucho más.
¿Es nuevo por aquí? Empiece con estos tips. Cómo usar la comunidad Guía para nuevos miembros
Navegue y encuentre contenido personalizado de la comunidad