Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering Python Networking
Mastering Python Networking

Mastering Python Networking: Your one stop solution to using Python for network automation, DevOps, and SDN

eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Mastering Python Networking

Low-Level Network Device Interactions

In Chapter 1, Review of TCP/IP Protocol Suite and Python Language, we looked at the theories and specifications behind network communication protocols, and we took a quick tour of the Python language. In this chapter, we will start to dive deeper into the management of these network devices. In particular, we will examine the different ways in which we can use Python to programmatically communicate with legacy network routers and switches.

What do I mean by legacy network routers and switches? While it is hard to imagine any networking device coming out today without an Application Program Interface (API) for automating tasks, it is a known fact that many of the network devices deployed today do not have APIs. The only way to manage them is through Command Line Interfaces (CLI) using terminal programs, which originally were developed with...

The challenges of CLI

At the Interop expo in Las Vegas 2014, BigSwitch Networks CEO Douglas Murray displayed the following slide to illustrate what has changed in Data Center Networking (DCN) in 20 years between 1993 to 2013:

Datacenter Networking Changes (source: https://www.bigswitch.com/sites/default/files/presentations/murraydouglasstartuphotseatpanel.pdf)

While he might be negatively biased toward the incumbent vendors when displaying this slide, the point is well taken. In his opinion, the only thing in managing routers and switches that has changed in 20 years was the protocol changing from Telnet to the more secured SSH. It is right around the same time that we start to see the consensus around the industry for the clear need to move away from manual, human-driven CLI toward an automatic, computer-centric automation API. Make no mistake, we still need to directly communicate...

Constructing a virtual lab

Before we dive into the packages, let's examine the options of putting together a lab for the benefit of learning. As the old saying goes, "Practice Makes Perfect": we need an isolated sandbox to safely make mistakes, try out new ways of doing things, and repeat some of the steps to reinforce concepts that were not clear in the first try. It is easy enough to install Python and the necessary packages for the management host, but what about those routers and switches that we want to simulate?

To put together a network lab, we basically have two options, each with its advantages and disadvantages:

  • Physical device: This option consists of physical devices that you can see and touch. If you are lucky enough, you might be able to put together a lab that is an exact replication of your production environment.
    • Advantages: It is an easy transition...

Python Pexpect Library

Pexpect is a pure Python module for spawning child applications, controlling them, and responding to expected patterns in their output. Pexpect works like Don Libes' Expect. Pexpct allows your script to spawn a child application and control it as if a human were typing commands. - Pexpect Read the Docs, https://pexpect.readthedocs.io/en/stable/index.html

Like the original Expect module by Don Libe, Pexpect launches or spawns another process and watches over it in order to control the interaction. Unlike the original Expect, it is entirely written in Python that does not quire TCL or C extensions to be compiled. This allows us to use the familiar Python syntax and its rich standard library in our code.

Installation

...

The Python Paramiko library

Paramiko is a Python implementation of the SSHv2 protocol. Just like the pxssh subclass of Pexpect, Paramiko simplifies the SSHv2 interaction with the remote device. Unlike pxssh, Paramiko is only focused on SSHv2 and provides both client and server operations.

Paramiko is the low-level SSH client behind the high-level automation framework Ansible for its network modules. We will cover Ansible in the later chapters, so first, let's take a look at the Paramiko library.

Installating Paramiko

Installating Paramiko is pretty straight forward with PIP. However, there is a hard dependency on the Cryptography library. The library provides the low-level, C-based encryption algorithms for the SSH protocol...

Looking ahead

We have taken a pretty huge leap forward as far as automating our network using Python in this chapter. However, the method we have used is somewhat a work-around for the automation. This is mainly due to the fact that the systems were originally built for human.

Downsides of Pexpect and Paramiko compared to other tools

The number one downside for our method so far is that they do not return structured data. They return the data that we find ideal to fit on a terminal to be interpreted by a human but not by a computer program. The human eye can easily interpret a space while the computer only sees a return character. This, of course, depends on the network devices to be made that is automation friendly.

We will...

The challenges of CLI


At the Interop expo in Las Vegas 2014, BigSwitch Networks CEO Douglas Murray displayed the following slide to illustrate what has changed in Data Center Networking (DCN) in 20 years between 1993 to 2013:

Datacenter Networking Changes (source: https://www.bigswitch.com/sites/default/files/presentations/murraydouglasstartuphotseatpanel.pdf)

While he might be negatively biased toward the incumbent vendors when displaying this slide, the point is well taken. In his opinion, the only thing in managing routers and switches that has changed in 20 years was the protocol changing from Telnet to the more secured SSH. It is right around the same time that we start to see the consensus around the industry for the clear need to move away from manual, human-driven CLI toward an automatic, computer-centric automation API. Make no mistake, we still need to directly communicate with the device when making network designs, bringing up initial proof of concepts, and deploying the topology...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Build the skills to perform all networking tasks using Python with ease
  • Use Python for network device automation, DevOps, and software-defined networking
  • Get practical guidance to networking with Python

Description

This book begins with a review of the TCP/ IP protocol suite and a refresher of the core elements of the Python language. Next, you will start using Python and supported libraries to automate network tasks from the current major network vendors. We will look at automating traditional network devices based on the command-line interface, as well as newer devices with API support, with hands-on labs. We will then learn the concepts and practical use cases of the Ansible framework in order to achieve your network goals. We will then move on to using Python for DevOps, starting with using open source tools to test, secure, and analyze your network. Then, we will focus on network monitoring and visualization. We will learn how to retrieve network information using a polling mechanism, ?ow-based monitoring, and visualizing the data programmatically. Next, we will learn how to use the Python framework to build your own customized network web services. In the last module, you will use Python for SDN, where you will use a Python-based controller with OpenFlow in a hands-on lab to learn its concepts and applications. We will compare and contrast OpenFlow, OpenStack, OpenDaylight, and NFV. Finally, you will use everything you’ve learned in the book to construct a migration plan to go from a legacy to a scalable SDN-based network.

Who is this book for?

If you are a network engineer or a programmer who wants to use Python for networking, then this book is for you. A basic familiarity with networking-related concepts such as TCP/IP and a familiarity with Python programming will be useful.

What you will learn

  • Review all the fundamentals of Python and the TCP/IP suite
  • Use Python to execute commands when the device does not support the API or programmatic interaction with the device
  • Implement automation techniques by integrating Python with Cisco, Juniper, and Arista eAPI
  • Integrate Ansible using Python to control Cisco, Juniper, and Arista networks
  • Achieve network security with Python
  • Build Flask-based web-service APIs with Python
  • Construct a Python-based migration plan from a legacy to scalable SDN-based network

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 28, 2017
Length: 446 pages
Edition : 1st
Language : English
ISBN-13 : 9781784397623
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Jun 28, 2017
Length: 446 pages
Edition : 1st
Language : English
ISBN-13 : 9781784397623
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 203.97
Linux: Powerful Server Administration
$99.99
Mastering Python Networking
$54.99
Applied Network Security
$48.99
Total $ 203.97 Stars icon

Table of Contents

13 Chapters
Review of TCP/IP Protocol Suite and Python Language Chevron down icon Chevron up icon
Low-Level Network Device Interactions Chevron down icon Chevron up icon
API and Intent-Driven Networking Chevron down icon Chevron up icon
The Python Automation Framework - Ansible Basics Chevron down icon Chevron up icon
The Python Automation Framework - Ansible Advance Topics Chevron down icon Chevron up icon
Network Security with Python Chevron down icon Chevron up icon
Network Monitoring with Python - Part 1 Chevron down icon Chevron up icon
Network Monitoring with Python - Part 2 Chevron down icon Chevron up icon
Building Network Web Services with Python Chevron down icon Chevron up icon
OpenFlow Basics Chevron down icon Chevron up icon
Advanced OpenFlow Topics Chevron down icon Chevron up icon
OpenStack, OpenDaylight, and NFV Chevron down icon Chevron up icon
Hybrid SDN Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(10 Ratings)
5 star 80%
4 star 0%
3 star 10%
2 star 10%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




CPM 3 Oct 19, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a MUST HAVE for any Network Engineer. Automation with Python is a skill that most engineers need to have moving forward. This book is a great guide those wanting to gain that skill.
Amazon Verified review Amazon
Josh Van Deraa Apr 03, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Sets the basics needed in the network coding world. Also a good chapter on creating a network API. I would recommend as the getting started in network programming.
Amazon Verified review Amazon
Eric Mar 26, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I bought this book after the author did an interview/run down on packet pushers. It's an awesome well written book that should be considered everyone's first peek at devops.
Amazon Verified review Amazon
routerguy Sep 11, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you're looking for guidance on how to use python and python based tools to manage network equipment, this book is for you. This book is full of clear and useful examples that you can put to work on your network today. Make certain your configurations are consistently deployed, rapidly respond to changing requirements, ask for a raise! Strongly recommended!
Amazon Verified review Amazon
Amazon Customer Jun 10, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good stuff!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.