Building the python script

We will start by defining our switches. We want to back up their configuration as a text file and provide the credentials and access details separated by commas. This will allow us to use the split() function inside the python script to get the data and use it inside the ConnectHandler function. Also, the file can be easily exported and imported from a Microsoft Excel sheet or from any database.

The file structure is:

<device_ipaddress>,<username>,<password>,<enable_password>,<vendor>

Now we will start building our Python script by importing the file inside it, using the with open clause. We use the readlines()

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.