Automating Junos Administration

Book description

How can you grow and maintain a reliable, flexible, and cost-efficient network in the face of ever-increasing demands? With this practical guide, network engineers will learn how to program Juniper network devices to perform day-to-day tasks, using the automation features of the Junos OS. Junos supports several automation tools that provide powerful solutions to common network automation tasks. Authors Jonathan Looney and Stacy Smith, senior testing engineers at Juniper, will help you determine which tools work best for your particular network requirements.

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword
  2. Preface
    1. Assumptions
    2. How to Read This Book
    3. What’s in This Book?
    4. Conventions Used in This Book
    5. Using Code Examples
    6. Safari® Books Online
    7. How to Contact Us
    8. Acknowledgments
      1. From Jonathan Looney
      2. From Stacy Smith
  3. 1. Introduction
    1. Benefits of Automation
      1. Automation Saves Time
      2. Automation Prevents Human Error
      3. Automation Saves Memory
      4. Automation Prevents Copy/Paste Errors
      5. Automation Enables New Services
    2. Management System Internals
      1. Accessing the Management System
      2. Operational Command Flow
      3. Configuration Data Flow
    3. Configuration Databases and the Commit Model
      1. Configuration Databases
      2. The Commit Process
    4. Information About the Book
  4. 2. RPC Mechanisms
    1. Structured Data Model
      1. Structured Data Formats
      2. Using Structured Data in Python
    2. Running RPCs on a Junos Device
      1. RPC Authorization
    3. Operational RPCs
      1. RPC Output Formats
      2. Discovering Operational RPC Syntax
      3. Discovering RPC Reply Syntax
    4. Configuration with RPCs
      1. Configuration Representation in XML
      2. Discovering XML Configuration Syntax
      3. Operational RPCs to View and Change the Configuration
      4. Viewing the Configuration
      5. Changing the Configuration
    5. Chapter Summary
  5. 3. The RESTful API Service
    1. Enabling the RESTful API Service
    2. HTTP GET Requests
    3. Authentication and Authorization
    4. Formatting HTTP Responses
    5. HTTP POST Requests
    6. Adding Parameters to RPCs
    7. Multiple RPCs in One Request
    8. Configuration
    9. RESTful API Explorer
    10. Using the RESTful APIs in Python
      1. The Preamble
      2. Loop Through Each Device
      3. Gather LLDP Neighbor Information
      4. Gather and Parse Interface Descriptions
      5. Check for XML Warnings and Errors
      6. Compare Current and Previous LLDP Neighbor Information
      7. Build a Candidate Configuration
      8. Apply and Commit the Candidate Configuration
      9. Parse Multi-RPC Responses
      10. Putting It All Together
    11. Additional RESTful API Service Configuration
    12. Internal Design
    13. Limitations
    14. Chapter Summary
  6. 4. Junos PyEZ
    1. Installation
    2. Device Connectivity
      1. Creating a Device Instance
      2. Making the Connection
      3. Authentication and Authorization
      4. Connection Exceptions
      5. Facts Gathering
      6. Closing the Connection
    3. RPC Execution
      1. RPC on Demand
      2. RPC Parameters
      3. RPC Timeout
      4. RPC Exceptions
    4. RPC Responses
      1. lxml Elements
      2. Response Normalization
      3. jxmlease
      4. JSON
    5. Operational Tables and Views
      1. Prepackaged Operational Tables and Views
      2. Creating New Operational Tables and Views
      3. Using the New Operational Table and View
      4. Applying a Different View
      5. Saving and Loading XML Files from Tables
    6. Configuration
      1. Loading Configuration Changes
      2. Configuration Templates
      3. Viewing Configuration Differences
      4. Committing Configuration Changes
      5. Using the Rescue Configuration
    7. Utilities
    8. A PyEZ Example
      1. The Preamble
      2. Loop Through Each Device
      3. Gather LLDP Neighbor Information
      4. Gather and Parse Interface Descriptions
      5. Compare Current and Previous LLDP Neighbor Information
      6. Build, Apply, and Commit the Candidate Configuration
      7. Putting It All Together
    9. Limitations
    10. NETCONF Libraries for Other Languages
    11. Chapter Summary
  7. 5. Commit Scripts
    1. Use Cases
      1. Custom Configuration Checks
      2. Automatically Fixing Mistakes
      3. Dynamically Expanding Configuration
    2. Basic Execution Flow
      1. XML Transformations
      2. Commit Script XML Input and Output Documents
      3. Performing Other Operations
    3. Changing the Configuration
      1. Handling Transient Changes
      2. Handling Permanent Changes
    4. Writing Commit Scripts in SLAX/XSLT
      1. Overview of a SLAX Script
      2. Building an Output Document
      3. Working with Variables and XML Data
      4. Templates
      5. Flow Control
      6. Predefined Templates
    5. Commit Script Examples
      1. Example: Custom Configuration Checks
      2. Example: Automatically Fixing Mistakes
      3. Example: Dynamically Expanding Configuration
    6. Chapter Summary
  8. 6. Op Scripts
    1. Use Cases
      1. Custom CLI Commands
      2. Automatically Responding to Events
      3. Customizing Your Device
    2. Overview of Op Script Operation
      1. Op Script Input Document
      2. Op Script Arguments
      3. Op Script Document Processing
      4. Op Script Output Document
    3. Operational and Configuration State
      1. Interacting with Operational State
      2. Interacting with Configuration State
    4. Op Script Input and Output
      1. Formatting Output
      2. Displaying Immediate Output
      3. Obtaining User Input
    5. Some Useful Tools for Op and Event Scripts
      1. Dampening Events
      2. Parsing Strings
      3. Generating SNMP Objects and Traps
    6. Debugging Op and Event Scripts
      1. Printing Progress Messages
      2. Trace Messages
      3. Syslog Messages
      4. The SLAX Debugger
    7. Configuring Op Scripts
    8. Examples
      1. Example: Custom CLI Command
      2. Example: Filtering CLI Output
    9. Chapter Summary
  9. 7. Event Scripts and Event Policies
    1. Overview of Event Script Operation
      1. Event Script Input Document
      2. Event Script Arguments
      3. Event Script Document Processing
      4. Event Script Output Document
    2. Event Policies
      1. Event Discovery
      2. Defining Event Policy Match Criteria
      3. Defining Event Policy Actions
      4. Event Policy Loops
      5. Embedding Event Policies in Event Scripts
      6. Testing Event Policies
    3. Configuring Event Scripts
    4. Example: Responding to a Flapping Link
      1. The Event
      2. The Event Policy
      3. The Event Script
      4. The Results
    5. Chapter Summary
  10. 8. Initial Provisioning
    1. ZTP
    2. Netconify
    3. Chapter Summary
  11. 9. Puppet
    1. Puppet Architecture
    2. Components for Junos Devices
    3. Installation and Configuration
      1. Puppet Master
      2. Junos Device
      3. Creating a Minimal Manifest
      4. Executing the Puppet Agent for the First Time
    4. The Puppet Language
      1. Basic Resource Syntax
      2. Variables
      3. Strings
      4. Classes
      5. Conditional Statements
      6. Node Definitions
      7. Manifest Organization
    5. Using Core Resource Types
      1. Managing ~/.cshrc with the file Resource
      2. Managing puppet.conf with an ERB Template
      3. Managing the Puppet Agent with the cron Resource
    6. Using the netdev Resource Types
      1. The netdev_device Resource
      2. The netdev_vlan Resource
      3. The netdev_interface Resource
      4. The netdev_l2_interface Resource
      5. The netdev_lag Resource
      6. The netdev_stdlib_junos::apply_group Resource
    7. Chapter Summary
  12. 10. Ansible
    1. Architecture and Communication
      1. Typical Communication
      2. Communicating with Junos Managed Nodes
    2. Installation and Configuration
      1. Installing Ansible
      2. Installing the Juniper.junos Role
      3. The Ansible Configuration File
      4. Junos Authentication and Authorization
    3. Creating Ansible Playbooks
      1. Inventory
      2. Playbooks and Plays
      3. Tasks and Modules
      4. Handlers
      5. Execution
      6. Variables
      7. Roles
      8. Conditionals
      9. Loops
      10. Vaults
    4. Ansible for Junos Modules
      1. junos_get_facts
      2. junos_zeroize
      3. junos_srx_cluster
      4. junos_shutdown
      5. junos_install_os
      6. junos_get_config
      7. junos_install_config
      8. junos_rollback
      9. junos_commit
    5. Example Playbooks
      1. Inventory, Variables, and Ansible Configuration Settings
      2. Gathering Junos Facts and Dynamic Groups
      3. Zeroize
      4. Initial Configuration
      5. Core OSPF Configuration
    6. Chapter Summary
  13. 11. Putting Automation into Practice
    1. Use Cases
      1. Configuration Use Cases
      2. Operational Use Cases
    2. Best Practices
      1. General Recommendations
      2. Tool-Specific Recommendations
    3. Wrap-Up
  14. Glossary
  15. Index

Product information

  • Title: Automating Junos Administration
  • Author(s): Jonathan Looney, Stacy Smith
  • Release date: April 2016
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491928882