Mastering Python Networking
eBook - ePub

Mastering Python Networking

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

Eric Chou

Share book
  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

Eric Chou

Book details
Book preview
Table of contents
Citations

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

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
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.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
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.
Do you support text-to-speech?
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.
Is Mastering Python Networking an online PDF/ePUB?
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 & Programming in Python. We have over one million books available in our catalogue for you to explore.

Information

Year
2020
ISBN
9781839218675
Edition
3

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