Mastering Python Networking
eBook - ePub

Mastering Python Networking

Your one-stop solution to using Python for network automation, programmability, and DevOps, 3rd Edition

  1. 576 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering Python Networking

Your one-stop solution to using Python for network automation, programmability, and DevOps, 3rd Edition

About this book

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.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere β€” even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Mastering Python Networking by Eric Chou in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Networking. We have over one million books available in our catalogue for you to explore.

Information

7

Network Monitoring with Python – Part 1

Imagine you get a call from your company's network operations center at 2:00 a.m. in the morning. The person on the other end says: "Hi, we are facing a difficult issue that is impacting production services. We suspect it might be network related. Can you check this for us?" For this type of urgent, open-ended question, what would be the first thing you do? Most of the time, the thing that comes to mind would be: What changed in the time between when the network was working and when something went wrong? Chances are you would check your monitoring tool and see if any of the key metrics changed in the last few hours. Better yet, you may have received monitoring alerts for any metrics that deviated from the normal baseline numbers.
Throughout this book, we have been discussing various ways to systematically make predictable changes to our network, with the goal of keeping the network running as smoothly as possible. However, networks are not static – far from it – they are probably one of the most fluid parts of the entire infrastructure. By definition, a network connects different parts of the infrastructure together, constantly passing traffic back and forth.
There are lots of moving parts that can cause your network to stop working as expected: hardware failures, software with bugs, human mistakes despite their best intentions, and many more. It is not a question of whether things will go wrong, but rather a question of when and what will go wrong when it happens. We need ways to monitor our network to make sure it works as expected and hopefully be notified when it does not.
In the upcoming two chapters, we will look at various ways to perform network monitoring tasks. Many of the tools we have looked at thus far can be tied together or directly managed by Python. Like many tools we have looked at, network monitoring has two parts.
First, we need to know what information the equipment is capable of transmitting. Second, we need to identify what useful information we can interpret from it.
In this chapter, we will begin by looking at a few tools that allow us to monitor the network effectively:
  • The lab setup
  • The Simple Network Management Protocol (SNMP) and related Python libraries to work with SNMP
  • Python visualization libraries:
    • Matplotlib and examples
    • Pygal and examples
  • Python integration with MRTG and Cacti for network visualization
This list is not exhaustive, and there is certainly no lack of commercial vendors in the network monitoring space. The basics of network monitoring that we will look at, however, carry well for both open source and commercial tools.

Lab setup

The lab for this chapter is similar to the one in Chapter 6, Network Security with Python, but with this difference: both of the network devices are IOSv devices. Here's an illustration of this:
Figure 1: Lab topology
The two Ubuntu hosts will be used to generate traffic across the network so that we can look at some non-zero counters.

SNMP

SNMP is a standardized protocol used to collect and manage devices. Although the standard allows you to use SNMP for device management, in my experience, most network administrators prefer to keep SNMP as an information collection mechanism only. Since SNMP operates on UDP, which is connectionless, and considering the relatively weak security mechanism in versions 1 and 2, making device changes via SNMP tends to make network operators a bit uneasy. SNMP version 3 has added cryptographic security and new concepts and terminology to the protocol, but the way SNMP version 3 is adapted varies among network device vendors.
SNMP is widely used in network monitoring and has been around since 1988 as part of RFC 1065. The operations are straightforward, with the network manager sending GET and SET requests toward the device and the device with the SNMP agent responding with the information per request. The most widely adopted standard is SNMPv2c, which is defined in RFC 1901 – RFC 1908. It uses a simple community-based security scheme for security. It has also introduced new features, such as the ability to get bulk information. The following diagram displays the high-level operation for SNMP:
Fi...

Table of contents

  1. Why subscribe?
  2. Preface
  3. Review of TCP/IP Protocol Suite and Python
  4. Low-Level Network Device Interactions
  5. APIs and Intent-Driven Networking
  6. The Python Automation Framework – Ansible Basics
  7. The Python Automation Framework – Beyond Basics
  8. Network Security with Python
  9. Network Monitoring with Python – Part 1
  10. Network Monitoring with Python – Part 2
  11. Building Network Web Services with Python
  12. AWS Cloud Networking
  13. Azure Cloud Networking
  14. Network Data Analysis with Elastic Stack
  15. Working with Git
  16. Continuous Integration with Jenkins
  17. Test-Driven Development for Networks
  18. Other Books You May Enjoy