Exit from file of commands with Netmiko

Viewed 223

I have a problem in my Python script because I send command from my file text.txt to my Cisco router but I don't have the possibility to exit from the command line.

Python code:

device.config_mode()
device.send_config_from_file(config_file="text.txt")
device.exit_config_mode()

text.txt

interface loopback 10.10.10.10
  description LO
  ip adress 10.10.10.10 255.255.255.0
exit
  vrf definition VRF 10
  description vrf
  ...

The exit command does not work.

1 Answers

you can use these config :

from netmiko import ConnectHandler
from getpass import getpass

cisco_Router = {
    "device_type": "cisco_ios",
    "host": "IPaddress",
    "username": "username",
    "password": "password",
    "secret": "enable_password"}

with ConnectHandler(**cisco_Router) as net_connect:
    
    net_connect.enable()
    output = net_connect.send_config_from_file('config_file.txt')

    net_connect.disconnect()
Related