Configuring devices using netmiko

Netmiko can be used to configure remote devices over SSH. It does that by accessing config mode using the .config method and then applies the configuration given in list format. The list itself can be provided inside the Python script or read from the file, then converted to a list using the readlines() method:

from netmiko import ConnectHandlerSW2 = {    'device_type': 'cisco_ios',    'ip': '10.10.88.112',    'username': 'admin',    'password': 'access123',    'secret': 'access123',}core_sw_config = ["int range gig0/1 - 2","switchport trunk encapsulation dot1q",                  "switchport mode trunk","switchport trunk allowed vlan 1,2"]print "########## Connecting to Device {0} ############".format(SW2['ip'])net_connect = ConnectHandler ...

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.