Python for Network Automation#
Learn Network Programmability with Python, GNS3, and Cisco devices.
What you’ll learn
Python fundamentals
Network Automation with Python
About the author
Associate Engineer (DAE in Electronics) exploring network automation, my skills as an Associate Engineer include:
Routing and Switching
OFC/LAN Networking
IP Addressing and Sub-netting
Computer Basics - Windows 7/10
Linux and Ubuntu Desktop/Server
VMware/KVM/VirtualBox
Docker/Vagrant - Hands On
Ansible for Network Automation
Python for Network Automation
Conventions
This book is a guide for network engineers and is intended for network engineers to write code. Therefore, no time is spent on coding style. Programming concepts such as object-oriented programming are not covered in detail due to their complexity. However, this book mainly focuses on getting Python scripting to work with minimal effort to automate network devices.
Warning
This book is under development.
Table of Contents:
- What is Network Automation?
- Basic Data Types
- Collections and Sequences in Python
- Understanding Lists in Python
- Understanding Tuples in Python
- What is a Tuple?
- Storing Different Data Types in a Tuple
- Using Parentheses
- Checking the Type of a Tuple
- Immutable Nature of Tuples
- Accessing Elements in a Tuple
- Restrictions on Tuple Operations
- Tuple Notation
- Understanding Sets in Python
- How to Use Sets in Python
- Creating Sets
- Using Sets
- How to Modify Sets in Python
- How to Perform Set Operations in Python
- How Set Operations Can Help Network Engineers
- Python Dictionaries: A Network Engineer’s Guide
- Similarities with Lists: Mutability
- Using Curly Braces to Create a Dictionary
- Navigating Dictionaries in Python
- Dictionary Toolbox: Methods
- Exploring Keys, Values, and Items
- Dynamic Modifications with
.pop()
- Deletion Strategies:
del
andupdate
- Dictionary Iteration Techniques
- Nested Dictionaries in Python
- Understanding Mutable and Immutable Objects in Python
- Mutable Objects in Python
- How Lists Work Internally
- List Comprehensions: Simplifying Data Manipulation
- Advanced Techniques with Nested List Comprehensions
- Using List Comprehensions for Data Transformation
- Pros and Cons of List Comprehensions
- Set Comprehensions in Python
- Conditional Statements**
- Understanding Booleans
- Boolean Logic in Python
- Truthy and Falsy Values in Python
- None in Python
- Conditional Statements in Python
- Importance of Conditions in Programming
- Conditional Statements -
elif
andelse
- Comparison Operators and Conditionals
- Logical Operators and Conditional Statements
- Nested Conditional Statements
- Truthy and Falsy Values in Python
- Idiomatic Expressions in Python
- Loops in Python
- File Handling in Python
- Exception Handling in Python for Network Engineers
- Functions and Classes
- Network Automation Lab
- Telnet Programming in Python: Streamlining Network Operations
- Paramiko - Secure SSH Connections in Python
- Setting up Paramiko for SSH Communication
- Establishing Secure Connections to Network Devices
- Executing Commands and Handling Responses Asynchronously
- Handling Exceptions and Error Scenarios Gracefully
- Advanced Example: Creating Loopback Interfaces
- Connecting to Multiple Devices
- Connecting to Multiple Devices with a List
- Conclusion
- Simplifying Network Device Management with Netmiko
- What is Netmiko?
- Installing Netmiko
- Connecting a Single Device
- Simplify Device Connections with Python Dictionaries in Netmiko
- Enabling Privilege EXEC Mode with Netmiko
- Device Configuration with Netmiko
- Safeguarding Passwords in Network Automation with Python’s getpass
- Sending Multiple Commands
- Connecting to Multiple Devices with Netmiko
- Simplifying Network Configuration with Netmiko
- Conclusion
- NAPALM - Unified Network Device Management
- Getting Started with Nornir - Network Automation
- Appendix
- Simplifying Network Automation with Python dotenv
- Understanding Python-dotenv
- Key Benefits of Python-dotenv
- Getting Started with Python-dotenv
- Using Python-dotenv in Your Scripts
- Python Development: Essential VS Code Settings
- What is VS Code?
- What is a Virtual Environment?
- Essential Linux Networking Commands
- Essential Windows 10 Networking Commands
- 1. ipconfig
- 2. netsh
- 3. route
- 4. ping
- 5. tracert
- 6. netstat
- 7. nslookup
- 8. getmac
- 9. telnet
- 10. pscp
- 11. nmap
- 12. arp
- 13. net use
- 14. gpupdate
- 15. systeminfo
- 16. tasklist
- 17. taskkill
- Using
help
Command - Additional Tips