O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Network Programmability and Automation

Book Description

Like sysadmins before them, network engineers are finding that they cannot do their work manually anymore. As the field faces new protocols, technologies, delivery models, and a pressing need for businesses to be more agile and flexible, network automation is becoming essential. This practical guide shows network engineers how to use a range of technologies and tools—including Linux, Python, JSON, and XML—to automate their systems through code.

Network programming and automation will help you simplify 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.

This book covers:

  • Python programming basics: data types, conditionals, loops, functions, classes, and modules
  • Linux fundamentals to provide the foundation you need on your network automation journey
  • Data formats and models: JSON, XML, YAML, and YANG for networking
  • Jinja templating and its applicability for creating network device configurations
  • The role of application programming interfaces (APIs) in network automation
  • Source control with Git to manage code changes during the automation process
  • How Ansible, Salt, and StackStorm open source automation tools can be used to automate network devices
  • Key tools and technologies required for a Continuous Integration (CI) pipeline in network operations

Table of Contents

  1. Preface
    1. What This Book Covers
    2. How This Book Is Organized
    3. Who Should Read This Book
      1. Network Engineers
      2. Systems Administrators
      3. Software Developers
    4. Tools Used in this Book
    5. Online Resources
    6. Conventions Used in This Book
    7. O’Reilly Safari
    8. How to Contact Us
    9. Acknowledgments
  2. 1. Network Industry Trends
    1. The Rise of Software Defined Networking
      1. OpenFlow
      2. What Is Software Defined Networking?
    2. Summary
  3. 2. Network Automation
    1. Why Network Automation?
      1. Simplified Architectures
      2. Deterministic Outcomes
      3. Business Agility
    2. Types of Network Automation
      1. Device Provisioning
      2. Data Collection
      3. Migrations
      4. Configuration Management
      5. Compliance
      6. Reporting
      7. Troubleshooting
    3. Evolving the Management Plane from SNMP to Device APIs
      1. Application Programming Interfaces (APIs)
      2. Impact of Open Networking
    4. Network Automation in the SDN Era
    5. Summary
  4. 3. Linux
    1. Examining Linux in a Network Automation Context
    2. A Brief History of Linux
    3. Linux Distributions
      1. Red Hat Enterprise Linux, Fedora, and CentOS
      2. Debian, Ubuntu, and Other Derivatives
      3. Other Linux Distributions
    4. Interacting with Linux
      1. Navigating the Filesystem
      2. Manipulating Files and Directories
      3. Running Programs
      4. Working with Daemons
    5. Networking in Linux
      1. Working with Interfaces
      2. Routing as an End Host
      3. Routing as a Router
      4. Bridging (Switching)
    6. Summary
  5. 4. Learning Python in a Network Context
    1. Should Network Engineers Learn to Code?
    2. Using the Python Interactive Interpreter
    3. Understanding Python Data Types
      1. Learning to Use Strings
      2. Learning to Use Numbers
      3. Learning to Use Booleans
      4. Learning to Use Python Lists
      5. Learning to Use Python Dictionaries
      6. Learning About Python Sets and Tuples
    4. Adding Conditional Logic to Your Code
    5. Understanding Containment
    6. Using Loops in Python
      1. Understanding the while Loop
      2. Understanding the for Loop
    7. Using Python Functions
    8. Working with Files
      1. Reading from a File
      2. Writing to a File
    9. Creating Python Programs
      1. Creating a Basic Python Script
      2. Understanding the Shebang
      3. Migrating Code from the Python Interpreter to a Python Script
    10. Working with Python Modules
    11. Passing Arguments into a Python Script
    12. Using pip and Installing Python Packages
    13. Learning Additional Tips, Tricks, and General Information When Using Python
    14. Summary
  6. 5. Data Formats and Data Models
    1. Introduction to Data Formats
      1. Types of Data
    2. YAML
      1. Reviewing YAML Basics
      2. Working with YAML in Python
      3. Data Models in YAML
    3. XML
      1. Reviewing XML Basics
      2. Using XML Schema Definition (XSD) for Data Models
      3. Transforming XML with XSLT
      4. Searching XML Using XQuery
    4. JSON
      1. Reviewing JSON Basics
      2. Working with JSON in Python
      3. Using JSON Schema for Data Models
    5. Data Models Using YANG
      1. YANG Overview
      2. Taking a Deeper Dive into YANG
    6. Summary
  7. 6. Network Configuration Templates
    1. The Rise of Modern Template Languages
      1. Using Templates for Web Development
      2. Expanding On the Use of Templates
    2. The Value of Templates in Network Automation
    3. Jinja for Network Configuration Templates
      1. Why Jinja?
      2. Dynamically Inserting Data into a Basic Jinja Template
      3. Rendering a Jinja Template File in Python
      4. Conditionals and Loops
      5. Jinja Filters
      6. Template Inheritance in Jinja
      7. Variable Creation in Jinja
    4. Summary
  8. 7. Working with Network APIs
    1. Understanding Network APIs
      1. Getting Familiar with HTTP-Based APIs
      2. Diving into NETCONF
    2. Exploring Network APIs
      1. Exploring HTTP-Based APIs
      2. Exploring NETCONF
    3. Automating Using Network APIs
      1. Using the Python requests Library
      2. Using the Python ncclient Library
      3. Using netmiko
    4. Summary
  9. 8. Source Control with Git
    1. Use Cases for Source Control
    2. Benefits of Source Control
      1. Change Tracking
      2. Accountability
      3. Process and Workflow
    3. Benefits of Source Control for Networking
    4. Enter Git
      1. Brief History of Git
      2. Git Terminology
      3. Overview of Git’s Architecture
    5. Working with Git
      1. Installing Git
      2. Creating a Repository
      3. Adding Files to a Repository
      4. Committing Changes to a Repository
      5. Changing and Committing Tracked Files
      6. Unstaging Files
      7. Excluding Files from a Repository
      8. Viewing More Information About a Repository
      9. Distilling Differences Between Versions of Files
    6. Branching in Git
      1. Creating a Branch
      2. Checking Out a Branch
      3. Merging and Deleting Branches
    7. Collaborating with Git
      1. Collaborating Between Multiple Systems Running Git
      2. Collaborating Using Git-Based Online Services
    8. Summary
  10. 9. Automation Tools
    1. Reviewing Automation Tools
    2. Using Ansible
      1. Understanding How Ansible Works
      2. Constructing an Inventory File
      3. Executing an Ansible Playbook
      4. Using Variable Files
      5. Writing Ansible Playbooks for Network Automation
      6. Using Third-Party Ansible Modules
      7. Ansible Summary
    3. Automating with Salt
      1. Understanding the Salt Architecture
      2. Getting Familiar with Salt
      3. Managing Network Configurations with Salt
      4. Executing Salt Functions Remotely
      5. Diving into Salt’s Event-Driven Infrastructure
      6. Diving into Salt a Bit Further
      7. Salt Summary
    4. Event-Driven Network Automation with StackStorm
      1. StackStorm Concepts
      2. StackStorm Architecture
      3. Actions and Workflows
      4. Sensors and Triggers
      5. Rules
      6. StackStorm Summary
    5. Summary
  11. 10. Continuous Integration
    1. Important Prerequisites
      1. Simple Is Better
      2. People, Process, and Technology
      3. Learn to Code
    2. Introduction to Continuous Integration
      1. Basics of Continuous Integration
      2. Continuous Delivery
      3. Test-Driven Development
      4. Why Continuous Integration for Networking?
    3. A Continuous Integration Pipeline for Networking
      1. Peer Review
      2. Build Automation
      3. Test/Dev/Staging Environment
      4. Deployment Tools
      5. Testing Tools and Test-Driven Network Automation
    4. Summary
  12. 11. Building a Culture for Network Automation
    1. Organizational Strategy and Flexibility
      1. Transforming an Old-World Organization
      2. The Importance of Executive Buy-in
      3. Build Versus Buy
    2. Embracing Failure
    3. Skills and Education
      1. Learn What You Don’t Know
      2. Focus on Fundamentals
      3. Certifications?
      4. Won’t Automation Take My Job?!
    4. Summary
  13. A. Advanced Networking in Linux
    1. Using macvlan Interfaces
      1. Use Cases for macvlan Interfaces
      2. Creating, Configuring, and Deleting macvlan Interfaces
    2. Networking Virtual Machines
      1. Using a Bridge
      2. Using macvtap Interfaces
    3. Working with Network Namespaces
      1. Use Cases for Network Namespaces
      2. Creating and Removing Network Namespaces
      3. Placing Interfaces in a Network Namespace
      4. Executing Commands in a Network Namespace
      5. Connecting Network Namespaces with veth Pairs
    4. Networking Linux Containers
      1. Configuring LXC Networking
      2. Configuring Docker Networking
    5. Using Open vSwitch
      1. Installing OVS
      2. Configuring OVS
      3. Connecting Workloads to OVS
  14. B. Using NAPALM
    1. Understanding Configuration Management in NAPALM
      1. Performing a Configuration Replace
      2. Performing a Configuration Merge
    2. Retrieving Data with NAPALM
    3. NAPALM Integrations
      1. Using NAPALM in Ansible
      2. Using NAPALM in Salt
      3. Using NAPALM in StackStorm
  15. Index