Applying Junos Operations Automation

Transcription

Junos Automation SeriesDAY ONE: APPLYING JUNOSOPERATIONS AUTOMATIONIt’s day one and you have a job todo. Start using Junos automationtoday. In this Day One bookletyou’re just a day away from usingthe Junos automation toolset foroperations in your network.By Curtis Call

Junos Automation Series#1Day One: Applying Junos Operations AutomationAs an organization continues to work with the Junos operating system, they will build a knowledgereservoir of best practices and lessons learned, a body of intelligence that can be available 24x7to help the network run optimally. This is the possibility that Junos automation provides. It allowsorganizations to automate their accumulated intelligence through scripts which automaticallycontrol Junos devices according to the desired best practices.Junos automation is a standard part of the Junos operating system available on Juniper Networksplatforms including routers, switches, and security devices. This booklet introduces Junosautomation and demonstrates how to take advantage of its potential. It also explains how to useOperation (op) scripts, one type of Junos automation script.“Junos automation technology provides a rich portfolio of toolsets thatare extremely powerful yet simple to adopt. This book demonstratesthat in very little time you too can create solutions for manychallenging network management tasks.”Lixun Qi, Lead IP Engineer, T-Systems North America Inc.Day One: Applying Junos Operations Automation shows you how to:· Explain where to use the different Junos script types.· Use reference scripts from this book and Juniper’s script library.· Interpret the XML data structures used by Junos devices.· Communicate with Junos through the Junos XML API.· Ease how you write XML data structures using the SLAX XML abbreviated format.· Read SLAX scripts and understand the operations they perform.· Create your own customized operation scripts.Juniper Networks Day One booklets provide just the information you need on day one. They arewritten by subject matter experts and engineers who specialize in getting networks up and running.Look for other titles covering high-performance networking solutions at www.juniper.net/dayone.This book is available in both PDF and printed formats.7100109

Junos Automation SeriesDay One: Applying JunosOperations AutomationBy Curtis CallChapter 1: Introducing Junos Automation. . . . . . . . . . . . . . 5Chapter 2: Writing Your First Script. . . . . . . . . . . . . . . . . 19Chapter 3: Understanding SLAX LanguageFundamentals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Chapter 4: Communicating with Junos . . . . . . . . . . . . . . . 53Supplemental Junos automation information is available in thePDF version of this booklet:Appendix. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

ii 2009 by Juniper Networks, Inc. All rightsreserved. Juniper Networks, the Juniper Networkslogo, Junos, NetScreen, and ScreenOS areregistered trademarks of Juniper Networks, Inc. inthe United States and other countries. Junose is atrademark of Juniper Networks, Inc. All othertrademarks, service marks, registered trademarks,or registered service marks are the property oftheir respective owners.Juniper Networks assumes no responsibility forany inaccuracies in this document. JuniperNetworks reserves the right to change, modify,transfer, or otherwise revise this publicationwithout notice. Products made or sold by JuniperNetworks or components thereof might be coveredby one or more of the following patents that areowned by or licensed to Juniper Networks: U.S.Patent Nos. 5,473,599, 5,905,725, 5,909,440,6,192,051, 6,333,650, 6,359,479, 6,406,312,6,429,706, 6,459,579, 6,493,347, 6,538,518,6,538,899, 6,552,918, 6,567,902, 6,578,186, and6,590,785.Day One Series Editor: Cathy GadeckiWriter: Curtis CallCopyeditor and Proofing: Nancy KoerbelLiterary Management: Ames & Eames, Inc.Printed in the USA by Vervante Corporation.Version History: v2 November 20093 4 5 6 7 8 9 10About the AuthorCurtis Call is a Systems Engineer at JuniperNetworks. He is JNCIE-M #43 and has eightyears experience working with Junos devices.Author’s AcknowledgmentsThe author would like to thank all those whohelped in the creation of this booklet. The literarymanager, Patrick Ames worked with me to find theright outlet for this material and Nancy Koerbelfine-tuned my writing. The Day One Series EditorCathy Gadecki was instrumental in bringing thisproject to fruition and helped me position thecontent to be more instructional. Roy Lee, theJunos automation Product Line Manager,reviewed the manuscript several times and alwaysfound ways to clarify the presentation.Thank you all.A free PDF version of this booklet is available at:www.juniper.net/dayone.

Welcome to Day OneDay One booklets help you to start quickly in a new topic with just theinformation that you need on day one. The Day One series covers theessentials with straightforward explanations, step-by-step instructions, and practical examples that are easy to follow, while alsoproviding lots of references for learning more.Why Day One Booklets?It’s a simple premise – you want to use your Juniper equipment asquickly and effectively as possible. You don’t have the time to readthrough a lot of different documents. You may not even know whereto start. All you want to know is what to do on the first day, day one.Day One booklets let you learn from Juniper experts, so you not onlyfind out how to run your device, but also where the shortcuts are, howto stay out of trouble, and what are best practices.What This Booklet Offers YouThis first booklet in our Junos Automation Series helps you to automate operations tasks in your devices. Read this booklet to learn howto use the Junos automation scripting toolset and how to write yourfirst operation scripts.When you’re done with this booklet, you’ll be able to:PUnderstand how the Junos automation tools work.PExplain where to use the different Junos script types.PUse reference scripts from this book and Juniper’s script library.PInterpret the XML data structures used by Junos devices.PCommunicate with Junos through the Junos XML API.PEase how you write XML data structures using the SLAX XMLabbreviated format.PRead SLAX scripts and understand the operations they perform.PCreate your own customized operation scripts.iii

ivWhat You Need to Know Before ReadingBefore reading this booklet, you should be familiar with the basicadministrative functions of the Junos operating system. This includesthe ability to work with operational commands and to read, understand, and change the Junos configuration. The Day One booklets ofthe Junos Fundamentals Series, as well as the training materials available on the Fast Track portal, can help to provide this background (seethe last page of this booklet for these and other references).Other things that you will find helpful as you explore the pages of thisbooklet:PHaving access to a Junos device while reading this booklet is veryuseful. A number of practice examples which reinforce the conceptsbeing taught are included. Most of these examples require creatingor modifying a script and then running it on a Junos device in orderto see and understand the effect.PThe best way to edit SLAX scripts is to use a text editor on yourlocal PC or laptop and then to transfer the edited file to the Junosdevice using a file transfer application. Doing this requires access toa basic ASCII text editor on your local computer as well as softwareto transfer the updated script using scp or ftp.PWhile a programming background is not a prerequisite for usingthis booklet, a basic understanding of programming concepts isbeneficial.Supplemental AppendixIf you’re reading the print edition of this booklet, there’s another 20 pages in the PDF supplemental appendix. Go to www.juniper.net/dayone and download the free PDF version of this booklet, Day One:Applying Junos Operations Automation. The supplemental appendix isincluded in that PDF edition.How to Give Us FeedbackWe’d like to hear your comments and critiques. Please send us yoursuggestions by email at dayone@juniper.net.

Chapter 1Introducing Junos AutomationWhat Junos Automation Can Do. . . . . . . . . . . . . . . . . . . . 7How Junos Automation Works . . . . . . . . . . . . . . . . . . . . . 9XML Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12SLAX Abbreviated XML Format. . . . . . . . . . . . . . . . . . . 17

6Day One: Applying Junos Operations AutomationComputer networks continue to improve - promising higher speeds,more capabilities, and increased reliability. Yet enhanced functionalitycarries with it an increase in complexity, as more technologies have tocoexist and work together. This tradeoff presents a challenge to networkoperators who want the advantages of new opportunities but still need tokeep their networks as simple as possible in order to minimize operatingcosts and prevent errors.Deploying Junos devices within a network can reduce the level ofcomplexity that would otherwise be present. This benefit comes from theability to use the same operating system to control routers, switches, andsecurity devices. Instead of having to train staff to support multipleoperating systems for each type of device, only a single operating systemhas to be learned and maintained. This decreases the overall complexityof the network.As an organization continues to work with Junos it will build a knowledge reservoir of best practices and lessons learned. Imagine if thisaccumulated experience could always be available to help the networkrun optimally. Imagine if every configuration change, every system event,and every troubleshooting step could take advantage of the organization’s gathered knowledge and make use of it. Enter Junos automation.It allows organizations to automate their pooled intelligence throughscripts that automatically control Junos devices according to the desiredbest practices.Junos automation is a standard part of the Junos operating systemavailable on all Junos devices, including routers, switches, and securitydevices. This booklet introduces Junos automation and demonstrateshow to take advantage of its potential. It also explains how to useoperation scripts, one type of Junos automation script.Junos automation enables an organization to embed its wealth ofknowledge and experience of operations directly into its Junos devices:n Business rules automation: compliance checks can be enforced.Change management can help to avert human error.n Provisioning automation: complex configurations can beabstracted and simplified. Errors can be automatically corrected.n Operations automation: customized commands and outputs canbe created to streamline tasks and ease troubleshooting.n Event automation: responses can be pre-defined for eventsallowing the device to monitor itself and react as desired.

Chapter 1: Introducing AutomationWhat Junos Automation Can DoJunos automation is a powerful suite of tools for automating themethods and procedures of operating a network. Automation can notonly save your team time, it also helps to establish high performanceoperation of the network and to manage greater scale in the networkby simplifying complex tasks.The tool sets let you automate a majority of the commands usedwithin the Junos command-line, further control the commit process,as well as automate the response to defined events. Junos includesthree types of automation scripts, each providing different types offunctionality for automation:n Operation (op) scripts instruct Junos of actions to take wheneverthe script is called through the command-line or by another script.n Event scripts instruct Junos of actions to take in response to anoccurrence in a monitored set of events.n Commit scripts instruct Junos of actions to take during thecommit process of activating configuration changes.MORE?To see examples of each type of script go to the online script library atwww.juniper.net/scriptlibrary.Operation (Op) ScriptsThis booklet helps you to write your first op scripts. Op scripts areused in operational mode to create custom commands and to changeconfigurations. They execute whenever called upon, either by anoperator who simply enters a command request in the CLI or fromwithin an event script (see below).Tailor made show commands are the most common form of op scripts.An op script written for this objective gathers data from multiple showcommands, processes it, and then outputs the desired information tothe screen.Another common form of op script is an automated configurationchange. These op scripts perform controlled configuration changesbased on supplied input from command line arguments, interactiveprompts, or Junos show commands. The advantage of this approach is7

8Day One: Applying Junos Operations Automationthat you can code the structure of the change into the script itself. Thismitigates human error and allows users with less expertise the ability tochange the configuration in controlled ways.You can also create op scripts to iteratively narrow the potential causeof network problems. These scripts run an operational mode command,process the output, determine the next appropriate action, and repeatthe process until the source of the problem is determined and reportedto the CLI. Op scripts can thereby give operators a running start that isimmensely valuable during troubleshooting.By uncovering the root cause, or at least helping operators to quicklyshorten the list of possible causes, op scripts can speed the time toresolution. Rapid problem diagnosis is crucial during an outage; it isnot uncommon for an operations team to spend hours diagnosing aproblem that ultimately takes only a few

Junos automation is a standard part of the Junos operating system available on Juniper Networks platforms including routers, switches, and security devices. This booklet introduces Junos automation and demonstrates how to take advantage of its potential. It also explains how to use Operation (op) scripts, one type of Junos automation script. “Junos automation technology provides a rich .