Programming And Automating Cisco Networks

3y ago
295 Views
76 Downloads
1.15 MB
94 Pages
Last View : 25d ago
Last Download : 3m ago
Upload by : Milena Petrie
Transcription

Programming andAutomating CiscoNetworksRyan Tischer, CCIE No. 11459Jason Gooley, CCIE No. 38759 (R&S & SP)Cisco Press800 East 96th StreetIndianapolis, Indiana 46240 USA

iiProgramming and Automating Cisco NetworksProgramming and Automating Cisco NetworksRyan TischerJason GooleyCopyright 2017 Cisco Systems, Inc.Published by:Cisco Press800 East 96th StreetIndianapolis, IN 46240 USAAll rights reserved. No part of this book may be reproduced or transmitted in any form or by any means,electronic or mechanical, including photocopying, recording, or by any information storage and retrievalsystem, without written permission from the publisher, except for the inclusion of brief quotations in areview.Printed in the United States of AmericaFirst Printing August 2016Library of Congress Control Number: 2016942372ISBN-13: 978-1-58714-465-3ISBN-10: 1-58714-465-4Warning and DisclaimerThis book is designed to provide information about network programmability and automation of CiscoData Center, Campus, and WAN networks. Every effort has been made to make this book as completeand as accurate as possible, but no warranty or fitness is implied.The information is provided on an “as is” basis. The authors, Cisco Press, and Cisco Systems, Inc. shallhave neither liability nor responsibility to any person or entity with respect to any loss or damagesarising from the information contained in this book or from the use of the discs or programs that mayaccompany it.The opinions expressed in this book belong to the author and are not necessarily those of CiscoSystems, Inc.Trademark AcknowledgmentsAll terms mentioned in this book that are known to be trademarks or service marks have beenappropriately capitalized. Cisco Press or Cisco Systems, Inc., cannot attest to the accuracy of thisinformation. Use of a term in this book should not be regarded as affecting the validity of any trademarkor service mark.

iiiSpecial SalesFor information about buying this title in bulk quantities, or for special sales opportunities (which mayinclude electronic versions; custom cover designs; and content particular to your business, training goals,marketing focus, or branding interests), please contact our corporate sales department at corpsales@pearsoned.com or (800) 382-3419.For government sales inquiries, please contact governmentsales@pearsoned.com.For questions about sales outside the U.S., please contact intlcs@pearson.com.Feedback InformationAt Cisco Press, our goal is to create in-depth technical books of the highest quality and value. Each bookis crafted with care and precision, undergoing rigorous development that involves the unique expertise ofmembers from the professional technical community.Readers’ feedback is a natural continuation of this process. If you have any comments regarding how wecould improve the quality of this book, or otherwise alter it to better suit your needs, you can contact usthrough email at feedback@ciscopress.com. Please make sure to include the book title and ISBN in yourmessage.We greatly appreciate your assistance.Editor-in-Chief: Mark TaubTechnical Editor(s): Joe Clarke, Omar SultanProduct Line Manager: Brett BartowEditorial Assistant: Vanessa EvansAlliances Manager, Cisco Press: Ronald FliggeCover Designer: Chuti PrasertsithManaging Editor: Sandra SchroederComposition: codeMantraDevelopment Editor: Ellie C. BruIndexer: Erika MillenProject Editor: Mandie FrankProofreader: KamalakannanCopy Editor: Lori Martinsek

ivProgramming and Automating Cisco NetworksAbout the AuthorsRyan Tischer, CCIE No. 11459 is a Technical Solution Architect at Cisco wherehe focuses on SDN, Cloud, and network programmability. He has worked in IT for20 years, specifically focused on design, deployment, and operations of networkingtechnologies. Ryan holds a BA in Information Technology from the University ofMassachusetts, Lowell and a MS in Network Engineering from Depaul University.Ryan lives with his wife and children in the Milwaukee, WI area. Ryan blogs athttp://Policyetc.com.Jason Gooley, CCIE No. 38759 (R&S & SP), is a very enthusiastic engineer that ispassionate about helping others in the industry succeed. Jason has more than 20 yearsof experience in the Information Technology and Telecommunications industry.Jason currently works at Cisco as a Strategic Systems Engineer where he specializesin SD-WAN, campus, and data center network design. In addition, Jason works withLearning@Cisco on certification development, mentoring, and training. Jason is also aProgram Committee member and organizer for the Chicago Network Operators Group(CHINOG). Jason lives in Illinois with his wife Jamie and their daughter Kaleigh.

vAbout the Technical ReviewersJoe Clarke, CCIE No. 5384 is a Global TAC engineer. He has contributed to networkmanagement products and technologies by finding and fixing bugs, as well asimplementing maintenance and troubleshooting components in Cisco Prime.Joe helps to support and enhance the embedded automation and programmabilitytechnologies, such as the Embedded Event Manager, Tcl, NETCONF/RESTCONF, andONE Platform Kit (onePK). Joe is a top-rated speaker at Cisco’s annual user conference,CiscoLive!, as well as certified as a Cisco Certified Internetworking Expert, CertifiedJava Programmer, and VMware Certified Professional. Joe provides network consultingand design support for the Internet Engineering Task Force (IETF) conference networkinfrastructure deployments. He has authored numerous technical documents on Cisconetwork management, automation, and programmability products and technologies. Joeis co-author of more than 20 Cisco patents. He is an alumnus of the University of Miamiand holds a Bachelor of Science degree in computer science. Outside of Cisco, Joe is amember of the FreeBSD project. He is a committer in the project focusing mainly on theGNOME Desktop. He also maintains the FreeBSD ports Tinderbox application, whichfacilitates the automated packaging and testing of FreeBSD third-party ports.Omar Sultan currently leads a team of sales managers and product managers focusedon Cisco’s web and cloud customers. At Cisco since 1999, Omar has focused on helpingthe company successfully enter new markets and is currently focused on the softwareand hardware technologies that underpin web-scale infrastructure. A geek at heart, Omarhas been involved with IT since VAXes roamed the earth. Omar has been involved inevery aspect of IT from cabling to coding to systems and networking, which has left himthe perspective that data centers should really be viewed as their own class of quirkycomplex life forms.

viProgramming and Automating Cisco NetworksDedicationsRyan Tischer:This book is dedicated to my wife Jennifer and my children Madeline, Alexander, andElaina. When the road gets rough, you are the reason I do not give up. When scaryarrives, you are the source for my courage. When good enough is reached, you make mepush for better. When things don’t go my way, you make me substitute my cuss words.ILMF4EVERSpecial thank you to my parents—Stop saying I turned out all right; there’s still time.To my friends—I know the best place for chili.A message to my children—Whatever your life has in store for you, be curiouspassionatethoughtfulBreak ground and glassBe anything but boring.—RyanJason Gooley:I would like to dedicate this book to my family. To my wife Jamie for being so endlesslysupportive of me with my various “projects.” Without you, I would not have beenable to make it this far. To my daughter Kaleigh, who at the time of this writing is just15 months old: It is extremely difficult to leave your side when all I want to do is spendtime with you. I feel like I have already missed so much just writing this paragraph!To my father and brother for always having my back and believing in me. To my latemother, you have been the guiding light that has kept me on the right path.

viiAcknowledgmentsRyan Tischer:I’d like to give special recognition to the amazing engineers, managers, sales teams,and customers I have the privilege of working with. I am humbled to be a part ofthis community, and I fully recognize that without your inspiration, encouragement,and knowledge, this book would not be possible. I have been truly blessed to havemanagers and co-workers who believe in me, told me when I screwed up, and gave methe opportunity of a lifetime. Special thank you to INSBU for building wickedly-coolproducts and letting me play.A big thank you to Joe Clark, Omar Sultan, Brett Bartow, and Eleanor Bru for theiramazing work on this book.Finally, I’d like to thank my co-author Jason Gooley. I approached him with this projectat the very last minute, and he’s worked very hard to keep the book on time, while notsacrificing technical depth or content.Jason Gooley:First, thank you to Brett Bartow, Eleanor Bru, and the rest of the Cisco Press team forall of the support during creation of this book. It was a pleasure to work with such anamazing group of professionals.I would like to thank the entire Cisco Commercial Midwest Select Operation forsupporting me during this process. Thank you to my manager and all of my teammateson the Illinois Select team for the continued reinforcement of this project.A special thanks to Anthony Sequeira, Keith Barker, Andre Laurent, and Luke Kaelin forall the mentoring and words of encouragement. I can’t thank you enough for all of yoursupport over the years.Thank you, Ryan, for giving me the opportunity to write this book with you. It has beenan absolute blast, and I am honored to be a part of it.Finally, I would like to thank all my friends and family who have patiently waited for meto finish this project, so I would be able to go outside and play. You know who you are!

viiiProgramming and Automating Cisco NetworksContents at a GlanceIntroductionxviiiSection IGetting Started with Network ProgrammabilityChapter 1Introduction: Why Network ProgrammabilityChapter 2Foundational Skills113Section II Cisco Programmable Data CenterChapter 3Next-Generation Cisco Data Center Networking67Chapter 4On-Box Programmability and Automation with Cisco Nexus NX-OS83Chapter 5Off-Box Programmability and Automation with Cisco Nexus NX-OS125Chapter 6Network Programmability with Cisco ACI159Section III Cisco Programmable Campus and WANChapter 7On-Box Automation and Operations ToolsChapter 8Network Automation Tools for Campus EnvironmentsChapter 9Piecing It All TogetherIndex307303215255

ixContentsIntroductionSection IChapter 1xviiiGetting Started with Network ProgrammabilityIntroduction: Why Network ProgrammabilityWhat Is Network ProgrammabilityNetwork Programmability BenefitsSimplified Networking44Network Innovation with ProgrammabilityCloud, SDN, and Network ProgrammabilitySDN468Is Programmability a New Idea?Network AutomationSummary910Automation ExampleChapter 2131111Foundational Skills13Introduction to Software Development13Common Constructs—Variables, Flow Control, Functions,and Objects 15Variables15Flow Control—ConditionsFlow Control—LoopsFunctionsObjects17181819A Basic Introduction to PythonMore on StringsHelp!2223Flow Control24Python ConditionsPython LoopsWhile Loop242526Python FunctionsPython Files2829Importing Libraries30Installing Python LibrariesUsing PIP313020

xProgramming and Automating Cisco NetworksUsing Common Python LibrariesAPIs and SDKs3137Web Technologies37Web Technologies—Data FormattingXML38JSON39Google PostmanUsing Postman384040Using JSON in Python43Basic Introduction to Version Control, Git, and GitHubGit—Add a File47Creating and Editing Source CodeGetting Started with PyCharm4950Writing Code in PyCharm—Get the WeatherDebugging in PyCharmIntroduction to LinuxWorking in LinuxLinux Architecture54555658Display Linux ProcessUsing Systemd5961Linux File System and PermissionsLinux Directories6364Installing Applications on LinuxWhere to Go for HelpSummary53646566Section IICisco Programmable Data CenterChapter 3Next-Generation Cisco Data Center NetworkingCisco Application-Centric Infrastructure (ACI)Nexus Data Broker74Use Case—Nexus Data Broker75Evolution of Data Center Network ArchitectureCisco Data Center Network ControllersNexus Fabric Manager80Virtual Topology System (VTS)Cisco ACISummary8281708180766745

ContentsChapter 4On-Box Programmability and Automationwith Cisco Nexus NX-OS 83Open NX-OS Automation—Bootstrap and ProvisioningCisco POAP83Cisco Ignite87Using Ignite87NX-OS iPXE88Bash88Bash Scripting89Bash Variables, Conditions, and LoopsBash Arithmetic8990Bash Conditions and Flow ControlBash Redirection and Pipes94Working with Text in Bash96Awk839198Bash on Nexus 9000ifconfig101Tcpdumpethtool99101103Run a Bash Script at Startup103Bash Example—Configure NTP Servers at bootLinux Containers (LXC)106Network Access in Guestshell109Installing Applications in Guestshell110Puppet Agent Installation in GuestshellNMap Installation in GuestshellEmbedded Nexus Data Broker111111Nexus Embedded Event ManagerEEM Variables112113On-box Python Scripting113Using the NX-OS Python CLI LibraryUsing NX-OS Cisco Python LibraryNon-Interactive PythonCisco or CLI Package?118EEM Neighbor Discovery124115116118On-Box Python—Use Cases and ExamplesSummary111121118106xi

xiiProgramming and Automating Cisco NetworksChapter 5Off-Box Programmability and Automation withCisco Nexus NX-OS 125Nexus NX-API125NX-API Transport125NX-API Message FormatNX-API Security126NX-API Sandbox127126Using NX-API in Python129Configuring an IP Address with Python and NX-APINX-API REST: An Object-Oriented Data ModelNX-API REST Object Model Data133Authenticating to NX-API (nxapi auth cookie)136Changing NX-API Objects Data via Postman138Modifying NX-API Objects Data via Python140NX-API Event SubscriptionNXTool Kit143146Using NXTool Kit146NXTool Kit BGP Configuration148Automation and DevOps Tools151Puppet152Using PuppetChapter 6131153Puppet and Nexus 9000154Ansible and Nexus 9000157Summary158Resources158Network Programmability with Cisco ACICisco ACI Automation160ACI Policy InstantiationA Bit More PythonVirtualenv161162162Virtualenv in PyCharm166Python Exceptions HandlingACI Fundamentals166169ACI Management Information ModelACI Object NamingFault Severity170173ACI Health Scores174169159130

ContentsACI Programmability174Invoking the API176GUI178APIC Object Save-as178APIC API Inspector179APIC Object Store Browser (Visore)APIC API Authentication182185Using Python to Authenticate to APIC186Using Postman to Automate APIC ConfigurationsUsing Postman188Creating New Postman Calls189Programmability Using the APIC RESTful APIACI Event SubscriptionCobra SDK188192196198Using APIC Cobra200Working with Objects202Example Cobra SDK—Creating a CompleteTenant Configuration 204APIC REST Python Adapter (Arya)Using AryaLogger207208APIC Automation with UCS DirectorSummary211213Section IIICisco Programmable Campus and WANChapter 7On-Box Automation and Operations ToolsAutomated Port ProfilingAutoSmart Ports215216216Enabling AutoSmart Ports on a Cisco Catalyst SwitchAutoConf217220Enabling AutoConf on a Cisco Catalyst SwitchModifying a Built-in TemplateAuto Security222224227Enabling Auto Security on a Cisco Catalyst SwitchQuality of Service for Campus ArchitecturesAutoQoS on Campus LAN Devices230230Enabling AutoQoS on a Cisco Catalyst Switch231228xiii

xivProgramming and Automating Cisco NetworksAutoQoS on Campus WAN Devices233Enabling AutoQoS on a Cisco ISR Router234Automating Management and Monitoring TasksSmart Call Home236236Enabling Smart Call Home on an Cisco Catalyst SwitchTcl Shell243Embedded Event Manager (EEM)EEM AppletsEEM SummaryChapter 8246246EEM and Tcl ScriptsSummary251253253Network Automation Tools for Campus EnvironmentsData Models and Supporting ProtocolsYANG Data ModelsNETCONFConfD237255256256258259Application Policy Infrastructure Controller Enterprise Module(APIC-EM) 263APIC-EM Architecture263APIC-EM Applications264Intelligent WAN (IWAN) ApplicationPlug and Play (PnP) ApplicationPath Trace Application276Additional APIC-EM FeaturesTopology264269279279Device Inventory281Easy Quality of Service (Easy QoS)Dynamic QoS283285Policy Application286APIC-EM Programmability Examples Using PostmanTicket APIHost API288291288

ContentsNetwork Device APIUser API292294Available APIC-EM APIs296APIC-EM Programmability Examples Using PythonTicket APIHost APISummaryChapter 9297299302Piecing It All TogetherIndex307303297xv

xviProgramming and Automating Cisco NetworksReader ServicesRegister your copy at www.ciscopress.com/title/ISBN for convenient access todownloads, updates, and corrections as they become available. To start the registrationprocess, go to www.ciscopress.com/register and log in or create an account.* Enter theproduct ISBN 9781587144653 and click Submit. Once the process is complete, you willfind any available bonus content under Registered Products.*Be sure to check the box that you would like to hear from us to receive exclusivediscounts on future editions of this product.

xviiIcons Used in This BookCommunicationServerPC withSoftwarePCMacintoshAccessServerISDN/Frame orkstationTokenRingToken nframeFront atewayRouterNetwork CloudBridgeLine: EthernetHubLine: SerialDSU/CSUDSU/CSUFDDICatalystSwitchLine: Switched SerialCisco ASACommand Syntax ConventionsThe conventions used to present command syntax in this book are the same conventionsused in the IOS Command Reference. The Command Reference describes theseconventions as follows: Boldface indicates commands and keywords that are entered literally as shown.In actual configuration examples and output (not general command syntax), boldfaceindicates commands that are manually input by the user (such as a show command). Italic indicates arguments for which you supply actual values. Vertical bars ( ) separate alternative, mutually exclusive elements. Square brackets ([ ]) indicate an optional element. Braces ({ }) indicate a required choice. Braces within brackets ([{ }]) indicate a required choice within an optional element.

xviiiProgramming and Automating Cisco NetworksIntroductionThis book was designed with the focus on utilizing Cisco ACI Cisco Nexus 9000, CiscoUCS Director, Cisco (JSON), Python, Linux, Cisco APIC-EM, ConfD, and Data Modelsin a production environment as effectively as possible. Industry leaders were consultedfor technical accuracy throughout this book.Who Should Read This Book?This book is designed for those network engineers and operators who want toimplement, manage, and maintain Cisco networking solutions in modern environments.This book discusses automation and programming tools and techniques across the Ciscodata center, campus, and LAN and WAN technologies.How This Book Is OrganizedChapter 1, “Introduction: Why Network Programmability:” Networkprogrammability can solve business problems, reduce operating expenses and increasebusiness agility. Current network management is slow and prone to errors because it’s aclosed, box-by-box, CLI-driven system that requires constant and expensive attention.Network programmability serves as a tool kit to automate network configurations andtroubleshooting, significantly reducing nonoperational states. Additionally networkprogrammability allows the network to participate or add value to dynamic applicationenvironments, that is, DevOps, web, security, by facilitating a tight bond betweenapplications and infrastructure.Chapter 2, “Foundational Skills:” A basic introduction into software engineering andDEVOPS.Chapter 3, “Next-Generation Cisco Data Center Networking:” This chapter discussesCisco portfolio and where the reader could possibly implement network programmabilityand automation.Chapter 4, “On-Box Programmability and Automation with Cisco Nexus NX-OS:”This chapter discusses writing software designed to run on the Nexus switch.Chapter 5, “Off-Box Programmability and Automat

Chapter 2 Foundational Skills 13 Section II Cisco Programmable Data Center Chapter 3 Next-Generation Cisco Data Center Networking 67 Chapter 4 On-Box Programmability and Automation with Cisco Nexus NX-OS 83 Chapter 5 Off-Box Programmability and Automation with Cisco Nexus NX-OS 125 Chapter 6 Network Programmability with Cisco ACI 159

Related Documents:

Cisco ASA 5505 Cisco ASA 5505SP Cisco ASA 5510 Cisco ASA 5510SP Cisco ASA 5520 Cisco ASA 5520 VPN Cisco ASA 5540 Cisco ASA 5540 VPN Premium Cisco ASA 5540 VPN Cisco ASA 5550 Cisco ASA 5580-20 Cisco ASA 5580-40 Cisco ASA 5585-X Cisco ASA w/ AIP-SSM Cisco ASA w/ CSC-SSM Cisco C7600 Ser

Apr 05, 2017 · Cisco 4G LTE and Cisco 4G LTE-Advanced Network Interface Module Installation Guide Table 1 Cisco 4G LTE NIM and Cisco 4G LTE-Advanced NIM SKUs Cisco 4G LTE NIM and Cisco 4G LTE-Advanced NIM SKUs Description Mode Operating Region Band NIM-4G-LTE-LA Cisco 4G LTE NIM module (LTE 2.5) for LATAM/APAC carriers. This SKU is File Size: 2MBPage Count: 18Explore furtherCisco 4G LTE Software Configuration Guide - GfK Etilizecontent.etilize.comSolved: 4G LTE Configuration - Cisco Communitycommunity.cisco.comCisco 4G LTE Software Configuration Guide - Ciscowww.cisco.comCisco 4G LTE-Advanced Configurationwww.cisco.com4G LTE Configuration - Cisco Communitycommunity.cisco.comRecommended to you b

Sep 11, 2017 · Note: Refer to the Getting Started with Cisco Commerce User Guide for detailed information on how to use common utilities for a record in Cisco Commerce. See Cisco Commerce Estimates and Configurations User Guide for more information.File Size: 664KBPage Count: 5Explore furtherSolved: Cisco Serial Number Lookups - Cisco Communitycommunity.cisco.comHow to view and/or update your CCO profilewww.cisco.comSolved: How do I associate a contract to my Cisco.com .community.cisco.comHow do I find my Cisco Contract Number? - Ciscowww.cisco.comPower calculator tool - Cisco Communitycommunity.cisco.comRecommended to you b

Cisco Nexus 1000V Cisco Nexus 1010 Cisco Nexus 4000 Cisco MDS 9100 Series Cisco Nexus 5000 Cisco Nexus 2000 Cisco Nexus 6000 Cisco MDS 9250i Multiservice Switch Cisco MDS 9700 Series Cisco Nexus 7000/7700 Cisco Nexus 3500 and 3000 CISCO NX-OS: From Hypervisor to Core CISCO DCNM: Single

Cisco 2951 2 2 Cisco 3925 4 4 Cisco 3945 4 4 Cisco 3925E 3 3 Cisco 3945E 3 3 Cisco 1841 1 1 Cisco 2801 2 1 Cisco 2811 2 1 Cisco 2821 2 1 Cisco 2851 2 1 Cisco 3825 4 2 Cisco 3845 4 4 Table 1A provides relevant software information Router Chassis Software Release Minimum Software Package Cisco 1921 15.0(1)M2 IP Base

Supported Devices - Cisco SiSi NetFlow supported Cisco devices Cisco Catalyst 3560 Cisco 800 Cisco 7200 Cisco Catalyst 3750 Cisco 1800 Cisco 7600 Cisco Catalyst 4500 Cisco 1900 Cisco 12000 Cisco Catalyst 6500 Cisco 2800 Cisco ASR se

Cisco Nexus 7706 Cisco ASR1001 . Cisco ISR 4431 Cisco Firepower 1010 Cisco Firepower 1140 Cisco Firepower 2110 Cisco Firepower 2130 Cisco FMC 1600 Cisco MDS 91485 Cisco Catalyst 3750X Cisco Catalyst 3850 Cisco Catalyst 4507 Cisco 5500 Wireless Controllers Cisco Aironet Access Points .

Cisco Certified Internetwork Expert logo, Cisco IOS, Cisco Press, Cisco Systems, Cisco Systems Capital, the Cisco Systems logo, Cisco Unified Computing System (Cisco UCS), Cisco UCS B-Series Blade Servers, Cisco UCS C-Series Rack Servers, Cisco UCS S-Series Storage Servers, Cisco UCS Manager, Cisco UCS