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

Using python netmiko from IOS_XR

f4cruz
Level 1
Level 1

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')

 

3 RESPUESTAS 3

balaji.bandi
Hall of Fame
Hall of Fame

what is the error you getting, try  with expect

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

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

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

f4cruz
Level 1
Level 1

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
)