Netmiko in a Multivendor Environment: Cisco & Arista Configuration

Andrei Dumitrescu
A free video tutorial from Andrei Dumitrescu
DevOps Engineer and Professional Trainer
4.6 instructor rating • 7 courses • 20,725 students

Learn more from the full course

Master Network Automation with Python for Network Engineers

Real-Life Hands-On Python and Ansible Automation: Netmiko, Paramiko, Napalm, Telnet, Ansible, Cisco, Arista, Linux etc

18:03:02 of on-demand video • Updated October 2020

  • You will MASTER all the Python 3 key concepts starting from Scratch. No prior Python or programming knowledge is required
  • Learn how to automate the configuration of networking devices with Python 3 in a Multivendor Environment
  • Learn network programmability with Python, GNS3 and Ansible
  • Learn and apply advanced Python concepts like Multiprocessing and Multithreading in Network Automation
  • See real-world examples of automation scripts with Python for Cisco IOS, Arista EOS or Linux
  • Understand how to use Telnet and SSH with Python for network automation
  • Learn how to use and improve Paramiko and Netmiko for automation of common administration tasks with Python
  • Automate and troubleshoot network configurations with Ansible
  • You will be able to use Ansible, manage Ansible Inventory files, Tasks, Modules for Linux and networking devices, Playbooks, Vaults and YAML Files
  • Use NAPALM Python library in a Multivendor Environment
  • Learn how to configure networking devices with Python using a Serial Console Connection
  • Improve the existing Python modules and create your own modules for network automation
  • You will ultimately gain real-life skills for a good Network of DevOps Engineer
  • You will learn in-depth general Python Programming
English [Auto] In this lecture I'm going to show you how to configure these multi-event vendor environment using net Micko. We have a c quiesce router and to our stock e o s sweetie's they are running on GNAS 3 on another machine and I have access to that machine and to these devices they aren't configured. I've configured just the IP address and S-sh in order to be able to connect to them and I'm going to configure villanies and that the OSPF routing protocol on each device. So let's take a look at the script. I've just created. First I want to show you this fight. The device is dxed the file contains the type of the device see Squires or artista as the IP address of the device. The user name in the passport used for S-sh and here I am going to read the file in a list. In fact the file content is a list and each line is an element. After that I am iterating through this list and by splitting the list using the column character is the separator and I am creating a list in effect here that this will be a list. This will be the first element of the list. The IP address will be the second element of the list the user name. The third element of the list and the password the last element of the list this will be the second list with its first element second element and so on. And the third list and all lists will belong to another list. Better Lex copy paste this code. Here and Here. Liks print file content and I've thought of that. Print the devices list and I'm going to run the script. OK. This is the file content please. We can see a single list. This is the first element of the list. The second element of the list in the last element of the list. And then I am processing 4 out of our list by creating another list. And this is the first element of the list that device type with the IP address is the second element of the list. And so on I need that this list because it's easier to iterate and to have access to this information backdoor script. I am iterating through the devices list device will be an element from my list. So these will be that device list in the first iteration in the second iteration. These will be the device list and so on. And by creating a dictionary that device type is the first element of that device least see Squire as sort artist by us. Then I have with the API that is the second element of the list the user name and the password. We have the same password as the secret password but we could have had another password if we have wanted. I can simply add here and either field or I can use the get pass model. After that I'm creating a connection object and I am entering the Enable mode. Of course if I'm not already in the Enable mode and then and this is very interesting I am asking for a configuration file. The user must enter the configuration file for each device. Each device has its own configuration file. After entering the configuration file I am reading the file and I am sending the commands. In fact this part of from here is exactly as in our previous script from the previous lecture. The configuration fine for example 4C Squier's. I am going to have a list. Each line will be an element of the list and I'm going to send the content of the list to the device of course by using the Send come Fix-It function. I've explained to you in detail in the previous lecture you can be kept from there after sending the commands. I am this quarter next thing and I am printing for the hashes. This is for the clarity of the output. Perfect inside the configuration files for the devices. I start the oil spill felting protocol. That's all I am configuring on the sea squirt outer and on the artists sweetie's. I am starting in configuring the OSPF routing protocol but I am also creating to violence this trunk connection from between the three keys and I am adding the interfaces to their villain. In fact I've explained the configuration in the previous lecture. This is the configuration for the first suite and this is the configuration for it. The second switch everything is the same only the IP addresses of the switched Vittal interface are different. Exactly as in the image you see here. If I tried to display the routing table I pick out. There is no remote network. SPF is not running and there is no villain on the street and thinks the same for each device. Now back to the machine that has access to the apology. This Linux machine I'm going to run the script. I've copied the script to the machine earlier so we have exactly this script and I'm going to execute the script in this way so Python 3 Ned Mikol our staff sees what the vendor is connecting to the first device. The first device is my outer and it's configuration file is named underlined config dot Dickstein X asking for the configuration file executing this line from here the line 31. So I'm going to enter the name of X configuration file see squander line config Duthie XTi and now it's sending the commands to our device. These are the commands. It's configured the OSPF routing protocol. And now I must enter the configuration file for the second device. The second device is the first switch. Sorry star one underlined config. Thought the 60 x connecting to the switch and X executing the comics. After that it's disconnecting and it goes further to the last device. We can see how it created the villanous how to created the switch to Viertel interface and configured IP addresses and how it started and configured the OSPF routing protocol here the configuration file of the last device is artista to underline config that the XTi and the last device has been configured. Now let's check the configuration and the connectivity between each device. We can already see how the OSPF accounting protocol changed each state from loading to full if I want to try out. I can see here all the auks that have been learned through OSPF and Lexa check that connectivity. For example I want to ping from the Cisco outer ICI streatch interface. Each streatch verbal interface from here being one hundred sixty eight 192 168 and that one got them to do it. Twenty one twenty two. I can also check the connectivity between three keys and between villanous ping ping router being works I love being the first switch artist Taiwan. And we can see that we have full connectivity between devices and everything works as expected. This is a very interesting script that can be used to configure an environment of multiple vendors. We have information about devices in a file. We can add other devices. We can get other types of devices and we also have a configuration file for each device. So this example is also scalable.