Network engineers are finding it harder than ever to rely solely on manual processes to get their jobs done. New protocols, technologies, delivery models, and the need for businesses to become more agile and flexible have made network automation essential. The updated second edition of this practical guide shows network engineers how to use a range of technologies and tools, including Linux, Python, APIs, and Git, to automate systems through code. This edition also includes brand new topics such as network development environments, cloud, programming with Go, and a reference network automation architecture.
Network Programmability and Automation will help you automate tasks involved in configuring, managing, and operating network equipment, topologies, services, and connectivity. Through the course of the book, you'll learn the basic skills and tools you need to make this critical transition.
You'll learn:
• Programming skills with Python and Go: data types, conditionals, loops, functions, and more
• New Linux-based networking technologies and cloud native environments, and how to use them to bootstrap development environments for your network projects
• Data formats and models: JSON, XML, YAML, Protobuf, and YANG
• Jinja templating for creating network device configurations
• A holistic approach to architecting network automation services
• The role of application programming interfaces (APIs) in network automation
• Source control with Git to manage code changes during the automation process
• Cloud-native technologies like Docker and Kubernetes
• How to automate network devices and services using Ansible, Nornir, and Terraform
• Tools and technologies for developing and continuously integrating network automation
Author(s): Matt Oswalt, Christian Adell, Scott Lowe, Jason Edelman
Edition: 2
Publisher: O'Reilly Media
Year: 2023
Language: English
Commentary: Publisher's PDF; 2023-08-16: First Release
Pages: 825
City: Sebastopol, CA
Tags: Linux; Cloud Computing; Python; JSON; Network Programming; Go; Kubernetes; Automation; YAML; Ansible; Git; XML; Terraform; Configuration Management; SNMP; Salt; Version Control Systems; StackStorm; Nornir; Containers; CI/CD; Jinja
Cover
Copyright
Table of Contents
Preface
What This Book Covers
What’s New in This Edition
How This Book Is Organized
Who Should Read This Book
Network Engineers
Systems Administrators
Software Developers
Tools Used in This Book
Online Resources
Conventions Used in This Book
Using Code Examples
O’Reilly Online Learning
How to Contact Us
Acknowledgments
Chapter 1. Network Industry Trends
The Rise of Software-Defined Networking
The Advent of OpenFlow
Why OpenFlow?
What Is Software-Defined Networking?
Opening Up the Data Plane
Network Functions Virtualization
Virtual Switching
Network Virtualization
Device APIs
Network Automation
Bare-Metal Switching
Data Center Network Fabrics
SD-WAN
Controller Networking
Cloud Native Networking
Summary
Chapter 2. Network Automation
Why Network Automation?
Simplified Architectures
Deterministic Outcomes
Business Agility
Enhanced Security and Risk Reduction
Types of Network Automation
Device Provisioning
Data Collection and Enrichment
Migrations
Configuration Management
Configuration Compliance
State Validation
Reporting
Troubleshooting
Evolving the Management Plane from SNMP to APIs
Application Programming Interfaces
Impact of Open Networking
Network Automation in the SDN Era
Summary
Chapter 3. Linux
Examining Linux in a Network Automation Context
Exploring a Brief History of Linux
Understanding Linux Distributions
Red Hat Enterprise Linux, Fedora, CentOS, and Amazon Linux
Debian, Ubuntu, and Other Derivatives
Other Linux Distributions
Interacting with Linux
Navigating the Filesystem
Manipulating Files and Directories
Running Programs
Working with Daemons
Networking in Linux
Working with Interfaces
Routing as an End Host
Routing as a Router
Bridging (Switching)
Automating Linux with bash Scripting
Evolving the Linux Kernel with eBPF and XDP
Summary
Chapter 4. Cloud
Brief Definition of Cloud Computing
Networking Fundamentals in the Cloud
Cloud Networking Building Blocks
Cloud Network Topologies
Network Automation in the Cloud
Containers
What Do Containers Have to Do with the Cloud?
What Do Containers Have to Do with Networking?
Extending Linux Networking for Containers
Kubernetes
Key Kubernetes Concepts
Building Blocks of Networking in Kubernetes
Service Mesh
Summary
Chapter 5. Network Developer Environments
Text Editors
Syntax Highlighting
Customization
Intelligent Code Analysis
Text Editors Versus Integrated Development Environments
Development Tools
Virtualenv
Make
Docker
dyff
Emulation/Simulation Tools
VirtualBox
Vagrant
Containerlab
Other Tools
Summary
Chapter 6. Python
Should Network Engineers Learn to Code?
Using the Python Interactive Interpreter
Understanding Python Data Types
Strings
Numbers
Booleans
Lists
Python Dictionaries
Sets and Tuples
Adding Conditional Logic to Your Code
Understanding Containment
Using Loops in Python
The while Loop
The for Loop
Using Python Functions
Working with Files
Reading from a File
Writing to a File
Creating Python Programs
Creating a Basic Python Script
Using Comments in Python
Migrating Code from the Python Interpreter to a Python Script
Working with Python Modules
Documenting Functions
Passing Arguments into a Python Script
Using pip and Installing Python Packages
Isolating Your Dependencies with Virtualenv
Understanding Python Classes
Using Classes
Building Your Own Classes
Embracing Failure with try/except
Parallelizing Your Python Programs
Summary
Chapter 7. Go
Why Go?
Is Go Faster Than Python?
Is Go Harder than Python?
Fundamental Go Concepts
Types and Variables
Flow Control
Collection Types
Functions
Structs
Methods
Interfaces
Advanced Concepts
Concurrency
Generics
Packages and Modules
Standard Library Packages
Third-Party Modules and Packages
Summary
Chapter 8. Data Formats and Models
Benefits and Fundamentals of Structured Data Formats
When Structured Data Isn’t Available: Screen Scraping
Types of Data
Documents Versus Data
Categories of Data Formats
Text-Based Data Formats
YAML
XML
JSON
Binary Data Formats
Protocol Buffers
Other Binary Data Formats
Data Modeling
YANG
JSON Schema
XML Schema Definition
Modeling and Validating Protocol Buffers
Summary
Chapter 9. Templates
The Rise of Modern Template Languages
Using Templates for Web Development
Expanding On the Use of Templates
The Value of Templates in Network Automation
Jinja
Rendering a Jinja Template File in Python
Using Conditionals and Loops
Using Jinja Filters
Template Inheritance in Jinja
Variable Creation in Jinja
Extensible Stylesheet Language Transformations
Go Templates
Summary
Chapter 10. Working with Network APIs
Understanding Network APIs
Getting Familiar with HTTP-Based APIs
Using NETCONF
Using RESTCONF
Using gRPC and gNMI
Comparing NETCONF, RESTCONF, and gNMI
Using Network APIs for Automation
The Python Requests Library
The Go net/http Package
The Python ncclient Library
The OpenConfig gNMIc Go Package
The Netmiko Python Library
Summary
Chapter 11. Source Control with Git
Use Cases for Source Control
Benefits of Source Control
Change Tracking
Accountability
Process and Workflow
Benefits of Source Control for Networking
Enter Git
Brief History of Git
Git Terminology
Overview of Git’s Architecture
Working with Git
Installing Git
Creating a Repository
Adding Files to a Repository
Committing Changes to a Repository
Changing and Committing Tracked Files
Unstaging Files
Excluding Files from a Repository
Viewing More Information About a Repository
Distilling Differences Between Versions of Files
Tagging Commits in Git
Branching in Git
Renaming the Default Branch
Creating a Branch
Checking Out a Branch
Stashing Uncommitted Changes
Merging and Deleting Branches
Collaborating with Git
Collaborating Between Multiple Systems Running Git
Collaborating via Git-Based Online Services
Summary
Chapter 12. Automation Tools
Reviewing Automation Tools
Using Ansible
Discovering the Ansible Framework
Understanding How Ansible Works
Constructing an Inventory File
Executing an Ansible Playbook
Using Secrets
Using Variable Files
Writing Ansible Playbooks for Network Automation
Using Third-Party Collections and Modules
Ansible Summary
Automating with Nornir
Getting Started with Nornir
Using NAPALM with Nornir
Nornir Summary
Managing Dynamic Infrastructure with Terraform
Understanding Terraform Architecture
Provisioning Your First Resource with Terraform
Extending Terraform Execution
Managing Terraform at Scale
Terraform Out of Its Comfort Zone
Terraform Summary
Summary
Chapter 13. Continuous Integration
Important Prerequisites
Simple Is Better
People, Process, and Technology
Learn to Code
Introduction to Continuous Integration
Basics of Continuous Integration
Continuous Delivery
Test-Driven Development
Why Continuous Integration for Networking?
A Continuous Integration Pipeline for Networking
Peer Review
Build Automation
Deployment Validation and Testing
Test/Dev/Staging Environment
Deployment Tools and Strategies
Summary
Chapter 14. Network Automation Architecture
Introducing the Network Automation Architecture
Overview of the Architecture Components
User Interactions
Source of Truth
Automation Engine
Telemetry and Observability
Orchestration
Understanding the Architecture with an Example
Determine the Operation’s Workflow
Translate the Workflow Steps to Automated Tasks
Map the Automated Tasks to Architecture Components
Choose the Tools to Implement Each Component’s Tasks
Summary
Index
About the Authors
Colophon