Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Practical Network Automation
Practical Network Automation

Practical Network Automation: A beginner's guide to automating and optimizing networks using Python, Ansible, and more , Second Edition

eBook
R$80 R$196.99
Paperback
R$245.99
Subscription
Free Trial
Renews at R$50p/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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Practical Network Automation

Python Automation for Network Engineers

This chapter will introduce ways to interact with network devices using Python. We will also see certain use cases on configuring network devices using configuration templates, and also write a modular code to ensure high reusability of the code to perform repetitive tasks. We will also see the benefits of parallel processing of tasks and the efficiency that can be gained through multithreading.

The following topics will be covered in this chapter:

  • Interaction of network devices
  • Network device configuration using template
  • Multithreading
  • Use cases

Technical requirements

Interacting with network devices

Python is widely used to perform multiple tasks. One of the tasks that widely uses Python is network automation. With its wide set of libraries (such as Netmiko and Paramiko), there are endless possibilities for network device interactions for different vendors. Owing to the support of Python, the list of supported devices continues to expand with the developer community, adding support for additional vendors as they are introduced to market.

Before we proceed to interact with devices, let us understand one of the most widely used libraries for network interactions. We will be using Netmiko to perform our network interactions.

Netmiko (https://github.com/ktbyers/netmiko) is a library/module in Python that is used extensively to interact with network devices. This is a multi-vendor library with support for Cisco IOS, NX-OS, firewalls, and many other...

Network device configuration using template

With all the routers reachable and accessible through SSH, let us configure a base template that sends the Syslog to a Syslog server and additionally ensures that only information logs are sent to the Syslog server. Also, after configuration, a validation needs to be performed to ensure that logs are being sent to the Syslog server.

The logging server info is as follows:

  • Logging server IP: 192.168.20.5
  • Logging port: 514
  • Logging protocol: TCP

Additionally, a loopback interface (loopback 30) needs to be configured with the {rtr} loopback interface description.

The code lines for the template are as follows:

logging host 192.168.20.5 transport tcp port 514
logging trap 6
interface loopback 30
description "{rtr} loopback interface"

To validate that the Syslog server is reachable, and that the logs sent are informational, use the...

Multithreading

A key focus area while performing operations on multiple devices is how quickly we can perform the actions. To put this into perspective, if each router takes around 10 seconds to log in, gather the output, and log out, and we have around 30 routers that we need to get this information from, we would need 10*30 = 300 seconds for the program to complete the execution. If we are looking for more advanced or complex calculations on each output, which might take up to a minute, then it will take 30 minutes for just 30 routers.

This starts becoming very inefficient when our complexity and scalability grows. To help with this, we need to add parallelism to our programs. What this simply means is that we log in simultaneously on all 30 routers, and perform the same task to fetch the output at the same time. Effectively, this means that we now get the output on all 30 routers...

Use cases

We will now review the topics discussed through some use cases that are being used as common scenarios. These use cases, along with helping us to understand the concepts, can also be leveraged or enhanced to create complex automation that can perform actions at very large scale.

Using regular expressions (regex)

Let us examine a basic use of regex by parsing a base configuration containing the interface configuration of a router.
The task is to identify the interfaces that have
trunk enabled:

import re
sampletext="""
interface fa0/1
switchport mode trunk
no shut

interface fa0/0
no shut

interface fa1/0
switchport mode trunk
no shut

interface fa2/0
shut

interface fa2/1
switchport mode trunk
no shut

interface te3...

Summary

In this chapter, we learned how to interact with Network devices through Python. We got familiar with an extensively used library of Python (Netmiko) for network interactions. Readers also got an insight into how to interact with multiple network devices using a simulated lab in GNS3 through examples on config generation and implementation through network templates.

Additionally, we also got to know the device interaction through SNMP, which is an industry standard method of interaction with various infrastructure devices. Using examples, we saw how to fetch types of devices as well as interface stats on each router in a quick and efficient manner.

Additionally, we also touched base on multithreading, which is a key component in scalability through various examples. To sum this aspect up, we saw certain use cases that are a real-life challenge for any network engineer...

Questions

  1. Does Netmiko support only Cisco-based devices? (Yes/No)

  2. Are the preferred hardware specifications for multithreading an entry-level machine or a high-end machine?

  3. Can we use SNMP to push any configuration on a Cisco router? (Yes/No)

  4. To push multiline configuration on a router through Netmiko, do we use a comma-separated string or a list?

  5. Efficiency-wise, is extracting the version of the Cisco router faster from Netmiko or SNMP?

  6. Does the network template needs to be hardcoded in a script when we want to push to a router? (Yes/ No)

  7. What is the term used for authenticating SNMP information from a router?

  8. Name of Python library/module used to create multiple threads.

  9. Name of Python library/module used to fetch information from network devices using SNMP.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Get introduced to the concept of network automation with relevant use cases
  • Apply Continuous Integration and DevOps to improve your network performance
  • Implement effective automation using tools such as Python, Ansible, and more

Description

Network automation is the use of IT controls to supervise and carry out everyday network management functions. It plays a key role in network virtualization technologies and network functions. The book starts by providing an introduction to network automation, and its applications, which include integrating DevOps tools to automate the network efficiently. It then guides you through different network automation tasks and covers various data digging and performing tasks such as ensuring golden state configurations using templates, interface parsing. This book also focuses on Intelligent Operations using Artificial Intelligence and troubleshooting using chatbots and voice commands. The book then moves on to the use of Python and the management of SSH keys for machine-to-machine (M2M) communication, all followed by practical use cases. The book also covers the importance of Ansible for network automation, including best practices in automation; ways to test automated networks using tools such as Puppet, SaltStack, and Chef; and other important techniques. Through practical use-cases and examples, this book will acquaint you with the various aspects of network automation. It will give you the solid foundation you need to automate your own network without any hassle.

Who is this book for?

If you are a network engineer or a DevOps professional looking for an extensive guide to help you automate and manage your network efficiently, then this book is for you. No prior experience with network automation is required to get started, however you will need some exposure to Python programming to get the most out of this book.

What you will learn

  • Get started with the fundamental concepts of network automation
  • Perform intelligent data mining and remediation based on triggers
  • Understand how AIOps works in operations
  • Trigger automation through data factors
  • Improve your data center s robustness and security through data digging
  • Get access infrastructure through API Framework for chatbot and voice interactive troubleshootings
  • Set up communication with SSH-based devices using Netmiko

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 26, 2018
Length: 226 pages
Edition : 2nd
Language : English
ISBN-13 : 9781789950403
Vendor :
Red Hat
Languages :
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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 26, 2018
Length: 226 pages
Edition : 2nd
Language : English
ISBN-13 : 9781789950403
Vendor :
Red Hat
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 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
R$500 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 R$25 each
Feature tick icon Exclusive print discounts
R$800 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 R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 736.97
Python Automation Cookbook
R$217.99
Hands-On RESTful Python Web Services
R$272.99
Practical Network Automation
R$245.99
Total R$ 736.97 Stars icon

Table of Contents

8 Chapters
Fundamental Concepts of Network Automation Chevron down icon Chevron up icon
Python Automation for Network Engineers Chevron down icon Chevron up icon
Ansible and Network Templatizations Chevron down icon Chevron up icon
Using Artificial Intelligence in Operations Chevron down icon Chevron up icon
Web Framework for Automation Triggers Chevron down icon Chevron up icon
Continual Integration Chevron down icon Chevron up icon
Assessment Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(2 Ratings)
5 star 0%
4 star 50%
3 star 0%
2 star 50%
1 star 0%
Paul Sep 05, 2021
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Would be 5 stars if it didn't have random stupid errors throughoutFor example p58, the code in the book is missing the function "puchconfig" and the only way to learn to code is to code not copy and paste. Found the missing function in the downloaded zip file..Good overall book though and would recommend..
Amazon Verified review Amazon
Fizzle Mar 05, 2022
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Got lost in the very first chapter because the author introduces Netmiko but does not show how to verify it and does not explain the order of commands and what we should expect at every turn. This is supposed to be a beginner`s guide? Why start by showing a bunch of use cases in different languanges. You did not even properly introduce those languages or how to acquire them and install them and know that the installation is good and then the first steps. Now I have to put down my new book and search Youtube were everyone is doing it with different hardware, and SW, and platforms. This book has powerful things but is an intermediate book.
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.