0%

Book Description

New edition of the bestselling guide to mastering Python Networking, updated to Python 3 and including the latest on network data analysis, Cloud Networking, Ansible 2.8, and new libraries

Key Features

  • Explore the power of Python libraries to tackle difficult network problems efficiently and effectively, including pyATS, Nornir, and Ansible 2.8
  • Use Python and Ansible for DevOps, network device automation, DevOps, and software-defined networking
  • Become an expert in implementing advanced network-related tasks with Python 3

Book Description

Networks in your infrastructure set the foundation for how your application can be deployed, maintained, and serviced. Python is the ideal language for network engineers to explore tools that were previously available to systems engineers and application developers. In Mastering Python Networking, Third edition, you'll embark on a Python-based journey to transition from traditional network engineers to network developers ready for the next-generation of networks.

This new edition is completely revised and updated to work with Python 3. In addition to new chapters on network data analysis with ELK stack (Elasticsearch, Logstash, Kibana, and Beats) and Azure Cloud Networking, it includes updates on using newer libraries such as pyATS and Nornir, as well as Ansible 2.8. Each chapter is updated with the latest libraries with working examples to ensure compatibility and understanding of the concepts.

Starting with a basic overview of Python, the book teaches you how it can interact with both legacy and API-enabled network devices. You will learn to leverage high-level Python packages and frameworks to perform network automation tasks, monitoring, management, and enhanced network security followed by Azure and AWS Cloud networking. Finally, you will use Jenkins for continuous integration as well as testing tools to verify your network.

What you will learn

  • Use Python libraries to interact with your network
  • Integrate Ansible 2.8 using Python to control Cisco, Juniper, and Arista network devices
  • Leverage existing Flask web frameworks to construct high-level APIs
  • Learn how to build virtual networks in the AWS & Azure Cloud
  • Learn how to use Elastic Stack for network data analysis
  • Understand how Jenkins can be used to automatically deploy changes in your network
  • Use PyTest and Unittest for Test-Driven Network Development in networking engineering with Python

Who this book is for

Mastering Python Networking, Third edition is for network engineers, developers, and SREs who want to use Python for network automation, programmability, and data analysis. Basic familiarity with Python programming and networking-related concepts such as Transmission Control Protocol/Internet Protocol (TCP/IP) will be useful.

Table of Contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  2. Review of TCP/IP Protocol Suite and Python
    1. An overview of the internet
      1. Servers, hosts, and network components
      2. The rise of data centers
        1. Enterprise data centers
        2. Cloud data centers
        3. Edge data centers
    2. The OSI model
    3. Client-server model
    4. Network protocol suites
      1. The transmission control protocol
        1. Functions and characteristics of TCP
        2. TCP messages and data transfer
      2. The user datagram protocol
      3. The internet protocol
        1. IP network address translation (NAT) and network security
        2. IP routing concepts
    5. Python language overview
      1. Python versions
      2. Operating system
      3. Running a Python program
      4. Python built-in types
        1. The None type
        2. Numerics
        3. Sequences
        4. Mapping
        5. Sets
      5. Python operators
      6. Python control flow tools
      7. Python functions
      8. Python classes
      9. Python modules and packages
    6. Summary
  3. Low-Level Network Device Interactions
    1. The challenges of the CLI
    2. Constructing a virtual lab
      1. Physical devices
      2. Virtual devices
      3. Cisco VIRL
        1. VIRL tips
      4. Cisco DevNet and dCloud
      5. GNS3
    3. Python Pexpect library
      1. Python virtual environment
      2. Pexpect installation
      3. Pexpect overview
      4. Our first Pexpect program
      5. More Pexpect features
      6. Pexpect and SSH
      7. Putting things together for Pexpect
    4. The Python Paramiko library
      1. Installation of Paramiko
      2. Paramiko overview
      3. Our first Paramiko program
      4. More Paramiko features
        1. Paramiko for servers
      5. Putting things together for Paramiko
    5. The Netmiko library
    6. The Nornir framework
      1. Downsides of Pexpect and Paramiko compared to other tools
        1. Idempotent network device interaction
        2. Bad automation speeds bad things up
    7. Summary
  4. APIs and Intent-Driven Networking
    1. Infrastructure-as-code
      1. Intent-driven networking
      2. Screen scraping versus API structured output
      3. Data modeling for infrastructure-as-code
      4. YANG and NETCONF
    2. The Cisco API and ACI
      1. Cisco NX-API
        1. Lab software installation and device preparation
        2. NX-API examples
      2. The Cisco YANG model
      3. The Cisco ACI and APIC-EM
    3. Cisco Meraki controller
    4. The Python API for Juniper Networks
      1. Juniper and NETCONF
        1. Device preparation
        2. Juniper NETCONF examples
      2. Juniper PyEZ for developers
        1. Installation and preparation
        2. PyEZ examples
    5. The Arista Python API
      1. Arista eAPI management
        1. eAPI preparation
        2. eAPI examples
      2. The Arista Pyeapi library
        1. Pyeapi installation
        2. Pyeapi examples
    6. VyOS example
    7. Other libraries
    8. Summary
  5. The Python Automation Framework – Ansible Basics
    1. Ansible – a more declarative framework
    2. A quick Ansible example
      1. The control node installation
      2. Running different versions of Ansible from source
      3. Lab setup
      4. Your first Ansible playbook
        1. The public key authorization
        2. The inventory file
        3. Our first playbook
    3. The Advantages of Ansible
      1. Agentless
      2. Idempotence
      3. Simple and extensible
      4. Network vendor support
    4. The Ansible architecture
      1. YAML
      2. Inventories
      3. Variables
      4. Templates with Jinja2
    5. Ansible networking modules
      1. Local connections and facts
      2. Provider arguments
    6. The Ansible Cisco example
    7. Ansible 2.8 playbook example
    8. The Ansible Juniper example
    9. The Ansible Arista example
    10. Summary
  6. The Python Automation Framework – Beyond Basics
    1. Lab preparation
    2. Ansible conditionals
      1. The when clause
      2. Ansible network facts
      3. Network module conditional
    3. Ansible loops
      1. Standard loops
      2. Looping over dictionaries
    4. Templates
      1. The Jinja2 template variables
      2. Jinja2 loops
      3. The Jinja2 conditional
    5. Group and host variables
      1. Group variables
      2. Host variables
    6. The Ansible Vault
    7. The Ansible include and roles
      1. The Ansible include statement
      2. Ansible roles
    8. Writing your own custom module
      1. The first custom module
      2. The second custom module
    9. Summary
  7. Network Security with Python
    1. The lab setup
    2. Python Scapy
      1. Installing Scapy
      2. Interactive examples
      3. Packet captures with Scapy
      4. The TCP port scan
      5. The ping collection
      6. Common attacks
      7. Scapy resources
    3. Access lists
      1. Implementing access lists with Ansible
      2. MAC access lists
    4. The Syslog search
      1. Searching with the regular expression module
    5. Other tools
      1. Private VLANs
      2. UFW with Python
    6. Further reading
    7. Summary
  8. Network Monitoring with Python – Part 1
    1. Lab setup
    2. SNMP
      1. Setup
      2. PySNMP
    3. Python for data visualization
      1. Matplotlib
        1. Installation
        2. Matplotlib – the first example
        3. Matplotlib for SNMP results
        4. Additional Matplotlib resources
      2. Pygal
        1. Installation
        2. Pygal – the first example
        3. Pygal for SNMP results
        4. Additional Pygal resources
    4. Python for Cacti
      1. Installation
      2. Python script as an input source
    5. Summary
  9. Network Monitoring with Python – Part 2
    1. Graphviz
      1. Lab setup
      2. Installation
      3. Graphviz examples
      4. Python with Graphviz examples
      5. LLDP neighbor graphing
        1. Information retrieval
        2. Python parser script
        3. Testing the playbook
    2. Flow-based monitoring
      1. NetFlow parsing with Python
        1. Python socket and struct
    3. ntop traffic monitoring
      1. Python extension for ntop
      2. sFlow
        1. SFlowtool and sFlow-RT with Python
    4. Summary
  10. Building Network Web Services with Python
    1. Comparing Python web frameworks
    2. Flask and lab setup
    3. Introduction to Flask
      1. The HTTPie client
      2. URL routing
      3. URL variables
      4. URL generation
      5. The jsonify return
    4. Network resource API
      1. Flask-SQLAlchemy
      2. The network content API
      3. The devices API
      4. The device ID API
    5. Network dynamic operations
      1. Asynchronous operations
    6. Authentication and authorization
    7. Running Flask in containers
    8. Summary
  11. AWS Cloud Networking
    1. AWS setup
      1. The AWS CLI and Python SDK
    2. AWS network overview
    3. Virtual private cloud
      1. Route tables and route targets
      2. Automation with CloudFormation
      3. Security groups and network ACLs
      4. Elastic IP
      5. NAT gateways
    4. Direct Connect and VPN
      1. VPN gateways
      2. Direct Connect
    5. Network scaling services
      1. Elastic Load Balancing
      2. Route 53 DNS service
      3. CloudFront CDN services
    6. Other AWS network services
    7. Summary
  12. Azure Cloud Networking
    1. Azure and AWS network service comparison
    2. Azure setup
    3. Azure administration and APIs
      1. Azure service principal
      2. Python versus PowerShell
    4. Azure global infrastructure
    5. Azure virtual networks
      1. Internet access
      2. Network resource creation
      3. VNet service endpoint
      4. VNet peering
    6. VNet routing
      1. Network security groups
    7. Azure VPNs
    8. Azure ExpressRoute
    9. Azure Network Load Balancers
    10. Other Azure network services
    11. Summary
  13. Network Data Analysis with Elastic Stack
    1. What is the Elastic Stack?
    2. Lab topology
    3. Elastic Stack as a Service
    4. First End-to-End example
    5. Elasticsearch with a Python client
    6. Data ingestion with Logstash
    7. Data ingestion with Beats
    8. Search with Elasticsearch
    9. Data visualization with Kibana
    10. Summary
  14. Working with Git
    1. Content management considerations and Git
    2. Introduction to Git
      1. Benefits of Git
      2. Git terminology
      3. Git and GitHub
    3. Setting up Git
      1. Gitignore
    4. Git usage examples
    5. Git branch
      1. GitHub example
        1. Collaborating with pull requests
    6. Git with Python
      1. GitPython
      2. PyGitHub
    7. Automating configuration backup
    8. Collaborating with Git
    9. Summary
  15. Continuous Integration with Jenkins
    1. The traditional change management process
    2. An introduction to continuous integration
    3. Installing Jenkins
    4. Jenkins example
      1. The first job for the Python script
      2. Jenkins plugins
      3. Network continuous integration example
    5. Jenkins with Python
    6. Continuous integration for networking
    7. Summary
  16. Test-Driven Development for Networks
    1. Test-driven development overview
      1. Test definitions
    2. Topology as code
      1. Python's unittest module
      2. More on Python testing
      3. pytest examples
    3. Writing tests for networking
      1. Testing for reachability
      2. Testing for network latency
      3. Testing for security
      4. Testing for transactions
      5. Testing for network configuration
      6. Testing for Ansible
    4. pytest Integration with Jenkins
      1. Jenkins integration
    5. pyATS and Genie
    6. Summary
  17. Other Books You May Enjoy
  18. Index