Table of Contents....5
About the Author....11
About the Technical Reviewer....12
Acknowledgments....13
Introduction....14
Chapter 1: Building a Python Network Automation Lab Environment....17
Embarking on the Next Phase of Your Python Network Automation Journey....18
Empowering Your Network Automation Journey with GNS3 and Cisco CML Integration....19
Before Integrating Cisco CML Images in GNS3....20
Integrating Cisco CML L2 and CML L3 Images on Your GNS3....22
Installing Cisco CML L2 Switch on GNS3....24
Quick Ping Test on CML L2 Switch....34
Installing the Cisco CML L3 Router on GNS3 Using the Import Appliance Option....40
Quick Ping Test on the CML L3 Router....54
Building a CML Lab Topology....56
Summary....66
Storytime 1: Still Enjoying the Most Expensive Sandwich in the World....67
Chapter 2: Python Network Automation Labs - Basic Telnet....69
Outline Placeholder....70
Python Network Automation: Network Engineer’s interface....72
Telnet Lab 1: Interactive Telnet Session to Cisco Devices on a Python Interpreter....76
Telnet Lab 2: Configure a Single Switch with a Python Telnet Template....88
Telnet Lab 3: Configure Random VLANs Using a for Loop....95
Telnet Lab 4: Configure Random VLANs Using a while Loop....102
Telnet Lab 5: Configure 100 VLANs Using the for ~ in range Loop....112
Telnet Lab 6: Add a Privilege 3 User on Multiple Devices Using IP Addresses from an External File....118
Telnet Lab 7: Taking Backups of running-config (or startup-config) to Local Server Storage....128
Summary....135
Chapter 3: Python Network Automation Labs: SSH in Action, paramiko and netmiko Labs....136
The Enduring Role of SSH in Network Infrastructure: Navigating the Evolution of Remote Management Tools....137
Python Network Automation Labs Using the paramiko and netmiko Libraries....138
Checking the SSH in Action on a Linux Server....139
Checking the SSH in Action on Cisco Devices....142
Python SSH Labs: paramiko....144
paramiko Lab 1: Configure the Clock and Time Zone of All Devices Interactively in the Python Interpreter....144
paramiko Lab 2: Configuring an NTP Server on Cisco Devices Without User Interaction (NTP Lab)....177
paramiko Lab 3: Create an Interactive paramiko SSH Script to Save Running Configurations to the TFTP Server....190
Python SSH Labs: netmiko....201
Installing the netmiko Library....202
netmiko Lab 1: netmiko Uses a Dictionary for Device Information, Not a JSON Object....203
netmiko Lab 2: Develop a Simple Port Scanner Using a Socket Module and Then Develop a netmiko Disable Telnet Script....218
netmiko Lab 3: config compare....228
Summary....241
Chapter 4: Python Network Automation Labs cron....243
Unveiling the Power of cron in Python Networking....243
Cloning a GNS3 Project for the Next Lab....244
Router Failure Simulation, P1 Network Recovery....252
Lab Pre-Task, Deleting VPCS and Adding More L2 Switches....258
Quick-Start to the Linux Scheduler, cron....264
Ubuntu LTS Task Scheduler: crontab....265
Fedora Task Scheduler: crond....272
Learn cron Job Definitions with Examples....281
Summary....284
Chapter 5: Python Network Automation Labs: SNMP Discovery with Python....286
Bridging Theory and Practice: Learning About SNMP with Python....287
Quick-Start Guide to SNMP....288
Quick SNMP History....289
Types of System Monitoring....290
Comparison Table: SNMP vs. Syslog vs. APIs....292
SNMP Standard Operation....294
SNMP Polling vs. the Trap (Event Reporting) Method....296
SNMP Versions....296
Understanding the SNMP Protocol in the TCP/IP Stack....297
About SNMP Message Types....298
Understanding SNMP’s SMI, MIB, and OID....299
SNMP Access Policy....299
Synchronous vs. Asynchronous Communication While Using SNMP Traps....300
SNMP Tools and Python Integrations....301
Using Python to Run an SNMPv3 Query....303
SNMP-Related Python Libraries....303
Understanding MIBs and OIDs and Browsing OIDs Directly....304
Learning to Use SNMPwalk on a Linux Server....305
Installing and Configuring SNMP Server on Fedora....306
Configuring Cisco Routers and Switches to Support SNMPv3 Using a Python Script....309
Troubleshooting SSH Connections Between Fedora and Cisco Devices....311
Configuring SNMP Agents (engineID, group, and user) on Cisco Devices....325
Doing the SNMPwalk on the Linux Server....338
Borrowing Some Example Python SNMP Code....344
SNMP Lab Source Code....345
SNMPv3 Python Code to Query Cisco Device Information....348
Using Python SNMP Code to Run a Query for an Interface Description....355
Summary....360
Chapter 6: Python Network Automation Virtual Lab 1: Ansible and pyATS in Python virtualenv....361
Python Virtual Lab 1: Ansible and pyATS in Python virtualenv....362
Navigating the Ansible and pyATS Networking Tools....363
Lab 1: Quick-Start Guide to Ansible in virtualenv....364
Installing virtualenv and Getting Started with Ansible....368
Lab 2: Quick-Start Guide to pyATS (Genie) in virtualenv....387
Summary....413
Storytime 2: Doubling Down!....413
Chapter 7: Python Network Automation Virtual Lab 2: Sendmail Email Notification and Twilio SMS Notification on Docker....416
Cost-Efficient IT Operations: Leveraging Docker for Python Networks....417
Expense Optimization in Python Networking: Docker, Kubernetes Impact....419
Python Network Automation Virtual Lab 2: Docker and Twilio SMS....420
Lab 1: Sendmail Lab Using an Imported Docker Image....421
Docker Components, Account Registration, and Installation....423
Docker Installation Procedure....423
Test-Driving Docker....426
Lab 2: Sendmail Python Lab Using Docker....435
Lab Prerequisites....435
Lab 3: Sendmail Email Notification Script Development in Docker....447
Lab 4: CPU Utilization Monitoring Lab: Send an SMS Message Using Twilio....458
Lab 5: TWILIO Account Creation: Install Twilio Python Module and Set Up an SMS Message....459
Lab 6: CPU Utilization Monitoring Lab with an SMS Message....467
Summary....482
Chapter 8: Upgrading Multiple Cisco IOS Routers....483
Empowering Python Network Automation: Unveiling OOP and Real-world Scenarios....483
Applying OOP Concepts to Your Network....484
Managing Flow Control and User Input: UID, PWD, and Information Collection....492
Proactive Patch Management and Zero Trust: Shaping Network Security....501
Router IOS Upgrade Lab Preparation....502
Cisco Catalyst 8000v IOS XE Software and Download....503
Cisco Catalyst 8000v Installation on VMware Workstation....505
How an IOS (IOS XE/XR) Is Upgraded on Cisco Devices....519
Tasks Involved in a Cisco IOS Upgrade....520
Summary....524
Chapter 9: Cisco IOS-XE Upgrade Tools Development Part 1....525
Mastering Cisco IOS Upgrades using Python: A Comprehensive Guide for Network Engineers....525
Tools Development 1: Network Connectivity and Socket Validation Tool....528
Tools Development 2: Login Credentials and User Input Collector....546
Tools Development 3: Collect a New IOS File Name and MD5 Value from a CSV File....553
Tools Development 4: Check the MD5 Value of the New IOS on the Server....566
Tools Development 5: Check the Flash Size on Cisco Routers....574
Tools Development 6: Make Backups of running-config, Interface Status, and Routing Table....580
Summary....585
Chapter 10: Cisco IOS-XE Upgrade Tools Development: Part 2....586
Cisco IOS Upgrade Application Development (Continued)....587
Tools Development 7: IOS Uploading and More Pre-check Tools Development....587
Tools Development 8: Check the New IOS MD5 Value on the Cisco Device’s Flash....606
Tools Development 9: Options to Stop or Reload the Routers....620
Tools Development 10: Check the Reloading Device and Perform a Post-Reload Configuration Verification....639
Summary....654
Storytime 3: IT Evolution: Unraveling the Cloud's Impact with Chicken Littles....655
Chapter 11: Upgrading the Application and Routers....657
Python Mastery for Network Automation: Building the Final IOS Upgrade Tool....658
Summary....722
Chapter 12: Installing NetBox (IPAM/DCIM) with Python....723
What Is NetBox, and Why Do You Need It?....723
Some NetBox Features....726
What NetBox Is Not....726
Server Specifications, Dependencies, and Functions....726
NetBox Concept: The “Site” Is the Core of NetBox....728
NetBox IP Address Management (IPAM): High-Level Overview....728
Changing NetBox into Multi-tenancy IPAM....729
NetBox 3 Manual Installation on Ubuntu 22.04 LTS....730
NetBox 3 Automated Python Script Installation on Ubuntu 22.04 LTS....750
Summary....773
Storytime 4: Embarking on the Python Programming Odyssey: A Journey of Network Automation and Career Advancement....774
Index....776
Continue your Python network automation journey and delve deeper into advanced techniques and methodologies. Volume 2 of this comprehensive guide takes you beyond the essentials, equipping you with advanced skills and strategies crucial for success in network automation. Building upon the knowledge gained in Volume 1, you’ll set the stage for mastery in this dynamic field.
You’ll start by establishing a robust lab environment for advanced automation projects tailored to your needs and use practical exercises to gain valuable insights into essential networking protocols. Then automate repetitive tasks with precision and efficiency by leveraging powerful Python libraries and tools. You’ll also see how to streamline IP address management and data center infrastructure management tasks with Python. Discover advanced techniques for network management and monitoring to optimize network performance and security.
Explore the development of custom tools and applications for Cisco IOS upgrade tasks in complex network environments and put your skills to the test with real-world scenarios. All this is designed to solidify your expertise and confidence in network automation practices. Your network management capabilities will be enhanced with advanced tools, such as NetBox.
Introduction to Python Network Automation Volume 2 - Stepping up provides a comprehensive roadmap to elevate your skills and excel in the dynamic field of network automation. Whether you're a seasoned professional or a newcomer to the field, this guide equips you with the tools and knowledge needed to thrive in today's network automation landscape.
IT engineers and developers, network managers and students, who would like to learn network automation using Python.