Practical Network Automation, - Abhishek Ratan - E-Book

Practical Network Automation, E-Book

Abhishek Ratan

0,0
31,19 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 180

Veröffentlichungsjahr: 2018

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Practical Network AutomationSecond Edition
A beginner's guide to automating and optimizing networks using Python, Ansible, and more
Abhishek Ratan
BIRMINGHAM - MUMBAI

Practical Network Automation Second Edition

Copyright © 2018 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Commissioning Editor: Amey VarangaonkarAcquisition Editor: Heramb BhavsarContent Development Editor: Abhijit SreedharanTechnical Editor: Swathy MohanCopy Editor:Safis EditingProject Coordinator: Jagdish PrabhuProofreader: Safis EditingIndexer: Rekha NairGraphics: Tom ScariaProduction Coordinator: Jyoti Chauhan

First published: November 2017 Second edition: December 2018

Production reference: 1221218

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78995-565-1

www.packtpub.com

mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools, to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

Packt.com

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and, as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

Contributors

About the author

Abhishek Ratanhas around 16 years of technical experience in networking, automation, and various ITIL processes, and has worked in a number of roles in different organizations. As a network engineer, security engineer, automation engineer, TAC engineer, tech lead, and content writer, he has gained a wealth of experience in his career. He also has a keen interest in strategy game playing and, when he is not working on technical stuff, he is busy spending time on his strategy games. He is currently leading the automation and monitoring team, learning, and expanding his automation and Artificial Intelligence skills in the ServiceNow. His previous experience includes working for companies such as Microsoft, Symantec, and Navisite.

I would like to thank the contribution of Harish Kulasekaran in web framework and Ops API and Abhishek Gupta for Alexa Integration.

About the reviewer

Dilip Reddy Guda has acquired expertise in the unified communications domain, along with IP network switching and routing. He has worked on session border controllers, such as CUBE, SIP Server, SIP proxies, CUCM, and CISCO gateways, including SRST, BE4K, CME, and UCCE. He has expertise in SIP protocol, H323, and TDM technologies, along with experience in C++ based application development for Huawei's NGIN solution, and TCL programming. He also has expertise in Python programming involving network device automation, and DevOps framework development.

Skilled in RESTful API development, he is a network programming engineer with experience of Python programming, IP networking domains, and REST API framework development for network automation.

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Practical Network Automation Second Edition

About Packt

Why subscribe?

Packt.com

Contributors

About the author

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

Fundamental Concepts of Network Automation

Technical requirements

A readable script

Basic programs

Validating an IPv4 address

Making the right choice

Hiding credentials

Accessing APIs

Using regular expressions (regex)

Handling files

Making a decision (Python or PowerShell)

API access

Interacting with local machines

Introduction to code check-in and its importance

Git installation and initialization

Code check-in

Sample use cases

First use case

Second use case

Summary

Questions

Python Automation for Network Engineers

Technical requirements

Interacting with network devices

Network device configuration using template

Multithreading

Use cases

Using regular expressions (regex)

Creating loopback interface

Dynamic configuration updates

Summary

Questions

Ansible and Network Templatizations

Technical requirements

Ansible and network templates

Introduction to ad hoc commands

Ansible playbooks

Playbook examples

Ping to a particular IP from all routers

Section 1 – defining the scope of script

Section 2 – defining what to execute (define the task)

Ping to multiple IPs from all routers

Section 1 – basic declarations

Section 2 – declaring variables

Section 3 – executing the task

Section 4 – validations

Network templates

Step 1 – identifying the number of users the device is going to serve

Step 2 – identifying the right configuration based upon the SKU

Step 3 – identifying the role of the device

Python integration

Chef and Puppet

Chef

Step 1 – creating the recipe

Step 2 – uploading the recipe

Step 3 – adding the recipe to the run-list

Step 4 – running the recipe

Puppet

Chef/Puppet/Ansible comparison

Summary

Questions

Using Artificial Intelligence in Operations

Technical requirements

AI in IT operations

Key pillars in AIOps

Data source

Structured data

Non-structured data

Data collector

Data analysis

Machine Learning (ML)

Example of linear regression

Intelligent remediation

Application and use cases

Summary

Questions

Web Framework for Automation Triggers

Technical requirements

Web framework

Falcon

Encoding and decoding

Calling the web framework

Sample use case

Summary

Questions

Continual Integration

Technical requirements

Remediation using intelligent triggers

Step 1 – ensuring Splunk is configured to receive the data

Step 2 – validating the data (sample data)

Step 3 – writing script

Standardizing configurations on scale

Chatbot interactions

Use cases

Interacting with SolarWinds

Configuring Open Shortest Path First (OSPF) through Python

Autonomous System Number (ASN) in BGP

Validating the IPv4 and IPv6 addresses

Summary

Questions

Assessment

Chapter 1: Fundamental Concepts of Network Automation

Chapter 2: Python Automation for Network Engineers

Chapter 3: Ansible and Network Templatizations

Chapter 4: Using Artificial Intelligence in Operations

Chapter 5: Web Framework for Automation Triggers

Chapter 6: Continual Integration

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

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 Aritifical 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 this book is 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 this book covers

Chapter 1, Fundamental Concepts of Network Automation,introduces you to how to get started with automation. This will also help you learn and understand the various important aspects of network automation.

Chapter 2, Python Automation for Network Engineers, walks you through the methods and samples of how to get data and parse through the use of regexes. We will also learn about a number of advanced topics, such as writing Python scripts for network automation. With the help of a use case, readers will be able to automate their network using Python.

Chapter 3, Ansible and Network Templatizations, focuses on using templates for network golden states, and auto deployments of infrastructure using Ansible. We will also learn about how to virtualize Oracle databases and scale dynamically to ensure service levels.

Chapter 4, Using Artificial Intelligence in Operations, includes the implementation of AI in operations in order to perform self healing and remediations.

Chapter 5, Web Framework for Automation Triggers, discusses how to make scalable calls to automation frameworks and generate custom HTML/dynamic pages. This chapter will also cover the performance of complex tasks using API calls, along with the use case toward the end.

Chapter 6, Continual Integration, provides an overview and integration principles for network engineers with a view to managing rapid growth with high availability and rapid disaster recovery.

To get the most out of this book

The hardware and software requirements for this book are Python (3.5 onward), IIS, Windows, Linux, an Ansible installation, and real routers.

You need an internet connection to download the Python libraries. Also, basic knowledge of Python, along with knowledge of networking and basic familiarity with web servers such as IIS, is required.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packt.com

.

Select the

SUPPORT

tab.

Click on

Code Downloads & Errata

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub athttps://github.com/PacktPublishing/Practical-Network-Automation-Second-Edition. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available athttps://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/9781789955651_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "From the installation directory, we just need to invoke python.exe, which will invoke the Python interpreter."

A block of code is set as follows:

index="main" earliest=0 | where interface_name="Loopback45" | dedup interface_name,router_name | where

interface_status="up"

| stats values(interface_name) values(interface_status) by router_name | table router_name

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

# map URL to Classes

app.add_route("/decode", decod)app.add_route('/encode', encod)

Any command-line input or output is written as follows:

pip install gevent

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

Fundamental Concepts of Network Automation

This chapter details some of the key concepts that need to be applied practically before we deep-dive into network-automation-specific examples. As detailed in the first edition, understanding the concepts and how to write a program for network automation is as important as giving out accurate results of a script.

The following topics will be covered in this chapter:

A readable script

Basic programs

Making a decision on which scripting language to use (Python or PowerShell)

Introduction to code check-in and its importance

Sample use cases

Technical requirements

The technical requirements are as follows:

Python (3.5 or above)

PowerShell (5.0 or above)

Windows 8 or

above

(for PowerShell)

The codes for this chapter can be found at https://github.com/PacktPublishing/Practical-Network-Automation-Second-Edition.

A readable script

As network automation/DevOps engineers, we often tend to overlook the way we write a script. The focus is always on providing accurate results, which is great, but as we scale our script or application, a focus on the readability of the script is essential.

This becomes a key requirement when we start to work as a team where we have multiple contributors for a script or set of scripts.

Let's look at an example of a bad Python script that returns the result as expected (output is correct):

x=input("What is your name:") print ("how are you"+x) y="how are you"+x if ("test1" in y) and ("test2" in y): print ("cool") x=y.split(" ") x=x[2]+"awesome" if ("are" in x): print ("not cool")

After the second or third line of code as we read through, we lose the understanding of program flow, and what the expected result was. Eventually, it becomes very difficult to interpret even a simple script such as this.

Imagine how difficult it would be for someone who has not written this code to interpret a bigger script (say, 50 lines).

Now, let's modify this code to make it readable:

#ask for input of user's name and prints it with a message

x=input("What is your name:")print ("how are you"+x)y="how are you"+x

#validates and prints message if 'test1' AND 'test2' exists in input

if ("test1" in y) and ("test2" in y): print ("cool")

#splits the sentence stored in variable x with blank spaces

x=y.split(" ")print (x)

#adds the string "awesome" to the third word in the sentence and stores

it in xx=x[2]+"awesome"

#validates if word "are" is in x and prints the message accordingly

if ("are" in x): print ("not cool")

As we can see, each section (or line) that achieves a specific result is tagged by a remark line (denoted by #). This line is a human-readable line that is ignored by the program (or compiler) and is used to ensure any reader of the program understands what is going on in each section. This ensures that each and every aspect of the script is easily understood by the reader; as the script is enhanced, troubleshooting and modifications in the program become very easy.

Another key aspect in the readability of a program is to ensure we add some key information at the very start of the code.

A generic suggestion would be to include the following:

The author's name

Version of the script (starts with 1.0)

One-liner description of basic usage of the script

Any specific installation requirements

As an example, let 's add this to the very top of the preceding script:

#Name: Abhishek Ratan#Version: 1.0#Usage: Asks for user input and validates it for some specific keywords#Additional installation required: None

Basic programs

Taking this forward, let's write some basic scripts or programs using Python that can help us understand how to leverage Python in our daily automation tasks.