Copy Paste MasteringAutomation

download Copy Paste MasteringAutomation

of 78

Transcript of Copy Paste MasteringAutomation

  • 8/16/2019 Copy Paste MasteringAutomation

    1/78

     This Week: Mastering Junos Automation Programming

     July 2011

    By Jeremy Schulman and Curtis Call

     The secial edition o! This Week: Mastering Junos Automation Programming isro"ided !or easy coying and asting o! the Junos automation scrits contained inthe #ook$

     %ou&ll note that '(&s are used to #lank out much o! the coyrighted material) so use a

    search in your te(t editor to locate the aro(imate location o! scrit or con*gurationo! your choosing$

    +,T-: By using this secial edition) you agree to use the material in this document atyour o.n risk$ Junier +et.orks assumes no resonsi#ility .hatsoe"er !or anyinaccuracies in this document or in the con*gurations or scrits contained .ithin$

    / 2011 #y Junier +et.orks) nc$ All rights reser"ed$ Junier +et.orks) the Junier +et.orks logo) Junos) +etScreen) and Screen,S are registeredtrademarks o! Junier +et.orks) nc$ in the nited States and other countries$ Junose is a trademark o! Junier +et.orks) nc$ All other trademarks) ser"ice

    marks) registered trademarks) or registered ser"ice marks are the roerty o!their resecti"e o.ners$Junier +et.orks assumes no resonsi#ility !or anyinaccuracies in this document$ Junier +et.orks reser"es the right to change)modi!y) trans!er) or other.ise re"ise this u#lication .ithout notice$

  • 8/16/2019 Copy Paste MasteringAutomation

    2/78

    Chater 1

    etting Started .ith Junos Automation Scriting

    '(((( (((((((((( ((((((((() ((((( (( ((( ((((( (((((( (( Xxxxx xxxxxxxxx ) (( ( ((( (((((((((( ((( (((((((((((( (((((((((( (((( ((((((( ((( (( (((((((( (((( '(((( ((((((( ((( (((( ((( 3((( ((((((4((((((((((( (((((((((((($ '(( ((( (((((( '(((( ((((((( (( ((( '(((((( '((((((( (((((( (((( ((((((( '(((( ((((((((( (((((() (((( (( ((( (((((( (((((((((( '' '((5'(((( (((((( 3''67 107807 90(((((((4) ((( '5 ((( ' (((((( (( ((((((() ((( '' (((((( (( '((((((( (((((((() ((( ((( ''' '((((((('((((((( (((((( (( ((((((( ((((((($ '(((( ( ((( (( (((((((( (((($

     This chater .ill introduce key concets a#out Junos automation scriting) such as .hat it is and ho. it.orks) and it .ill then sho. you ho. to get started ; .hat you need and ho. to do it$ Then at the end) itsractice time$

     TP ! you ha"ent already) you should check the !ront matter o! this #ook and the authors list o!assumtions a#out you and .hat you already kno.$ A!ter this introductory chater) this #ook is o< on atear) and #y the end youll #e .riting some retty o.er!ul stui through the ages and get #ack to .ork$

    +,T- The end o! this chater gets you started .ith the e=uiment you need to !ollo. along) #ut !or no.)lets introduce Junos automation scriting at a 10)0005!oot le"el$

    ntroducing Junos Automation

    '(((( ((((((( ((( ((((((((((( (((((((() ((((((( (((( (( ((( (((( (( (( (((((((( (((( ((((((( (((((((( ') (( (((((((((((( (((( (((( '((($ '((( ((( ((((((((( (((((() ( (((((((( ((((((( (( ( ?'(((()'((((@ '(((( (((((( ((((((( (( '''':

    "ersion 1$0

    ns unos ?htt:77(ml$unier$net7unos7D7unos@ ns (nm ?htt:77(ml$unier$net7(nm71$17(nm@ ns cs ?htt:77(ml$unier$net7unos7commit5scrits71$0@ imort ?$$7imort7unos$(sl@

    match 7 E Fo5scrit5resultsG E FoututG ?Hello WorldI@

    '((( ((((((( (((( (((((( (( (((((((((( (((( ((((( ((((((( (($ '(( ((((( (((( (((( (((((( (((((((((( (((((((( ((((((() ((( (( (( (((((( 1$0 ((((( '(((( (((( (((((((( ''''7''((( 1$0 (( (((( (((($'(( ((((( (((((((( (((( ?((@ ((( ((((((((( ((((((((((((; ((( (((( ((((() ((( (((((( (((( ((( ?(( ((( (( ((( '((@ (( (((((((( (((((((($ '(( ?((((((@((((((((( (((((((( (((((((((( (((( (((((((( (( '(((((( '((((((() (((( (() ?((((((@ ((((((((($'((() ((( ((( ((((( (( ((( ?((((( 7@ ((((( (( ((( (((( (((((((( ((((( ((( ((( (((((() (((( ((((34 ((?'@$ '((( (( (( ((((((( (( (( ((((((((((( (((((( 3(( ((((((4) (( ((( ((((((( (( ((( (((((( (((( (((((((((( (((((( ( F((5((((((5(((((((G ((((((($ '(((((( ((( F((((((G ((( ((((( '(((( (( ((((((( ((((((( (( ((( ((((((($

    '(( ((((( (( (((((((( ?'(( ; (((( (( ((( ((((KK L ((( ((( (( ' (((( ((((( (( ((((( (( ((((((( ''''K@'((( (((( (( (((( ((((( ((( (((((((( '''' ((( '(((( (((((((((() (( (((( ((((((( ((( (( (((( ((((((((( ((((((((( (((((IChater1:ettingStarted.ithJunosAutomationScriting

    '(((( ((( ((((( (((( ((((( (( '(((( (((((((((( ((((((( ((( (((( ((((( (((((:

  • 8/16/2019 Copy Paste MasteringAutomation

    3/78

    0. oerations automation 3op scripts4

    1. con*guration automation 3commit scripts4

    2. e"ent #ased automation 3event scripts4

    '(((( (((((((((( ((((((( ((( (((((((( (( (( xx-xxx xxxxxxxxxx  ((((((( ((( ((((((( ((( ((((((((((

    ((((((( (( ((( ((((((( ((( ((( (((((( ((( ((((((((( (( ((( '(((( ((((((((( (((((($'( (((((((( (( ((((( ((((((( (( (((((( (( '(((( 1$1$

     Ta#leN1$1N ,n5Bo(NAutomation

    '(((( (( ((((((( (((( (( '(((( (((((((((() (((((((( (((((((( (( (( xxxxxxx xxxxxxxxxxxxx  (( xxx- xxx  (((((((((() (((( (( ( (((((( (((((((((( (((((() (((( (() ((( ((((((() (((( (((((((((( ((((((3'''7'''4$ '((( (((( (( (((((((((( (((( ((( (((((((((5((((( (((((((( ''''''' 3((((((((((( '''(((( '''4 (( (((((((( ((((((( (( ((( '(((( ((((((( ((( ((((((( ((((((((((( ((( ((((((((((((((((((((($

     The net.ork orchestration toic is not co"ered in this #ook) #ut it is .orth mentioning that Junos is caa#leo! o

  • 8/16/2019 Copy Paste MasteringAutomation

    4/78

    '(((( (((((((( (((( (((( ((((((((( ((((((((( (( '((() '((((() (( (((( '((() ((( ((((((( ((((((((((((( '(((( (((((((((( (((((( (((((((((($

     %ou dont need to #e a rogramming ?guru@ to .rite Junos automation scrits) #ut it is hel!ul i! you are!amiliar .ith the !undamentals o! scriting languages like Perl$ The !ocus o! this #ook is to cature theersecti"e o! a classical scrit rogrammer and relate kno.n techni=ues to those used !or Junos scriting$

     Thats #ecause the Junos scriting rogramming model is a little di

  • 8/16/2019 Copy Paste MasteringAutomation

    5/78

    WhySOA'K

    '(( ((( ((( (((( ((((( ((((((( (( (((((( '''' (((((( (((( ((((( ( ((( ((((((K '''' (( ( (((((((((((( ((( (((((((( ''') ((( ((( (((((( (( (((((((((() ((((((() ((( ?(((((((((@ ((( (((((((5((5((((((( ((((((((((((($ '''' ((( (( (((((((((((( ((( (((((( (( ((((( (((((((((( ((((((( (((((((($'( ((((( ((((( ((((((((((( ((((((( (( '''' (( ((((( (( (((((((((( (( ((((((( (((( (((((( (((( ((((( '(($ '(( (((((((((( (((((((( (( ((((((( (((((((( (( (((((( '''' ((( ((((( (((((((((( (( (((

    ((((((((((( (((((( (( ((((((( (((( ((( (((((($ '((((( ((() ((((((( (((((((( (( '''' (( ((((((( ((((((((5((((() (( ((( '(((( ((((((((((( (((( ((((((((( (( (((  Xxxxxxxxxx Xxxxxxxx Xxxxxxxxxxx xxxxxX ) (( ''''$

    '''' ((( ( (((((( (((((( (((( ((((((( ((( ((((( (( ') (( '((($ '(((((((((( (((((((((( ((( ''(((((((((((((( ((( ((((( (((( ((((((((((( ((( ((((((( ''' (((((((( ((( (((((((((( (( ?(((((((((@(((((((( (((((((((($ '(( (((((((((( (((((( (( ((((((( ''' ((((((((((( ((( ((((((( (((( (((((((5((((((( (((((( (( (((((((( (( (((((( ((( (( ((((((((((() ((((( (((((() ((( (((((( ((((((((( ((((( 5((( (((((((( (((((((((( ((( ((((((((((($

    '((( '''') ((( (((((((((( (((((((((( ((( (((((((((( (((((( (( ''''$ '(((((( (( ((((( (( ((( ''''(((((($ '(( ((((( ((((( (( '''' (( ( (((5((((((((( ((( '''') ((((((( '''' (((((((((( ((((((7((((7(((( (((( ((( (((((((((( '''' (((((((((( (((( F(((:((((((G ((( F(((:((G (((((( ((( (((( ''''(((((((((((((( (((((( (((( ((((((($

    ' ((( (((((((((( (( '''' (((((((:

    ' '(( ((( ((7((((7(((( ((((((( (( F(((:((((((G ((( F(((:((G (((((((($

    N %ou ut test e(ressions in arentheses$' '(( (((  (( (((( (((((((( 3(( ((((( (((((((( ((((((((( ((((((4$

    ' '(( ((( : ((( '((((( '((( '((((((( 3'''4 (( ((((5((( (((((((((($

    ' '(((( (((((( ((( (((( (( (((( ((((((((((( ((((((( (( ((((((( (((($

    ' '(( ((( ((((((( (((((( ((((((((((((( ((((( (((  X  (((((((( 3(((((( (((( ((((Y4$

    ' '(( ((((( (((( ((((((( ((((( (((((( (((((( ((((((( (( ((( F(((:((((G ((((((($

    ' '((((((( ((((( ((((((((( (((( ( (((((( (((((((((( ( (((((((( (((($

    ' '((((((( ((((( ((((((((( (((( ( (((((( (((((((((( ( (((((((( (((((((((($' '((((((((( ((((((((( (((((((((((($

    ' '((((((( ((( ((((((( (( ((((((() (( (((((((( ((( ((((((((( ((((( (( (( (((( ((((((( (( ((((((((($

    N Writing more human5reada#le scrits$M,-K The comlete SOA' language re!erence is a"aila#le online at: htt:77code$google$com77li#sla(7do.nloads7detailKnamesla(5manual$html$

     The Junos Scrit Programming Model

    '((( (((( ((( ((((((((( (( ((( ((((((((((( ((((((((((( ((((( ((( (((( (( ((( ((((( ((((( (( '(((((((((((: (() (((((() ((( ((((($

    ts imortant !or you to understand ho. Junos e(ecutes these scrits in the conte(t o! the oeratingsystem) #ut not "ia a detailed o"er"ie.$ Oater sections in this #ook ro"ide use!ul tutorials) e(amles) andste5#y5ste techni=ues to take ad"antage o! each o! these scrit tyes) and in some cases) com#iningt.o scrits to create "ery o.er!ul automation solutions$

    M,-K See all the other #ooks in the Junos Automation Series at ...$unier$net7dayone) !or in5dethco"erage o! all the scrit tyes$

     Junos,Scrits

    '(((( ((((((((((( ((((((() (( xx xxxxxxx ) ((( ((((((((( ((( ((((( (((( (( (((((( ( ((( (((((((((((((((( (((((((((($ '((( ?'(((() '((((@ ((((((( (( ((( ((((( (( ((( ((((((( (( (( (( (((((($ '(((((((( ((( ((((((((( ((((((( (( ( (((( (( ((( '(((( '''$ '((( ((( ((((((( (( ((((((( ( (((((( ((((((((( ((( ((( ((((((( (((((((((( (((((((( (( ((( (((( (( ((( (((((( ((( (((( ((( ((((($ '( (((((((( ((( (((((((( ((( (((( ((((((((((( (((((((( ((( (((( ((((( ((((( (((((((($ '( (( (((((( ((((((( (( (((( (( (((((((( ((((((((((((( ((((((($

    '( (( ((((((((( (( (((((((((( (((( (( ((((((( ((( (((((((( (( ((( ((((((( (( ((( (((( (((((((( (((

  • 8/16/2019 Copy Paste MasteringAutomation

    6/78

    (((((($ '( (((( ((((( (((( ((( (( (((((( ((( (((( ((((((( ((( ((((((((( (((( ((( (((( ((((((((((((( ((((((($

    '(( '(((( ((5(((((( ((((((((((( ((((( (( ((((((((((( (( '((((( 1$2$ ThisWeek:Mastering JunosAutomationProgramming

    F((((((((G E F((((G $$$ F(((((G $ $ $

    igureN1$2N NTheN,5ScritNProgrammingNModel

    '((( ((( (((( ((((((((( ((((((( (( ((( ((((((( (( '((((( 1$2:

    0. Concetually) the source tree is emty) meaning that user5inut is not ro"ided as an 'MOdocument$ ! the o scrit has user5de*ned arameters) they are assed "ia aram arguments de*ned inthe scrit this techni=ue is similar to the use o! ZAR in Perl) and .ill #e more !ully co"ered later in this#ook$

    1. The o scrit is the stylesheet tree$

    2. The result tree is generally a series o! outut statements de*ned .ithin an Fo5scrit5resultsG 'MO #lock 3such as the ?Hello World@ o scrit resented at the start o! this chater4$

     The Junos oerating system ro"ides a comrehensi"e set 'MO5#ased AP remote rocedure called 3PCs4$ The o scrit can in"oke Junos commands #y !ormulating the 'MO PC e=ui"alent o! the CO command andcommunicating it directly to the management daemon$ The op script does not issue native CLI commands.or e(amle) a user at the CO romt .ould enter the command sho. chassis hard.are to dislay thehard.are in"entory$ A Junos o scrit .ould use the e=ui"alent 'MO PC : Fget5chassis5in"entoryG$

    +,T-N %ou can easily determine the 'MO PC !rom the Junos CO #y using the ?dislay (ml rc@ ie5otiona!ter the command$ or e(amle) sho. chassis hard.are [ dislay (ml rc .ould sho. you the 'MO PCs Fget5chassis5in"entoryG.

    M,-K or more introductory in!ormation on Junos o scrit rogramming re!er to the Junier +et.orks#ooklet: This Wee! Applyin" Junos Automation) a"aila#le at ...$unier$net7dayone$

     JunosCommitScrits

    '(((( (((((( ((((((( ((( (((((((( (((( ((( ((((((( (( '(((( ((( (((( ( (((((( 3((Chater1:ettingStarted.ithJunosAutomationScriting 1\

    (((((( (((((4 ((((((((( (((((() (( ((((((((((( (( '((((( 1$\$ ' (((((( (((((( ((( (( (((( (( ((((((((( ((((((((( ((((((((((((() (( (((((( (((((((() (( (( ((((((( ((( ((((((((((((( (((( (((((((((((((($ '(( (((((( (((((( ((( (((( ((((((( ((((((((((( (((((((( (( (((((((( '(((( ((((((((((()

    ((( ((((((() F(((5(((((((5(((((((((G$'((( (( ( ((((( (((( (( (((( (((((( (((((((((( ((((( ((((() ((( (( ((( (( ((((( ((((() ((( '(((((((((( (((((( (( (((((((( (( ((( (((( (((( (((((((:

    0. At de"ice #oot5u time .hen the con*guration is initially loaded$

    1. When a user at the CO enters the commit or commit check command$

    2. When an o scrit er!orms a con*guration change$

    3. When an e"ent scrit er!orms a con*guration change$

    4. on automatic con*guration roll#ack triggered #y a commit con*rmed$

    5. When an ,SS7BSS system is er!orming a con*guration change this is an e(amle o!

    net.ork orchestration or o

  • 8/16/2019 Copy Paste MasteringAutomation

    7/78

    0. The candidate con*guration *le is the source tree inut$

    1. The commit scrit is the stylesheet tree$

    2. The result tree is a series o! seci*c 'MO #locks that can make changes to the candidatecon*guration) generate .arnings) or e"en re"ent the con*guration !rom #ecoming acti"e$

    Any Junos de"ice can #e con*gured to run multile commit scrits$ -ach scrit) ho.e"er) recei"es thesame coy o! the candidate con*guration$ Although the Junos oerating system e(ecutes the commitscrits in the order seci*ed in the con*guration *le 3in a serial !ashion4) the changes made #y rior scritsin the list do not ass to later scrits in the list$

    M,-KN or more introductory in!ormation on Junos commit scrit rogramming re!er to the Junier+et.orks #ooklet: This Wee! Applyin" Junos Automation) a"aila#le at ...$unier$net7dayone$

    18 ThisWeek:Mastering JunosAutomationProgramming

     Junos-"entScrits

    '(((( ((((( ((((((( ((((( ((( (( (((((((( '(((( (((( (((((((( (((((( ((((($ '((((((( (( ((((((((((( (((( (( ((((((((( (((( (((( (( (((( (( (( '((((((( (( 6:00(($ '(( (((( (( (((((() (((((((()((( ((((((((( (( ((((((() ((( (( (((((((( (((( (((( (((((((( (((((((((( (((((((() (((((((((( ((((((( (((((( (( (((( ((((( ((((((( ((( ((((((( ((((((((((( (((((((() (((( ((((((( (( (((((((((((((((() (( ((( ((((((((((( 3($($ (( ((((((4$

    By de!ault e"ent scrits are e(ecuted in the root user conte(t) #ut they can #e con*gured to run in asseci*c user content as .ell$ The e"ent scrit rogramming model is illustrated in igure 1$8$

    igureN1$8N NTheN-"entNScritNProgrammingNModel

    '((( ((( (((( ((((((((( ((((((( (( ((( ((((((( (( '((((( 1$8:

    0. The source tree is an 'MO  #lock that contains in!ormation a#out the

    e"ent) including the Ftrigger5e"entG child #lock that ro"ides the details on the e"ent that triggered thee"ent olicy$

    1. The e"ent scrit is the stylesheet  tree$

    2. The result tree is contained .ithin the  'MO #lock$

    M,-KN or more introductory in!ormation on Junos commit scrit rogramming re!er to the Junier+et.orks #ooklet: This Wee! Applyin" Junos Automation) a"aila#le at ...$unier$net7dayone$

     JunosScritlo#alRaria#les

    '(((( ((((((( (((( (((((( (( ( (((((( (( (((((( ((((((((() ((((((: Z(((((((() Z((((((() Z(((((() Z(((()Z((((((((() ((( Z(((((((((5((($

    '(((( 11$1 (((( ( ((( (((((( ((((((((: Z(((((5((((((($ '((( (((((((( (( ( ((((5((( (((( (((((((((((((((( ((((((((((( (((( ((((((( ((((( (( (((((((((( (($ '(((( (((( (( ((( ((((( ''') ((((((( ((((( ((( (((((( (( ((((((( (( ((( (((((( '') (( ((( (((( (((( ((( (((((( (((((( (( ((((((( (( (((( ((((( ((((5(( (((((() ((( (((((( (((( (((( (((( ((((((((( (( ((( (((( ((( ((( ((( ((((( (((((((((((((((( (((( (((((( (((((((($

     The use o! a single "aria#le to store all the desired in!ormation) rather than multilearameters) is a dearture !rom the ast #ut o

  • 8/16/2019 Copy Paste MasteringAutomation

    8/78

    as Windo.s) Mac) or Oinu($

    1. Ste 2: Coying the Junos scrit code to a Junos de"ice) and into the correct directory$

    2. Ste \: Testing the Junos scrit code) and trou#leshooting either 3a4 synta( errors or 3#4logic errors$ ! the test !ails) go #ack to Ste 1$

    +,T-N There is also a one5time ste o! ena#ling the scrits so that Junos kno.s that these scrits are "alidand .ill run in the roer conte(t 3o scrit) commit scrit) or e"ent scrit4$

    '(( ((( (((( (((( ((( '(((( (((((( ((((5(((((( ((( (( ((((((( (( (((( (((( ((((((((K '((( (( (((((( ((((( (((( ((( ((( (((((((((( ((((((( (( ((((((((( ((( ?(((( ((((( (( ((((((@ (((($ '(((('(((( ((( ((( ''' (((((() (((((((( ((( (((((( (( (((((( ((((((( (( ((( (((( (((((((( (( '(((5((((($'( (((( (((( (((((((( (( '((((((5((((() (((( ( (((((( (( (((((((((((( ((( (( (((( (( ((((((( ((((((( (((((( (((( (((((( (((((($ '(( '(((((( ((( ((((( ((( '((''') ((((( (( (((() ((( '(((('(((()((((( (( ((($ '(( '((( ((( ((((( ((( ( ((((((( (((((( '(((('((($

    '(((((( ((( (( (( (((( ((((( ((((( (( ((( '(((( (((((( (( (((((((( (((( ((( '(((( '' ((((( (((((((((( ((( (((((( ((((( (((((((( (((( ((( '' '((( '((((( (( '(((( (((((($

     These are on5de"ice de"eloment techni=ues that can cut do.n on the *le and coy stes) #ut care must#e taken that the *nal scrits are sa"ed o< the de"ice so as to not lose imortant changes$

    Ste1:WritingScrits

    '(( ((( ((( ((( (((( (((((( ((( (((( (( ((((( '(((( ((((((($

     There are also a num#er o! commercial te(t editors that can #e customiQed to suort SOA' synta()meaning that key.ords can #e highlighted) and the structure o! the code can #e roerly indented$ The

     Junos Automation user community has de"eloed highlight modes to suort SOA' !or -dit and -clise $ These are not !ormally suorted #y Junier +et.orks) #ut any =uestion and suggestion regarding thesetools can #e directed to the J5+et Junos Automation #oard$M,-KN The -dit rogram can #e do.nloaded !rom: htt:77...$edit$org7 and the SOA' highlight modecan #e do.nloaded !rom the J5+et Automation !orum at htt:77 !orums$unier$net7t67Junos5Automation5Scriting7What5tools5do5you5use5to5de"elo5Junos5automation5scrits7td5762\62$

    M,-KN The -clise - can #e do.nloaded !rom the site: htt:77...$eclise$org7$ t is imortant to note)ho.e"er) that the SOA' lug5in !or -clise is still under de"eloment) and should hoe!ully #e comleted#y the time you are reading this #ook$

    Ste2:StoringScritsontheJunose"ice

    '( ((((( ((( '(((( ((((((( (( (( ((((((((( ((((((((() (((( (((( (( (((((( (( ((( ((((((( (((((((((((((( ((( '(((( (((( ((((((: #xxx#xxx#xxxxxxx $

    '(( 7(((7(((7((((((( ((((((((( (((((( (((((( ((((( (( ((( ((((((( (((((( ((((((((( ((((((( (((( ((((((((( (( ((((( (( (((($ ' ((((((( (( (((( ((((((((( (((((:

    user]unosG *le list 7"ar7run7scrits

    7"ar7run7scrits7: commit7 e"ent7 imort] 5G 7usr7li#data7cscrit7imort li#7 o 7

     The to5le"el scrits directory has su#5directories !or each o! the scrit tyes: o scrits are stored in the7"ar7run7scrits7o) commit scrits are stored in the 7"ar7 run7scrits7commit directory) and e"ent scrits are storedin the 7"ar7run7scrits7 e"ent$

    AO-TI The 7"ar7run7scrits7imort directory is used e(clusi"ely #y Junos) so dont try to ut anything there$

    +,T- Junos 11$1 added a ne. directory: 7"ar7run7scrits7li#$ This directory can #e used to store any *les you.ould like to share #et.een scrits$ %ou can think o! this as an include directory$

    Ste\:-na#lingScrits

    '( ((((( ((( '(((( '''' ((((((( (( (( (((((() (((( (((( (( (((((((( ((((((( (( ((( '((((

    ((((((((((((( (((($'(( (( (((((((:

    ^edit system scrits o_ set *le my5o5scrit$sla(

  • 8/16/2019 Copy Paste MasteringAutomation

    9/78

    '(( (((((( (((((((:

    ^edit system scrits commit_ set *le my5commit5scrit$sla(

    '(( ((((( (((((((:

    ^edit e"ent5otions e"ent5scrit_ set *le my5e"ent5scrit$sla(

    e#uggingScrits

    '(((((( (((( (((((( ((( ((((((((( ((((((( ((((((((( ((( '(((( '((((((((( ((((((((($ 3'((((((((((((( (( (((( ((((( ((( ((((((((( (( (((((((((( (((((((($4

     Tyically) de$u""in" !alls into t.o #road categories: 314 correcting synta( errors and324 (((((((((( ((((( (((((($

    '((((( ((( ((( ((( (( '''' 3(( ''''4 ((((((((( ((((( (((((( (((((( ((((( (( (( ((( (((((5((((((((((($ '(( ((((((((((( ((((( (( ((((((( ( (((((() ((((((( (( (( ( (((((() ((( (((( ((((((( ((((((( (((( ( (((((( ((((( ((( (( ((((( (((( ((((((((($ '(((((( ((( ((((((((( (( (((5(((( (((( (((((( xxxxxxxx  (((( ((( ((( ((( (( ((((( ((((( ((((( (( (((((( (((((() (( (((( (((((( ((( (((( ( ((((((5(((((5(((( (((((( (((((( ((((((( (( (((( (( ((( '(((( (((((($ '(((((( (( (((((((( ((( ((((((((( ((((( '((((((($

    '(((((((( ((((( (((((( ((( (( ( ((( (((( ((((((((((() ((( ((( (((( ((( ((((((((( ((((((((((((((((:

    0. sing ?rint@ statements in your code$

    1. sing traceotions *le and >ags to track rogram e(ecution$

    2. sing ?trace@ statements in your code to log custom messages to a traceotions *le$

    3. sing ?rogress@ statements in your code that are only in"oked .hen you use the detail otion this is only used !or o5scrits$

    n Junos 10$8) an on-tar"et de#ugger .as added that can #e e(ecuted !or o scrits) using a hiddenarameter: in"oke5de#ugger cli) .hich is discussed in detail in the Aendi($

    Hello) World Ste5#y5Ste

    '((() (((( ((((((( ((( (((((((( (((( '(((( '((((((((( (() ((( (( ((((() ((( (((( ((( (((( (( (((((((((($ '(( (((( (((( ((( (( ((((((( (( ((((( ((((5((5(((( (((((((((((( ((( ((((((( ((( ((( '(((()'(((( (( (((((( (((( ((( (( ((( ((((( (( (((( ((((((($ '(( (((((( ((( ((((((( (((((((((( ((( (((((((((($

    '(( ((((( (((( (( (( (((((( ((( (((() ((((( (((((5((((($((((:

    "ersion 1$0

    ns unos ?htt:77(ml$unier$net7unos7D7unos@ ns (nm ?htt:77(ml$unier$net7(nm71$17(nm@ ns cs ?htt:77(ml$unier$net7unos7commit5scrits71$0@ imort `$$7imort7unos$(sl

    match 7 E Fo5scrit5resultsG E FoututG `Hello WorldI

    '((( ((((((() (((( (((((( (((( (((((( ((( (((((( ?'(((() '((((@ (( ((( ''' ((((((($

    '(( (((( (((( (( (( (((( (((( (((( (( ((( (((((( '(((( (((((( (( ((( (((((( ((((((((( 7(((7(((7(((((((7(($ '((( (((( (( (((((((( ((((((((( (((((( ((((( (( ''' (((((( (( ((( ((( ((((((($ '((((((((((( (( (( ((((((( ((((( (((:user]mylatoZ sc hello5.orld$sla( user]unos:7"ar7run7scrit7o

     The ne(t ste is to ena#le this scrit on the Junos de"ice:

    user]unosG con*gure

    ^edit_ set system scrits o *le hello5.orld$sla(

    ^edit_ commit and5=uit

    inally the o scrit can #e e(ecuted at the Junos CO:

    user]unosG o hello5.orld Hello) WorldI

    RoilaI Hello World$Summary

    '(( (((( (( (((( (((( (((((( (((( ((( ((((( (((((((((((( (( (((( ((((((($ '((( ((( (((((( (((( ((

  • 8/16/2019 Copy Paste MasteringAutomation

    10/78

    (((( ((((((( ((( ((( (((( ((( ((((( (((((((((((( (( ''''$ '(((( (((() ((( (((( (((((( ( ((((((( (((((((( ((((((((( ''((() ''' ((((((((((() ((( (((( ((( ((((((( ((((((($

    '(((( ((( ((((( ((((( (( ((( '((((((( (((( ((( ((( ((((( (( (( ((( ((((: ((( ((((((((() ((( ((((((((((((((() ((( ((( (( (((((( (((((((($

    '(( (( ((( (((((((( (( (((( (((( (( (((((( (( ((((((( ( ((((( ((((((( (((((((( ((((((((((5 (((((((((((((( (((( ((( ((( (((( 3(((( (( '(((4 ((( ''''$ '(((( ((((( (( ((( '(( '(( '(((( '(((((((((

    '((((( ((( ((((((((( (( ((($((((((($(((7(((((($

    Chater 2

    SOA' undamentals

    %undamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .&'

    SLAX Script %ile Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .&(

    )aria$les . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .&*

    ControlStatements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*+

    Codeodularity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    sin" Junos /emote 0rocedure Calls 1/0C2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Console

    Input # 4utput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5( Stora"e Input 

     # 4utput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 Summary . . . . . . . .

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .56

     To #e ro*cient in SOA' rogramming you must #e a.are o! a !e. !undamental rogramming concets$ These concets come !rom the 'SOT rogramming en"ironment) so i! you are !amiliar .ith 'SOT) then these.ill not #e ne. to you$ Where"er you see SOA' in the !ollo.ing te(t) the same alies to 'SOT) so you.ont need to see ?SOA' 7 'SOT@ throughout this document$ ! Perl or Ja"a is your rogramming#ackground) then some o! these concets might #e un!amiliar and erhas challenging at *rst$ The goal o! this chater is to ro"ide a guide to hel you na"igate #et.een !amiliar rocedural #ased languages 3suchas Perl4 and SOA'$

    M,-K 'Path e(ressions !orm the !oundation !or SOA' rogramming$ ! you are not !amiliar .ith 'Pathe(ressions you are strongly encouraged to read 7ay 4ne! 8avi"atin" the Junos XL 9ierarchy  #ook !oundat ...$unier$net7dayone) or any other online materials that can #e !ound in the e!erence Section ateither the #eginning or end o! this #ook$

    undamentals

    '(((( ((( ( ((( ((((((((((( '''' ((((( ((( ((((((((: XXXX xx xxxxx xx XXxxx (.' xxx XXXX (.'. Xxx xxx xxxx x xxx xx xxxxxxxxx xxxxxxxx xxx XXxxx &.' xxx XXXX &.', xxx xxxxxxxxxxxxx xxx xxxxxx xxx xx.

     Xxxxxxxxx xxx xxxxxxxxx $ '((( ((((( (((( ((( ((( ((( ( (((((((( (((( (((( ((( (((((( (((((( ((

  • 8/16/2019 Copy Paste MasteringAutomation

    11/78

    ((((($

     Xxx :Xxxx-Xxx; xxxxxxxx xxxx-xxxx xx xxxx XXxxx $ ' ((((5((( (( ( ((( (( ''' ((((( (((( ((( ((((((((((( (( ''((( ((((((((((($ '((((( (((( '(((( ''' '''( ((( ''' ((((() (( ((((( (((((( ((((((((( ((((5(((($ '(( '(((( ((((((((((((( (((( (( (((( (( ''' (((((((() (( (( (( (((( (((( (( (((((((((((( ((( ((((5((( ((((5(((($ '(( ((((((((( (((( ((((((( ((((((((((( ((( (((((((((( (( ( ((((5(((((((((((:

    "ar Zmy5ns5"ar : E Finter!aceG E FnameG bge507070b Finter!aceGFnameG bge507071b

     Xxx :Xxxxxx Xxxx Xxxxxxxx; 1XXX2 xxxxxxxx xxxx-xxxx xx xxxx XXXX $ '( ''' ((( (((((( ((((( ( (((((((((((( (( ((((( (( ''' (((( 3((( ( ((((5(((4$ ' '''' (((((( ((( (((( ((((((( ((( ((((((((( ((((((((( (( ''': (((( (( (( ((( '''' (((((( (((() ((((((( (( (( ( (((((() (( ((((((( (( (( ( ((((5((( (( (((((( (((( ((((((( (( ((( (((((((( (( ((( ''' ((((($ '(( ((((((((( (((( ((((((( ((((((((((( ((((((((((((( (( ( ''' ((((((((:

    "ar Zmy5rt!5"ar E Finter!aceG E FnameG bge507070b Finter!aceGFnameG bge507071b

    AO-TIN %ou should ay close attention to the node5set and T code e(amles$ They are almost identicalexcept  that the "aria#le assignment !or the node5set "aria#le Zmy5ns5"ar is made using the colon5e=uals 3:4oerator and the T "aria#le Zmy5rt!5"ar is made using e=uals 34 oerator$ This "ery small di

  • 8/16/2019 Copy Paste MasteringAutomation

    12/78

    FnameG &inter!ace&FdescritionG &The inter!ace you .ant to control& FargumentG E

    FnameG &mtu5siQe&FdescritionG &The MT siQe 3de!ault is 20004&

    '(( ((((( ((((((( ((( ((((( ((((( ((( ((((( (((((((((( (((( ((( (((((( (((((( (((( ((((((( (( ((((((( '(((( ((((((((((((( (((($ '((( (((((((((( ((( ((((( (( '(((( $0) ((( (( ((( ((((((((((((((((((($ '(( ((((((( (((((( (((((((( Z(((((5(((((((((((( (((((((((( (( '(((( ((( (((( ((((((($

    '((( ((( Z((((((((( ((( Z(((((5(((((((((( ((((((( ((((((((( ((( ((((((((( ((((( (( (((( ((((((($'((( (( ((( (((( ((((((((( (( ((( xxxx xxxxxxxx ) ((((( ((( (((((( (((( (((((((((((( (((((($ '(((((( (((((( ((((((((((( (((((((( (( (( ((( ((( (((( (((((((( (( ((( ((( (( ((( (((($ '(( (((((((((((( (( ((( (((((((( (((( ((((((( ((( ((((( ((((((( (( ((((( ''' (((((((() (( ((((( (( ((((( (((( ((((( ''' (((((((( 3((((((5((((4$ '(( (((((((( (((( ((((((( (((((((( 3((((((((( (( (((((((((((5((((4 (( ((((( 7$

    '((( '(((( (((((( (((( ((( ( ((((((((( (((( (((((((($

    '(( (((( (((((((( ((( (( (( (((((( ((:

    match 7 E Fo5scrit5resultsG E 7D your code goes here D7 As you can see) the main temlate is using the matchanything notation 3 7 4) and the code e(ecution #egins here$'(( (((( (((((((( ((( (( ((((( (((((( ((:

    match 7 E Fe"ent5scrit5resultsG E 7D your code goes here D7 And the main temlate !or a commit scrit is:

    match con*guration E 7D your code goes here D7

    Here you can see that the main temlate is more seci*cally scoed$ t matches the 'MO node calledcon*guration) .hich is art o! the candidate con*guration resented to the commit scrit at runtime$

    M,-K The to5le"el match !or a commit scrit is di

  • 8/16/2019 Copy Paste MasteringAutomation

    13/78

    '(((((((( ((( (( (((((( (( ((( (( ((((( ((((((: (((((( 314) ((((((((7(((((((( 324) ((( (((((( (((((((((((( (((((((5((((( 3\4$ '((( (((((( ((((((((( ((( (( (((((((((( (( ((((( ((((((((((((((((($ '((( (((((((( (( (( ((((( ((((( ((( (((( (((((((( (((( (( (((((((( (((((( (((((($

    '((((( ((((((((( ((( (((((((((( ((( (((((((( ((((((( (( ((( ((((((((($ '((((( ((((((((( ((((((((((((( ((( ((((((((( (((((((( (( ((( ((( (( ((( (((((( (((() ((( (((( (( ((( ( ((((((((((($

    '(((((((( ((( ((((((((( ((( (((( (( (((((((((( (((( (((( 3((( (((((((( ((((((((((( ((((((( (((((

    ((( (((( (( ((((((((( ((((( (( (((( (((((((4$ '(((( (((((( ((((((((( ((( (((((((( (((((( ((( (((((((((((((( (( ((( (((((((( (( (((((((($ '(( ((((((((( ((((((( ((((((((((( (((((((( (((((((((3Z(((1) Z(((4 ((( ( (((((((( ((((((((( 3Z(((14:

    temlate !oo3 Zarg1 4 E "ar Z"ar1 Zarg1 V 10 "ar Zstr bthe "alue is: b X Z"ar1 7D the bunderscoreb is the string5concat oerator D7

    Assuming that the temlate !oo .as called .ith an argument o! 1) the resulting "alue in Zstr .ould #e the"alue is: 11$

    +,T- SOA' simli*es the synta( o! temlate de*nitions$ The temlate arameter Zarg1 .as declared .ithinthe de*nition o! the temlate and does not re=uire the key.ordaram$

    '((((((( ((((((((( ((( ((((((((( (((((((( (( ((( ((( (( ((( (((((((( (((((((((() ((( (((( (( ((((((((((($ '(((((((( (((( (( (((((((() ((((((() (((((( (((( ((( (( (((($ '(( ((((((() ((( ((((((((((((((((( ( '''' (((((( (((((:

    temlate !oo3 Zarg1 4 E "ar Zstr bthe "alue is: b X Z"ar1 7D S%TA' -, II D7 "ar Z"ar1 Zarg1 V 10

    '(((((() ((( ((( ((((((((((( (((( ((((((((( (((((((((( ((( (((((((( ((((((((((:

    temlate !oo3 Zarg1 4 E "ar Z"1 Zarg1 V 10 FoututG b"1 is: b X Z"1

    ((( Z(2 Z(1 D 1000 F((((((G b(2 ((: b X Z(2 '''' (((((((( ((( ((((((((((( ((((((( ((((((: (((5(((( (((((( ((7((((7(((($ '(((((((( ((( (( (((((((( (((((( ((( (((( (((((((( (( ((((( ((((((( (((((($ '((((((((((( ((((((((((( ( (((((( (((((((( 3Z((((((4 ((((( (((( (( ( (((((((( 3((((5(((((((((5((((4 (((( ((((((( ( (((5(((( ((((($ '(( Z((( (((((((( (( ((((((( (((((( (((((( ((( (((5(((( (((((:

    "ar Zi>ist : E Finter!aceG E FnameG bge507070b

    Finter!aceG FnameG bge507071b

    temlate sho.5inter!ace5list34 E!or5each3 Zi>ist7inter!ace 4 E "ar Zi!d $ 7D the bdotb is the conte(t node D7 FoututG Zi!d7name

    '(( ((( (( ( ((((((( (((((( (((((((( (( ( (((((( ((((((((( (( (((((((( (((( (( ((( ((((((((((((((((((( (( ((((((((( ((((((((($ '( ((((( (((((((((( ((((((((() ((( Z((( (((((((( ((((( (((((((((( ((((((( ((( (((5(((( (((() ((( (( ((((( (( (((((((( (( (((( ((((((((((($ '(( ((((((() (((((( ((((((((( (((((((( (( ''' ((((() ((( ((((( (( ( (((((( (((((:

    temlate sho.5inter!ace5list34 E "ar Zi!d

    !or5each3 Zi>ist7inter!ace 4 E Zi!d $ 7D +RAO 5"aria#les are immuta#leI D7 FoututG Zi!d7name '(((((((( ((( (( (((((((( (((((( ((( ((7((((7(((( ((((((( (((((((((( (( (((($ '(( (((((((:

    i!3 Zthis G Zthat 4 E "ar Zmsg bthis is really #igger than thatb FoututG Zmsgelse E "ar Zmsg bthat is not #igger than thisb FoututG ZmsgControl structures are !urther e(lained in an ucoming section o! this chater$

    'PathataTyes

    SOA' suorts the !our 'Path data tyes: 3string) num#er) #oolean) and node5set) 4 and the 'SOT result5tree5!ragment 3T4$ Since 'Path and 'SOT "aria#le tyes are .ell documented in many re!erencedocuments) including the 7ay 4ne #ooks) this section ser"es to ro"ide only a #rie! o"er"ie. and highlightkey concets$

    '(((((((

    '(((((( ((((((((( ((((((( (( (((((( (((( (( ((((($ '(((( ((( (( '(((((( ((((((( (((((() ((( ''((((((((((( ((((34 ((( (((((34 ((((((((($ ''((( (((( (((((((( ( (((((((34 (((((((( (((( (((((((((((((((((( (( (((((((((( (( (((((( (((( (( ((((($

     The numeric "alue o! 0 con"erts to !alse and any non5Qero num#er con"erts to true$ An emty string 3?@ or4 con"erts to !alse) and any non5emty string con"erts to true$ A non5emty node5set con"erts to true$ An

  • 8/16/2019 Copy Paste MasteringAutomation

    14/78

    emty node5set con"erts to !alse$ An T al.ays con"erts to true #ecause it al.ays contains a root node$

    AO-TI Be care!ul .hen e"aluating Ts in a Boolean conte(t since e"en an emty T co"erts to true$'(((((((:

    "ar Z#ol true34 7D true D7 "ar Z#ol 0 7D !alse in #oolean e(ression D7 "ar Z#ol 1 7D true in #oolean e(ression D7 "ar Z#ol bhellob 7D true in #oolean e(ression D7 "ar Z#ol bb 7D !alse in #oolean e(ression D7

    '((( (( (( ((((((((((( ((((((( ((((( ( (((((((( (( (((((((( (( ((((( ((((5((( ((((($ '((( (((((((((((((( (((( ((( ''' ((((( (((((((( 3((((((5((((4 (( ((((((( ((((((( (((( (((( ((( (((( (( ((((((((((((( (((($ '(( (((( (((( ((( (( ((((((( ((((((( (( '''':

    "ar Z#ol 7null 7D !alse in #oolean e(ression D7

    '((((((

    '(((((( ((( (((((( (( '''' 68 (((((((( ((((() ((((((((( ((( ((((((( '((5'5'((((( 3'('4 ((((($ '((((( (((((( ((((((( ((((((((( (((( (( ((((((( ((((((( (((((() (( (((( ((((((((((() ((( (( ((((( (((''((( ((((((34 (((((((($

    '(((((((:

    "ar Znum1 6 "ar Znum2 6$ "ar Znum\ Znum1 V Znum2 "ar Znum8 Znum1 V num#er3b6$b4 7D results in 10$ D7 "ar Znum6 Znum1 V true34 7D results is Y #ecause true34 con"erts to the "alue 1 D7

    '((((((

    '(((((( ((( (( ((((((( (( ((((((((( ((( ((((( (((( (((((( ((( ((((((5((((((((( 3 b4 (( ((( ((((((5((((((((( (((( 3&4 ((( ((( (((( (((( (((( (( (((( (( ((((( ((( ((( ((( (((((( ((((($ ''((( (((((((((((( ( ((((((34 (((((((( (( ((((((( ( (((5(((((( (((((((( (((( ( (((((( (((((((((($

    '(( ((( (((( ( ((((((5(((((( (((((( (((( (((((((( ( (((((( (((((:

    "ar Zstr bHo.&s it goingKb

    '(( ((( (((((( ( ((((((5(((((( (((((( (((( (((((((( ( (((((( (((((:

    "ar Zstr &She said: bHo. is it goingKb&

    '(( ((( (((((( (((((( ( (((((( ((((( (((( (((((((( (((( (((((( ((( (((((( ((((((:

    "ar Zstr &She said: bHo.&s it goingK& 7D +RAOII D7

    '((((((( ?'@ ((((((((( (((((((( (( ((((((( (( ((((:

    "ar Zstr bHello) WorldIfnb

    '(((((''(((''((((((((

    'SOT introduced the result tree !ragment concet$ As re"iously mentioned) there is not a lot you can do.ith these other than emit them to the scrit outut 3result5tree4) treat them as a string) or con"ert themto a node5set$

    AO-TI When declaring a result5tree5!ragment "aria#le .ith literal data) do not end the statement .ith asemicolon$

    "ar Zmy5rt!5"ar E Finter!aceG EFnameG bge507070b Finter!aceGFnameG bge507071b

    +otice that there is no semicolon a!ter the *nal close5#race 3 4$

    +,T- The imortant concet to remem#er is that temlates al.ays return an T$

    '((((((( ((( ((((((((( ((((((($ '((((( (((( (( ((((((( ((( ((( ((( F((((((G ((( (( ((((( ((( (((((((( ((( '(((( '''$ '(( ((( ((( ((((( (((( (((((( ( (((((((( ((( ((( (((((( ((((( (( ((( (((( (( (((((((( ((( (( ((( (((((((($ '(( ?'(((() '((((@ ((((((:

    ((((( 7 E F((5((((((5(((((((G E F((((((G b'(((() (((((Ib '((( (((((( xxxxx  ((( F((5((((((5(((((((G ((((((( (((((( ((((( (((((((( (( ((( ((((((5(((() (( ( ((((((5((((5((((((((I '(( ((((( 7 (((( (( ( (((((((() (((((((((( (( ((((((( (( (( '''$

    '(((( ((((((((( ((( ((((((5(((( ((( ((((( (((( (((( (( ((((((((( ((( F((((((G ((() (( ((((((((( ((((((( (( ((( '(((( '''$

    '(((( ( (((((((( (((((((( ( ((((((5((((5(((((((() ($($ (  xxxx  (((( ((((( (( (( ((((((((( (( (((

  • 8/16/2019 Copy Paste MasteringAutomation

    15/78

    ((((((( (( ((( ((((((5(((() ((( (((((( ((((( (( ((((((((( (( ((((((( ((( (((( (((((((:

    match 7 E Fo5scrit5resultsG E call hello5.orld34

    temlate hello5.orld34 E FoututG bHello) WorldIb '(((((((((( ((((( ((( ( (((((((( (( (((((( ((((((( ''' (((( (((((((((() ((( (((( ((( ((( ((((((($'(((( ((((((((( ((((((( '''() ((( ((((((( (((( (( ((((((((( (( ( ((((5((( ((((( ((( : (((((((($'((((((( ((( ((((((((( (((((((( (((( xxxxx  (( ''' (( F(((((G ((((((((:

    temlate make5colors34 E FcolorG E FnameG lue&

    FcolorG EFnameG &green& FcolorG EFnameG &red&

     Then the code to call this temlate and con"ert the results into a usa#le node5set .ould #e:temlate list5colors34 E

    "ar Zcolors : E call make5colors34

    !or5each3 Zcolors7color4 E "ar Zcolor $

    "ar Zmsg bThis color is b X Zcolor7name X b$b FoututG Zmsg '(( (((((( (( ((( '(((( ''' ((((( ((:

     This color is #lue$ This color is green$ This color is red$

    '(((5'(((

    '(((5(((( ((((( ((( (( (((((() ((( (((( ((((((((((() (( (((((((((( ((((((( (((( (((((((((( (( '''(((($ '(( (( (((( ((((((((((( (((( '(((( ''' ''') ((( ((((((( ((((((((((( (((((((() (( (((( ((((((( ((((5(((($ '(( (( (((( ((((((((((( (((( ((( '(((( ((((((((((((( (( ((((((((( (( (((((((((((((((( ((((5((($

    "ar Zmy5ns5"ar : E Finter!aceG EFnameG bge507070b Finter!aceGFnameG bge507071b 7D no semicolon here D7

    +,T- The key di

  • 8/16/2019 Copy Paste MasteringAutomation

    16/78

    discussion is resented in Chater \$

    M,-K -'SOT ro"ides a set li#rary o! !unctions$ e!er to htt:77...$e(slt$org7set7inde($ html !or moredetails$

    Comle(ataStructures

    '(((((( (((( (((((((((( ((( xxxxxxxx  ((((((((( (( '''') ((((( ((((((( ((( ((( (( ''' ((((5((((((( ''((( ((((((((((($ '( ((( ((((((( (( ((( (((((((( ((((((() ((( ((( (((((( (((((( (((((((((((((((( (((((((((( ((((( ''' ((((((7((((( (((((((() (( (((( (( ((((((( ''' (((((((((( (((((( ((((((((((($

    Mastering 'MO and 'Path e(ressions ena#les you to master Junos scrit de"eloment$

    M,-K ! you are looking !or additional training material on 'MO and 'Path) lease re!er to the W\school.e#site htt:77...$.\schools$com7 and the ay ,ne #ook) 8avi"atin" the Junos XL 9ierarchy, athtt:77...$unier$net7dayone$

    '( ((( ((( ((((((( ((( (((( (((((((( (( ((((((( (((( (((((((((() ((( ((( (((( ( (((( (( ((( '((((((((((((((((($ '((( ((( '(((( (((((() ((( ((( ((((((((( (((((((:

    user]unosG sho. con*guration [ dislay (ml

     %ou .ill #e resented .ith the Junos con*guration *le in 'MO !ormat$

    '(((((

     The 'SOT language does not ha"e a nati"e array data5tye) #ut there is a techni=ue !or using node5set'Path e(ressions to accomlish the same e

  • 8/16/2019 Copy Paste MasteringAutomation

    17/78

    '(((( ((( ( (((((( (( (((((((((( (( ''''$ '(( (( (( (((( (((  xxx  (( ((((((((( (( ((( (((($ '(((((((((:

    "ar Zhash : E Finter!ace namebge507070bG bub Finter!ace namebge517070bG bdo.nb

    FoututG bge507070 is b X Zhash7inter!ace^]name&ge507070&_+,T-N The element name Finter!aceG and the attri#ute name name are comletely u to you as the

    rogrammer$'(((( ((((( (( (((( ((( ((((((((( (( (((( ((((((() ((( ((((( xxxxx xxxx  ((( ''((( (((((((((() (((((((:

    FoututG bge507070 is b X Zhash7inter!ace^]D&ge507070&_

    ' (((((((((( ((((((((( (((((((( (( (( (((( ((( ((( (( ((((((( (((((( (((( (( ((((((((($ '(((((((((:

    "ar Zhash : EFinter!aceG E FnameG bge507070b FstatusG bubFinter!aceG E FnameG bge517070b FstatusG bdo.nb

    FoututG bge507070 is b X Zhash7inter!ace^name&ge507070&_7status

    '( ((( ((( ((( (( ((( ((((( (((((((() ((((((((((( ((( ((((((( ((((( ((( (( ((((((( (((((((((((((((( ((( '((( (((((((((( (((((( (( ((((((( ((( ((((((((((($ '( ((( ((((((( ((((( ((( ((( (( ((((((((((() ((( (((( 3((((((4 ((( (((((( ((( ((((( (( ((( ((((((( F(((((((((G$ '( ((( ((((((( ((((( (((((( (( (( ((((((( 3((((4) ((( ((((( (( (((((( ((( ((((((( ((((((( ((( (((( (((( ((( (((((( ((( ((((((((((((( (( ((((((((($

    '(((((( (((((((( (( (( ((( ((( '''' F(((:(((G (((5((((( ((((((( ((( (((34 (((((((($ '((((((( (((((((((((( ((((((( (((( (( ((((( ((( '(((( ((((((( ((((($ '(( (((((( (( ((( (((( ((((( ((((((( ((:

    user]unosG sho. route

    inet$0: 8 destinations) 8 routes 38 acti"e) 0 holddo.n) 0 hidden4V Acti"e oute) 5 Oast Acti"e) D Both

    0$0$0$070 D^Static76_ 00:01:89 G to 12$1Y9$2$1 "ia ge507072$0 10$10$10$17\2 D^irect70_ 0\:\:02 G "ia lo0$0 12$1Y9$2$0728 D^irect70_

    0\:\9:29 G "ia ge507072$0 12$1Y9$2$1Y7\2 D^Oocal70_ 0\:\9:\2 Oocal "ia ge507072$0

    '(( ((((((((( (( ((( (((( (((((( (( ''' (((((($ '(( ((((( ((((((((( (( ((( ((( (((((( (((( (((F((((((((5((((G ((( ((( F((G7F(((G (((((( (( ((( (((((((( (((((( (((( ((( ((((( (( ((((((( ((((5(((($:

    user]unosG sho. route [ dislay (ml

    Frc5rely (mlns:unosbhtt:77(ml$unier$net7unos710$2\7unosbGFroute5in!ormation (mlnsbhtt:77(ml$unier$net7unos710$2\7unos5routingbG FI55 keeali"e 55G Froute5ta#leGFta#le5nameGinet$0F7ta#le5nameG Fdestination5countG8F7destination5countGFtotal5route5countG8F7total5route5countG Facti"e5route5countG8F7acti"e5route5countG Fholddo.n5route5countG0F7holddo.n5route5countG Fhidden5route5countG0F7hidden5route5countG Frt unos:style#rie!GFrt5destinationG0$0$0$070F7rt5destinationGFrt5entryG Facti"e5tagGDF7acti"e5tagG Fcurrent5acti"e7G Flast5acti"e7G

  • 8/16/2019 Copy Paste MasteringAutomation

    18/78

    ((((( (( ((( ((((( (((((((( 3'(((((4 ((( ((( ((((( (( ((( ((((5((( ((((($ '((((((( ((( ((((((((((((((((( ((((((:

    "ersion 1$0

    ns unos bhtt:77(ml$unier$net7unos7D7unosb ns (nm bhtt:77(ml$unier$net7(nm71$17(nmb ns cs bhtt:77(ml$unier$net7unos7commit5scrits71$0b

    imort b$$7imort7unos$(slb

    7D e*ne F(sl:keyG elements D7 F(sl:key namebrotocolb matchbroute5ta#le7rtb usebrt5entry7rotocol5namebG F(sl:keynamebne(t5hob matchbroute5ta#le7rtb usebrt5entry7nh7"iabG

    "ar Zmatch5rotocol bStaticb 7D .e .ant to match on bstaticb routes D7 "ar Zmatch5inter!ace bge507070$0b 7D .e .ant to match onroutes "ia inter!ace ge507070$0 D7

    match 7 E Fo5scrit5resultsG E "ar Zresults cs:in"oke3bget5route5in!ormationb4

    7D Change current node to the Zresults 'MO document D7 !or5each3 Zresults 4 E

    7D islay all static routes D7 FoututG Zmatch5rotocol X b routes: b !or5each3 key3 brotocolb) Zmatch5rotocol 4 4 EFoututG rt5destination

    7D islay all routes .ith ne(t5ho o! ge507070$0 D7 FoututG b+e(t5ho b X Zmatch5inter!ace X b: b !or5each3 key3 bne(t5hob) Zmatch5inter!ace 4 4 E

    FoututG rt5destination

    '(( (((34 (((((((( (( (((( (((((( ((( (((5(((( ((((((( (((((((((($ '(( ((((5(((( (((( ((( (((34 (((((((( ((((((( (( ((((((( (( ((( ((( ((((((($ '((( ((( ((((((( ((((((((((( (((((( (((((5(((((7(( ((((5(((( ((((( (((( ((( ((( ((((( (((((((( (( ((( (((((((((($ '(((((((( ((( (((( (((((((:

    !or5each3 key3 brotocolb) Zmatch5rotocol 4 4 E FoututG rt5destination'(( ((((((( (((( (( ((( (((5(((( (((( ((((((( ((( (((((5(((((7(( (((((((( (((( (((( ( ((((((((5(((( ((((((( (((( ((( ((((( ((((( (( ?'(((((@$ '( ((( ((((( ((((((( ((((( (( (((( ((( ((((( (((( (((((((((((:

    Froute5ta#leG Fta#le5nameGinet$0F7ta#le5nameG Fdestination5countG8F7destination5countG Ftotal5route5countG8F7total5route5countG Facti"e5route5countG8F7acti"e5route5countG Fholddo.n5route5countG0F7holddo.n5route5countG Fhidden5route5countG0F7hidden5route5countG Frt unos:styleb#rie!bGFrt5destinationG0$0$0$070F7rt5destinationGFrt5entryG Facti"e5tagGDF7acti"e5tagG Fcurrent5acti"e7G Flast5acti"e7G

  • 8/16/2019 Copy Paste MasteringAutomation

    19/78

    '('(((((((

    '(( Z((((((((( (((((((( (( ( ((((((( (((((( (((((((( ((( (( ((((((( (((( (((((((( ((( ((((((( (((((((((((( (((( (( ((( (((($

    '((((((( (( (( (((((( (((( ((( ((( ((((((((((: ((((((((( ((( (((((5((((((($ '(( (((( (( ((((((((((( (((( ((((( (((( (((( ((( (((((((((:

    7D glo#al arameters 5scrit command5line otionsD7

    aram Zinter!ace aram Zadmin5control &disa#le&

    7D glo#al "aria#le to ro"ide command5line otion hel D7

    "ar Zarguments EFargumentG E FnameG &inter!ace& FdescritionG &The inter!ace to control&FargumentG E FnameG &admin5control& FdescritionG &^ena#le [ disa#le_) de!ault is disa#le&

    +,T- Take secial notice that the arameter name and the name in the Zarguments "aria#le must match inname$ or e(amle) the *rst aram is Zinter!ace) and the *rst FargumentG7FnameG is inter!ace$

    +,T- Also notice that the Zadmin5control is assigned a "alue o! disa#le$ This means that i! the user does not

    ro"ide the admin5control command5line otion) then the scrit #eha"es as i! the user did ro"ide the admin5control otion .ith the "alue o! disa#le$

    '((( ( (((( ((((((( (((( 3K4 (( ((( ((((((( (((() (((( ((((( ((( ((( (((((((((:

    user]unosde"G o change5inter!ace K

    Possi#le comletions: F^-nter_G -(ecute this command FnameG Argument name admin5control ^ena#le [ disa#le_) de!ault is disa#ledetail islay detailed outut inter!ace The inter!ace to control [ Pie through a command

    '(((('(((((((

    Starting in Junos $0) e"ent olicies used to trigger e"ent5#ased automation can #e directly con*gured intothe e"ent scrit rather than #eing stored in the Junos con*guration *le$ There are three main ad"antagesto this aroach:

    0. educed con*guration siQe: Because the e"ent olicy is no longer a art o! thecon*guration *le) the e"ent5otions con*guration hierarchy is smaller) esecially .hen multile e"entscrits are in use$

    1. -asier deloyment: By integrating the e"ent olicy .ithin the e"ent scrit) installation#ecomes a matter o! coying the scrit to the Junos de"ice and ena#ling the scrit under e"ent5otions$

     The actual e"ent olicy is distri#uted .ithin the e"ent scrit and does not ha"e to #e con*gured on eachde"ice$

    2. Consistent e"ent olicies: Because the e"ent olicy is em#edded .ithin the e"ent scrit) all Junos de"ices that ena#le the scrit share a consistent olicy con*guration$

    '(( Z(((((5(((((((((( (((((((( (( ( ((((((( (((((( (((((((( (((( (( ((((( ((( ((((( (((((($

    '(( ((((((((( (( (( ((((((( (( (( (((((((( ((((( (((((( (((((((((( (((( ((((( (( (((((((( (( (((((((( (((((( (((((( (((((5(((5((((((((((($((((:

    "ar Ze"ent5de*nition E Fe"ent5otionsG EFgenerate5e"entG E FnameG be"ery5hourb Ftime5inter"alG b\Y00bFolicyG E FnameG bcheck5"ar5utiliQationb Fe"entsG be"ery5hourb FthenG EFe"ent5scritG E FnameG bcheck5"ar5utiliQation$sla(b

    M,-K or more details on e"ent scriting and em#edding e"ent olicies) re!er to This Wee! Applin" Junos Automation #ook at ...$unier$net7dayone$

    '((((''((((((

    '((((((( (( '(((( 11$1) ( ((( (((((( (((((((() Z(((((5((((((() (((((((( ((((((((((( (((( (( (((((( ((((( ((((((( (( (((( (( ((((((((((( (((( (( (((((((( (( ((( (((((( (((($ '(( ((((((((( (((((((( (((''' ((((((( ((((((( ((( (((( (( ((( (((((( ((((($ '(((((((( ((((( (((((((() (((( ((((((( ((((((((($

    '(( (( (((((((:

  • 8/16/2019 Copy Paste MasteringAutomation

    20/78

    Funos5conte(tG FhostnameGsr(210F7hostnameG FroductGsr(210hF7roductG FlocaltimeGWed Aug 19 0:08:\02010F7localtimeG Flocaltime5isoG2010509519 0:08:\0 TCF7localtime5isoG Fscrit5tyeGoF7scrit5tyeG FidG1Y8\F7idGFttyG7de"7tty0F7ttyG FchassisGothersF7chassisG Frouting5engine5nameGre0F7routing5engine5nameG Fre5master7G Fuser5conte(tGFuserGnrF7userG Fclass5nameG5suer5userF7class5nameG FuidG2001F7uidG Flogin5nameGnrF7login5nameGF7user5conte(tG Fo5conte(tG F"ia5url7G F7o5conte(tG F7unos5conte(tG

    '(( (((((( (((((((:

    Funos5conte(tG FhostnameGsr(210F7hostnameG FroductGsr(210hF7roductG FlocaltimeGWed Aug 19 12:\0:20

    2010F7localtimeG Flocaltime5isoG2010509519 12:\0:20 TCF7localtime5isoG Fscrit5tyeGcommitF7scrit5tyeG FidG\00\F7idGFttyG7de"7tty1F7ttyG FchassisGothersF7chassisG Frouting5engine5nameGre0F7routing5engine5nameG Fre5master7G Fuser5conte(tGFuserGnrF7userG Fclass5nameG5suer5user5localF7class5nameG FuidG2001F7uidG Flogin5nameGnrF7login5nameGF7user5conte(tGFcommit5conte(tG Fcommit5sync7G Fcommit5con*rm7G Fcommit5check7G Fcommit5#oot7G Fcommit5commentGWalking and che.inggumF7commit5commentG

    F7commit5conte(tG F7unos5conte(tG

    '(( ((((( (((((((:

    Funos5conte(tG FhostnameGsr(210F7hostnameG FroductGsr(210hF7roductG FlocaltimeGWed Aug 19 18:26:002010F7localtimeG Flocaltime5isoG2010509519 18:26:00 TCF7localtime5isoG Fscrit5tyeGe"entF7scrit5tyeG FidG169F7idGFchassisGothersF7chassisG Frouting5engine5nameGre0F7routing5engine5nameG Fre5master7G Fuser5conte(tGFuserGrootF7userG Fclass5nameGsuer5userF7class5nameG FuidG0F7uidG Flogin5nameGrootF7login5nameG

    F7user5conte(tG F7unos5conte(tG

    '(( (((5((((( ((((((((:

    ' F((((((((G 5 '(( (((((( (((((((() (((( (( Z(((((((($

    N FroductG 5 The roduct) same as Zroduct$' F(((((((((G 5 '((( (((( ((( (((((( ((( ((((((() (((( (( Z((((((((($

    ' F(((((((((5(((G 5 '((( (((( ((( (((((( ((( ((((((( 5 (( ''' (((((() (((( (( Z(((((((((5((($

    ' F((((((5((((G 5 (() ((((() (( (((((($

    ' F(((G 5 ((((((( '' (((((( ((( ((( ((((((( ((((((($

    ' F(((G 5 ''' (( ((( ((((( ((((((( 3(( ((((((( (( ( (((( (((((((4$

    ' F(((((((G 5 (((((( '' '((((( 3((( (( (((4) ''' 3((( (( (((4) (( ((((((((( (( (( ?((((((@$

    N Frouting5engine5nameG 5 name o! the - that the scrit is running on$' F((5((((((G 5 (((( ((((((( (( ((( (((((( (( ((((((( (( ((( (((((( (((((((5(((((($ '(( F((((5

    (((((((G ((((((((:

    ' F((((G 5 ((((( (((( (( (((( (((( ((((((( ((( (((((($

    ' F(((((5((((G 5 ((((( ((((( (( (((( (((( ((((((( ((( (((((($

    ' F(((G 5 ''' (( (((( (((( ((((((( ((( (((((($

    ' F(((((5((((G 5 ((((( (((( (( (((( (((( ((((((( ((( (((((($ '( ''' (( (( ((() (((( (((( (( ((( (((((( ((( (((((( (((((((((((((( (((((($

     The Fo5conte(tG element:

    'F(((5(((G

     5 (((( ((((((( (( (( (((((( ((( (((((((( ((( ?(( (((@$ '((F((((((5(((((((G

     ((((((((:

    ' F((((((5((((G 5 (((( ((((((( (( ?(((((( (((((((((((@ ((( ((((((((($

    ' F((((((5(((((((G 5 (((( ((((((( (( ?(((((( (((((((((@ ((( ((((((((($

    ' F((((((5(((((G 5 (((( ((((((( (( ?(((((( (((((@ ((( ((((((((($

    N Fcommit5#ootG 5 only resent on the initial #oot5u commit$

    ' F((((((5(((((((G 5 (((( ((((((( (( ( ((((((( ((( (((((((( ((( ((( (((((($ '((( (((

    (((( ((((((((( ((((( (((( ((( ((( (( (((((((() (( ((((((((() (((( (((((((((((:

    ' ' ((((( (((((( (((( (((( (((((( ((((((( (((((((( (( ((((( (( ((((((( ((((( (((((: '(( Z(((((5(((((((7((( (( (((((((((( (((((( ((( (((( ((((((( ((( F(((((((5((((((5

    ((((G '''$' ' ((((( (((((( (((( (((((( ( ((((5((((( (((((( (((((( (((( (((((( ((( ((((((((((( ((((((: '(( Z(((((5(((((((7((( (( (((((((((( (((((( ((( (((( ((((((( (((F(((((((5((((((5((((G '''$

  • 8/16/2019 Copy Paste MasteringAutomation

    21/78

    ' '( ((((( (((((( (((( (((((( (((( ((((((( ((((((((((((( ((((((( (( ((( (((((((((((((5((((((: '(( Z(((((5(((((((7((5(((((((( ((((((((( (( ((( (((((( (( ((((((( (( ((((((((( (((((((5(((((( (( ((($

    ' ' (((((( (((((( (((( (((((( (((( ((( (((((( ((( ((((5(( ((((((: '(( Z(((((5(((((((7((((((5(((((((7((((((5(((((( ((((((((( (( ((( (((((( (( ((((((( (( ((($

    N A commit scrit that should re"ent certain changes #ased on the user: se Zunos5conte(t7user5conte(t7user to determine the local user name) or Zunosconte(t7user5conte(t7class5nameto determine their local class$' ' (((((( (((( (((((( ((((((( ((( (((((( (((((: '(( Z(((((5(((((((7((( (( (((((((((((( ((((((( ((((((( '' (( (((( (((( ?(((( (((((( ((((((((( (((((((((@$

    N A scrit that should kill a users login session: se Zunos5conte(t7tty to accurately logoutthe user through the Fre=uest5logout5userG PC$Control Statements

    !7Then7-lse

    '''' (((((((( ( ?'@7'((( ((((( (( ((( ''7''''7'''' ((((((((($ '(( (((((( ((((( ((( ((((((((((((((:

    i!3 FconditionG 4 E L'(:i!3 FconditionG 4 E Lelse E L

    '(:

    i!3 FconditionG 4 E else i! 3FconditionG 4 E else E

    '((( (((( ((((((( ((((( (((( (((((((( (((( (( ((((((($

     The FconditionG is any "alid Boolean e(ression$ ee in mind that a Boolean e(ression can #e the result o! any simle test e(ression) comle( 'Path e(ression) results o! !unction calls 3#ut not temlatesI4) andany com#ination o! the a#o"e$

    M,-K or details on the seci*c Boolean test oerations) lease re!er to htt:77...$.\schools$com7(ath7(athXoerators$as and the SOA' re!erence documentationhtt:77code$google$com77li#sla( $

    '(( (( ((( (((((( ((((((((( ((((( ((: ?'( ' ((( (((( ((( ( (((((((( (((() ((( (( ' ((( ( ((((((((((((( (( ( ((((((((((( (((((((((K@

    '(( ((((((( (((((((( (((( ((((( (((( ((((((((( (((( (((( 3'((( (((((4:

    Perl my Znum#er 0

    i!3 Zinut F 10 4 E Znum#er 2else E Znum#er 1

    '''' ((((( ((((( ((((((((( (( ((( (((( (((( ((((((((((( (((((((( ((((((((((( ((((((( ((((((((((((( '''($ '(( ((((( ((((((( ((((( (( ((((( (( '''' (( (((((((:

    "ar Znum#er : E i!3 Zinut F 10 4 E e(r 2 else E e(r 1

    i!3 Zthis F Zthat 4 E FcolorG bBlueb FcolorG b%ello.belse E FcolorG bPinkb FcolorG bPurleb

    !or5each3 Zmynodes7color 4 E FoututG $

    '((( ((( '' (((((( (( (((() (((( ((( ((((((((( (((((( ((((( ((:

    reen Blue %ello.'((( ((( '''' (((((( (( (((() (((( ((( ((((((((( (((((( ((((( ((:

    reen Pink Purle

    '(((((() (( ((( ((((( ((( Z((((((( (((( ((( (((((( (((((((((( 34 (((((( (((( ((( (((((5(((((( 3:4)

  • 8/16/2019 Copy Paste MasteringAutomation

    22/78

    (((( ((( (((((( ((((( ((((((( ( ((((((( ((((() (( (((((:

    error: n"alid tye error: runtime error: *le 7"ar7d#7scrits7o7test$sla( element !or5each error: ailed to e"aluate the &select& e(ression$

     The reason !or this error is that the !or5each statement re=uires a node5set$

    or5-ach

    '(( (((5(((( ((((((( ((((((((( (( ( (((((( ((((((( ((((((((( (( '''' (((( (((((( ((( (( ((((((((((( ( ((((5((($ '(( (((((( ((:

    !or5each3 F(ath5e(resssionG 4 E L '(((( (((( (( ((((((( (( ((((( (((5(((( (( ((( Xx#Xxxx#Xxxx  (((((((:

    !or5each3 Zmynodes7color 4 E FoututG $ '(( ((( ((((( 3$4 ((((((( ((( (((((((( (((((((( (((((((( (( (((( (( ((( ((((( (( ((( ((((5((( (((((( ((( ((((((((( (( ((( (((5(((( (((($ '(( ((( (((((((( (( (((( (( ((( (((( ((( (( ((( ZX  (((((((( (('((($ '(( ((((( ((((( (( ((5((((((( ((:

    !or5each3 Zmynodes7color 4 E "ar Zcolor $ FoututG Zcolor

     '(( (((( (((( (( ((((( ((((( (( ((((((( (( '((( ((:

    erl

    !oreach 3]mynodes4 E rint! ZX

    +,T- or large #locks o! code .ith multile layers !or control) it is recommended to e(licitly assign a"aria#le to the dot secial "aria#le$

    '( ((((( (((( ((( ((7((((7(((() ((( (((5(((( ((((((( ((( (( (((( (( (((((( ( (((((((( ((( (( (((($ '((((( (( ((((((( (((( (((((((( ( (((( (( (( (((((((((() (((( ((( (((( ((( ((( ''5((((((( (((((($

    "ar ZgeXinter!aces : E !or5each3 Zinter!aces7inter!ace^starts5.ith3name) bge5b4_ 4 E "ar Zi!d $

    Finter!aceG E FnameG Zi!d7name Fi5addrG Zi!d7unit^name0_7!amily7inet7address7name

    +,T- The node5list elements .ithin the !or5each control are created comletely at your discretion$ Theelements a"aila#le to the Zi!d are seci*c to the node5set resented to the !or5each F(ath e(ressionG$ That

    is) the choice o! using the element name Finter!aceG .ith child elements o! FnameG and Fi5addrG are not tiedto anything seci*c$ But Zi!d7name is tied to the !act that the !or5each inter!ace node5set has a name elementand a unit element$

    '(((((((((() ((( ((( (((( (( ((((((((((( (((((( ((((((( (((( (((((((((($

    !or5each3 Zge5inter!aces7inter!ace 4 E FoututG bnter!ace b X name X b has P5addr o! b X i5addr '(((( ((((((( (( ((((((( (((((( ((:

    nter!ace ge507070 has P5addr o! 12$1Y9$10$1728 nter!ace ge507176 has P5addr o! 12$1Y9$20$2728 nter!ace ge57171 has P5addr o!12$1Y9$\0$1728

    While

    SOA' 1$0 does not ha"e nati"e suort !or a .hile control structure) #ut it is a"aila#le in SOA' 1$1$ ntilSOA' 1$1 is a"aila#le in Junos) you must use thetechni=ue o! using recursi"e temlates to roduce the desired coding results$M,-K or !urther details on SOA' 1$1 and the .hile control structure) re!er to htt:77code$google$com77li#sla($

    '((((((( ((( ((((((((( '((( xxxxx xxxx :

    erl

    my Zcounter 0

    .hile3 Zcounter F ZS,M-5B5RAO- 4 E L Zcounter V ZS,M-5+C5RAO-

     The e=ui"alent code in SOA' 1$0 .ould #e:

    match 7 E 7D main #lock o! code D7

    call do5.hile5stu

  • 8/16/2019 Copy Paste MasteringAutomation

    23/78

    i!3 Zcounter F ZS,M-5B5RAO- 4 E L call do5.hile5stuhileloop construct in your code$

    AO-TI Junos scrit suorts a ma(imum recursion deth o! \000$ -(ceeding this causes the scrit to a#ort.ith an error$ Also kee in mind that memory allocation !or any "aria#les is not released until all o! the

    recursi"e rocessing comletes$

     The recursi"e temlate must  contain t.o arts: the *rst is the i!  control at the #eginning to ensure that thecondition is still met) and second) the recursi"e call to the temlate modi!ying the "alue o! the condition"aria#le$

    o5While

    SOA' 1$0 does not ha"e nati"e suort !or a do5.hile control structure$ %ou must use the recursi"e temlatetechni=ue to roduce the desired coding results$

    Comare the standard do5.hile code: erl

    do E L Zstatus get5ne.5status34

    .hile 3Zstatus I bdo.nb4

    '((( ((( '''' ((((((((((:

    match 7 E

    "ar Zstatus get5*rst5status34call do5.hile5status5not5do.n3 Zstatus 4 7D call the recursi"e temlate D7

    temlate do5.hile5status5not5do.n3 Zstatus 4E L "ar Zne.5status get5ne.5status34

    i!3 Zne.5status I bdo.nb 4 E call do5.hile5status5not5do.n3 Zstatus Zne.5status 4

     The rimary di

  • 8/16/2019 Copy Paste MasteringAutomation

    24/78

     There are a num#er o! .ays in .hich you can create modular code$ ,ne o! the *rst .ays is to createimport  *les ; e

  • 8/16/2019 Copy Paste MasteringAutomation

    25/78

    "ar Zmycolors : E FcolorG breenb FcolorG bBlueb FcolorG b%ello.b

    temlate make5colors34E FcolorG breenb FcolorG bBlueb FcolorG b%ello.b

    "ar Zmycolors : E call make5colors34

    "ar Zlist : E FitemG breenb FitemG bBlueb The other key oint regarding temlates is that they al.ays roduce a esult5Tree5ragment$ or e(amle)the !ollo.ing roduce identical results:

    s e=ui"alent to :

    And LFitemG b%ello.b

    temlate make5colors5!rom5list34 E !or5each3 Zlist7item 4 E FcolorG $

    "ar Zmycolors : E call make5colors5!rom5list34

    unctions

    unctions are not nati"e to SOA' #ut ha"e #een included as art o! the -(tended 'SOT Oi#rary 3-'SOT4$ Junos includes the -'SOT !unctions that are art o! the li#(slt distri#ution$

    M,-K or comlete li#rary documentation on -'SOT suort) re!er to htt:77...$e(slt$ org7$

    '''' 1$0 (((( ((( (((( (((((( (((((((( (((((( ((((((() ((( (((( (((( (( (((((((( (( '''' 1$1$ '(((('''' 1$1 (( (((((((( (( '(((() ((( (((( (((( (( (((( '''' ((((((((( (( ''''$

    '( ((((( (( ((( ((((((((( (( '''') ((( (((( ((((((( ((( (((( ((((((((( ((((((((((( (( ((( ((( (( ((((((((( ((((:

    ns !unc e(tension bhtt:77e(slt$org7!unctionsb

    AO-TI +otice the resence o! the e(tension key.ord$ %ou must  include this key.ord .hen including the-'SOT unctions namesace$ A comlete listing o! -'SOT namesaces and li#raries can #e !ound athtt:77...$e(slt$org7$

    '(( (((( (((( ((((((( (((( ((( ((((((((() ((((( (((((( ((((((((( ((( (((((((( (( (((( ( (((((((((((((((($ '(((( ((( xxxxxx  ((((((() ((( (((((((( (((5((5(((( ((((( (((( (((( ((( (((((((((:

    "ersion 1$0

    ns unos bhtt:77(ml$unier$net7unos7D7unosb ns (nm bhtt:77(ml$unier$net7(nm71$17(nmb ns cs bhtt:77(ml$unier$net7unos7commit5scrits71$0b ns !unc e(tension bhtt:77e(slt$org7!unctionsb

    ns mycor bhtt:77(ml$mycor$com7unosb

    imort b$$7imort7unos$(slb

    '(( (((( ((( '''' (( ((((((( ((( (((((((( ((((( ((( (((((( (( ((( ((((((((( (( ''''1$0$ '(( ((((((((( (((((((( (((((( (((((((((( ((( (((((((( (((((:F!unc:!unction namebmycor:incrbG E aram Znum

    F!unc:result selectbnum#er3ZnumV14bG

  • 8/16/2019 Copy Paste MasteringAutomation

    26/78

    AO-TI t is imortant to understand that the F!unc:resultG element de*nes the "alue that is #eing returned$t does not) ho.e"er) sto code e(ecution$ This #eha"ior is di

  • 8/16/2019 Copy Paste MasteringAutomation

    27/78

     The cs:oen34 routine is used to oen a connection to the Junos management daemon$ ! you call this routine.ithout any arameters) it oens a connection to the local Junos de"ice there!ore) the one running thescrit$"ar Zconnection cs:oen34

    '(( ((() ((((((() ((( (((( (((( ((((((( (( (((( ( (((((((((( (( ( (((((( '(((( (((((() ((( ((((((('''( (( (((( ((((((:

    "ar Zremote5de" cs:oen3 b12$1Y9$1$22b) badminb) badmin12\b 4

    '( ((( ((( ((( (((( ((( ((((( (((() ((( ((((( ((((((((( (( ((( (((((((( (( ''5((((((( (( ((( (((((((((((() ((( (((( (( ((( ((((5(((() ((( ((((((( ((((( (( ((( (((((((($ '(((((((( (((((((( ((( (( ((((((( (( (((((((( ((((((((( (((( (((( ((((((($ '(( ((((( (((((( ((( (((( ((( ( (((((((( ((((( (((:(((5((((((34) ((( ((((((($

    '(( (((:(((((((34 ((((((( (( (((( (( ((((((( ((( ''' (((( ((( (((( (( (((( (((((((((($ '(( (((((((:

    "ar Zin"entory cs:e(ecute3 Zconnection) &get5chassis5in"entory& 4 "ar Zin"entory5detail cs:e(ecute3 Zconnection) Zget5in"entory 4

    '(( (((:(((((34 ((((((( (( (((( (( ((((( ((( (((((((((( (( ((( '(((( (((((((((( (((((($ '(( (((((((:

    e(r cs:close3 Zconnection 4 The use o! the e(r key.ord here is used to consume the return "alue) assumingyou do not care a#out the result o! the  cs:close34 routine$

    singthePCesults

    '((( ((( (((( (((((((( (( ''' ((( (((( (( (((((((((( ((( ''' ((((((((( (( ((( ((((((( (( ((( ((((((((( ((( ((((((((((( ((((((((((($ '((((( (((( ((( (((((( (((((((( (( (((:((((((34 ((( (((:(((((((34 ((( ((((5((( (((( (((($

    sing the sho. chassis hard.are as an e(amle) you can e(amine the results in 'MO !ormat using the [ dislay(ml on the command line$ or e(amle: user]unosG sho. chassis hard.are [ dislay (ml

    Frc5rely (mlns:unosbhtt:77(ml$unier$net7unos710$2\7unosbG Fchassis5in"entory(mlnsbhtt:77(ml$unier$net7unos710$2\7unos5chassisbGFchassis unos:stylebin"entorybG FnameGChassisF7nameG Fserial5num#erGJ+111\B6AF7serial5num#erGFdescritionGJ2\20F7descritionG Fchassis5moduleGFnameGMidlaneF7nameG F"ersionG-R 0YF7"ersionG Fart5num#erG10501669F7art5num#erG Fserial5num#erGRY201F7serial5num#erG

    F7chassis5moduleGFchassis5moduleG FnameGSystem ,F7nameG F"ersionG-R 0F7"ersionG Fart5num#erG105016Y2F7art5num#erG Fserial5num#erGRYY80F7serial5num#erG FdescritionGJ2\'0 System ,F7descritionGF7chassis5moduleGFchassis5moduleG FnameGCryto ModuleF7nameG FdescritionGCryto AccelerationF7descritionGF7chassis5moduleG Fchassis5moduleG FnameGouting -ngineF7nameGF"ersionG-R 12F7"ersionG Fart5num#erG105016Y0F7art5num#erG Fserial5num#erGRYYYF7serial5num#erGFdescritionG-5J2\2052000F7descritionGF7chassis5moduleGFchassis5moduleG FnameGPC 0F7nameG FdescritionGPCF7descritionG Fchassis5su#5moduleGFnameGPC 0F7nameG FdescritionG8( - Base PCF7descritionG

    F7chassis5su#5moduleG F7chassis5moduleG Fchassis5moduleGFnameGPC \F7nameG F"ersionG-R 1\F7"ersionG Fart5num#erG60501616\F7art5num#erG Fserial5num#erGRYYF7serial5num#erG FdescritionGPCF7descritionG Fchassis5su#5moduleGFnameGPC 0F7nameG FdescritionG9( - uPMF7descritionG

    F7chassis5su#5moduleG F7chassis5moduleG Fchassis5moduleGFnameGPo.er Suly 0F7nameG F7chassis5moduleG F7chassisG F7chassis5in"entoryG

    FcliG F#annerGF7#annerGF7cliG F7rc5relyG

    '(( (((((( (((((((( (( xxxxxx  (( ((( ((((((( ((((((((((( ((((((((( ((( F(((5(((((G ((((((( (( ((((((((((() (((( ((((( (( F(((((((5(((((((((G$

    '(( ((((((() (( ((( (((((( (( (((( ((((((( (((( (( ((( F(((((((5((((((G (((((((( (((((((((( ((((((((( (((( (((((( ((((((() ((( (((( ((((( ((:

    match 7 E Fo5scrit5resultsG E

    "ar Zin"entory cs:in"oke3 &get5chassis5in"entory& 4

    !or5each3 Zin"entory7chassis7chassis5module^serial5num#er_ 4 E FoututG bModule b X name X b) serial num#er: b X serial5num#er

    '((( (((((( ((((( ((((((( ((( ((((((((( ((((((:

    Module Midlane) serial num#er: RY201 Module System ,) serial num#er: RYY80 Module outing -ngine) serial num#er: RYYYModule PC \) serial num#er: RYY

    AO-TI Mastering 'Path e(ressions is the key to mastering Junos automation scriting$ Without a good

  • 8/16/2019 Copy Paste MasteringAutomation

    28/78

    understanding o! 'Path and 'SOT rocessing) the !or5each loo in the a#o"e e(amle might #e diUcult tounderstand$Console nut 7 ,utut

    singcs:get5inut34andcs:get5secret34

    '((( (((:(((5(((((34 ((( (((:(((5((((((34 ((( (( (((( (( (( ((((((( (( (((((( ((((((( ((((( (((( ((( (((($'(( (((:(((5(((((34 ((((((( (((((( ((( (((( (((( ((( (((( (((((() ((((( ((( (((:(((5((((((34 (((( ((( ((((((( (((($

    '((((((( ((( ((((((((( ((((((( (( (((((( (((( (( (((( (( (((((((( ((((( (( ((((((( '(((( ((((((((( (((((((( ((( (((((((( (((((((:

    "ersion 1$0

    ns unos bhtt:77(ml$unier$net7unos7D7unosb ns (nm bhtt:77(ml$unier$net7(nm71$17(nmb ns cs bhtt:77(ml$unier$net7unos7commit5scrits71$0b

    imort b$$7imort7unos$(slb

    match 7 E Fo5scrit5resultsG E

    "ar Zremote5host cs:get5inut3 b-nter host5name: b 4 "ar Zuser5name cs:get5inut3 b-nter user5name: b 4 "ar Zass.ord

     cs:get5secret3 b-nter ass.ord: b 4

    7D ,en the remote connection D7 "ar Zconnection cs:oen3 Zremote5host) Zuser5name) Zass.ord 4

    i!3 Zconnection 4 E "ar Zresult cs:e(ecute3 Zconnection) bget5so!t.are5in!ormationb 4

    7D ra# the "ersion 5This ath should .ork on #oth single and multi5re systems D7 "ar Z"ersion Zresult7$$77so!t.are5in!ormation^1_7ackage5in!ormation n̂ame bunosb_

    e(r cs:outut3 bJunos "ersion on remote host: b) Z"ersion7comment 4 else Ee(r cs:outut3 bna#le to oen a connection$b 4

    nderstandingFoututGRersuscs:outut34Rersuscs:rint!34

    '((( F((((((G ((( (((:((((((34 ((( (( (((( (( (( ((((((( (( (((( ((((((( (( ((( ((((((($

    '(( F((((((G (((((((( ((( (((((((( (( '(((( (( (((( (( ((( ((((((5(((() (((( (() (( ((( (((((((((( ((

    ((( '(((( (((((($ '((( ((( ((( (((:((((((34) ((( (((((( (( ((((((((((( (((( (( ((( ((((((($ '(((((((((( ((((((((( ((((:

    match 7 EFo5scrit5resultsG E FoututG b,neb FoututG bT.ob e(r cs:outut3 bThreeb 4 e(r cs:outut3 bourb 4 FoututG bi"eb

    '(( (((((( ((((((( (((((( (((( ((:

     Three our ,ne T.o i"e

    AO-TIN %ou cannot use FoututG or cs:outut34 !rom a commit scrit$ %ou can use these .ith e"ent scrits i!you also con*gure an outut *le in the e"ent olicy de*nition #ecause it al.ays signals a commit !ailure to

     Junos) .hich halts the re=uested commit$

     The cs:rint!34 !unction does not actually send a string to the console$ ather it creates a !ormatted string).hich can then #e outut to the console 3or *le) or other "aria#le) etc$4

    '(( ((((((((( (((( ((((((( (((( (((:((((((34 (( ((((((( ((( (( (((((( (((((( ((((((((((:

    match 7 E Fo5scrit5resultsG E

    7D islay the arameters D7 e(r cs:outut3 cs:rint!3 b16s 510sb) bParameterb) bRalueb 4 4 e(r cs:outut3 cs:rint!3 b16s 510sb) bZuserb) Zuser 4 4 e(r cs:outut3 cs:rint!3 b16s 510sb) bZhostnameb) Zhostname 4 4 e(r cs:outut3 cs:rint!3 b16s 510sb) bZscritb) Zscrit 4 4 e(r cs:outut3 cs:rint!3 b16s 510sb) bZlocaltimeb) Zlocaltime 4 4

    "ar Zstring cs:get5inut3 b-nter string: b 4 "ar Z.idth cs:get5inut3 b-nter .idth: b 4 "ar Zrecision cs:get5inut3 b-nterrecision: b 4 e(r cs:outut3 cs:rint!3 b[D$Ds[b) Z.idth) Zrecision) Zstring 4 4

    M,-K or details on the  cs:rint!34 !ormatting controls) lease re!er to the Aendi($

    singF(sl:messageG

    '(( F(((:(((((((G ((((((( (( (((( (( ((((((( (( ((((((((( ((((( ((((((($ '(( (((((((:

    F(sl:messageG bna#le to create connectionb

  • 8/16/2019 Copy Paste MasteringAutomation

    29/78

    ((((( ((((((( ((( ((((((((( ((((((( ((((((:

    error: na#le to create connection

    AO-TIN The error message is sent to the standard error 3ST-4 de"ice$ %ou should #e care!ul .henusing this element in commit scrits

    '(( ((((((( (( ((( F(((:(((((((G ((((((( (( (((( (( ((( (( (((( (( ((((((((((( ((((((((( ((( (((((($'((( (((((((( ( ((((((( (((((( (( xxxx  (( xxx  (((((((( (( ((((( ((((((((($ '( (( (((() ((((((( ((((((((((((@(((@ ((((((((($ '(( (((((((:

    F(sl:message terminatebyesbG b+o connection) a#orting scrit no.b

    singcs:rogress34

    '(( (((:((((((((34 ((((((( (( (((( ((( ((((((((( (((((((($ '((( ((( ((( (( ((((((( ((( ((( ((((((( ((((((( (((((($ '( ((( ((( ((( (((((( (((((() (((( ((( (((((( (((( (((:((((((((34 (( (((((((( (( ((((((((((( (((((($ '( ((( (( ((( ((((((( ((( (((((( (((((() (((( ((( (((:((((((((34 (((((( (( (((((((((((($ '( ((( (( (((( (((((((((((( ((((((() ((((((() ((( ((((((( ((( (((((( (( ((((((((((((((( (((( (((((((((( (( (( ((( (((((( (((((( (( (((($

    or e(amle:match 7 EFo5scrit5resultsG E FoututG b,neb FoututG bT.ob e(r cs:rogress3 bStarting cs:oututb 4 e(r cs:outut3 bThreeb 4 e(r

     cs:outut3 bourb 4 FoututG bi"eb

    '((( (((((((( ((( (((((( (((( ((( (((((( (((((((:

    user]unosG o test detail 201150\502 08:10:6Y TC: running o scrit &test$sla(& 201150\502 08:10:6Y TC: oening o scrit&7"ar7d#7scrits7o7test$sla(& 201150\502 08:10:6Y TC: reading o scrit &test$sla(& 201150\502 08:10:6Y TC: Starting cs:outut Threeour 201150\502 08:10:6Y TC: insecting o outut &test$sla(& ,ne T.o i"e 201150\502 08:10:6Y TC: *nished o scrit &test$sla(&

    singF(nm:.arningGandF(nm:errorG!orCommitScrits

    '(((( ((( ((((((( ((((((( (((( ((( ((((((((( (((((( (((( (((((( ((((((($

    '(( F(((:(((((((G ((((((( ((( (( (((( (( (((((( ( ((((((( ((((((() ((( (((((((:

    match con*guration E F(nm:.arningG E FmessageG bThis is a testb ((((( ((((((( ((( ((((((((( ((((((:

    user]unos commit .arning: This is a test con*guration check succeeds

    '(( F(((:(((((G ((((((( ((( (( (((( (( (((((( (( ((((( ((((((() ((( (((( ((((((( '(((( (( ((((((( (((((((((((( ((((((((((((( (((( (((((((( (((((($ '(( (((((((:

    match con*guration E F(nm:errorG E FmessageG bon&t let this commit succeedb .ould roduce the !ollo.ing outut:

    user]unos commit error: on&t let this commit succeed error: 1 error reorted #y commit scrits error: commit scrit !ailure

    +,T-N The F(nm:.arningG and F(nm:errorG elements are art o! the commit scrit result tree$ This meansthat your code can check !or the e(istence o! these .arning7errors$ or e(amle) i! you ha"e an o scritthat makes a con*guration change) your scrit should look !or the resence o! F(nm:errorG elements in theresult to determine i! the commit succeeded or !ailed$

    M,-K or additional in!ormation on commit scrits) lease re!er to This Wee! Applyin" Junos Automation at htt:77...$unier$net7dayone$

    Storage nut 7 ,utut

    eading!romiles

    '((( '(((( ((((((( ((( (((( ((( ((((( (((( ((((( (((( ((( ((((( (((( (((((($

    '(( (( ((( (((((((( (((( (( (((( (( ''' (((( (((( (( (((((( (( ((( ((((( (((( (((((( (( ((((( ((('''' ((((((((34 (((((((($ '(( ((((((((( ((((((( ((((((((((( ((( ((( (( ((((((((34:

    match 7 E Fo5scrit5resultsG E

    7D Ooad document into scrit D7 "ar Zchassis5in!o document3b7"ar7home7nr7chassis5in"entory$(mlb4

    7D

    0. etrie"e chassis name) use local5name34 !unction to a"oid

  • 8/16/2019 Copy Paste MasteringAutomation

    30/78

    1. dealing .ith namesaces D7

    "ar Zchassis Zchassis5in!o77D^local5name34 bchassisb_ "ar Zchassis5name Zchassis7D^local5name34 bnameb_

    FoututG bChassis name is b X Zchassis5name

    '( ((( (((( (( ((( ''') ((( ((( ((( ((( '(((( F((((5(((G ''' ((( ((((((( (((( (((( ((((( ( (((:(((((5(((((34 (((($ '((((( ((((( (( ( (((( (((( ((( ((((((((( ((((((((:

     Jones) Bo#) \6) Male Oee) Sandra) 92) emale Baker) Oee) 1) Male Oe.is) Alison) \9) emale

    '(( ((((((((( (((((( ((((( (((( (((( (((( ((( ((((((( (((( (((( (( (((($

    match 7 E Fo5scrit5resultsG E "ar Zrc F*le5getG EF*lenameG b7"ar7tm7eole$cs"b FencodingG basciib

    "ar Zeole cs:in"oke3 Zrc 4i!3 Zeole77sel!::(nm:error 4 E e(r cs:outut3 bna#le to oen *le: b) Zeole77sel!::(nm:error7message 4 F(sl:messageterminatebyesbG

    "ar ZeoleXdata cs:#reak5lines3 Zeole7*le5contents 4

    !or5each3 Zeole7D 4 E "ar Zline $ FoututG Zline

    '( ((( (((( ((( ((( ((((() ((( ((((((() ((( ((((((((( ((((( (( (((((((((:

    na#le to oen *le: ailed to oen *le 37"ar7tm7eole$cs"4: +o such *le or directory

    Writingtoiles

    '(((( ((( ( (((((( (( ((((((( ((((((((( (((( ((((((( (( ((((($ '( ((( ((( ((((((( ( ((( '''5((((((((() ((( ((((( ((( ((( '(((( F((((5(((G ''') ((( F((((:((((((((G ((((((() (( ((( F((((((((:(((((G ((((((($

    '(( ((((((( ((((((( (( ((((( F((((5(((G (( ((( ((( ((((((( ((( (((( ((((((((((( (((( ((((((( ((((((($ '(( ((((((( (((((((( (( ((((( F((((5(((G (( (((( ((( (((((( ((( (( (( ((((( ''' ((((((((($

    '(( ((((((((( ((((((( ((((((((( ((( (((((( ((((((( (( ((( ((((((((((((( (((( (( (((( 3((((((((((((((4 ((( (((((( (( (( ( ((((( (((($

    match 7 E Fo5scrit5resultsG E

    "ar Zsho.5con*g5system Fget5con*guration !ormatbte(tbG E Fcon*gurationG E FsystemG

    "ar Zcon*g cs:in"oke3 Zsho.5con*g5system 4

    "ar Z.riting F*le5utG E F*lenameGb7"ar7tm7system5con*g$t(tb FencodingG basciib FermissionG bY88b Fdelete5i!5e(istG F*le5contentsG Zcon*g

    "ar Zresult5.riting cs:in"oke3 Z.riting 4

    or .riting ASC *les or 'MO documents) you can use either o! the t.o e(tensionelements$'(( ((((((( ((((((( (( ((((( F((((:((((((((G (( ((( ((((((((((( (( ((((((( (((( (( (((((($ '(((((((((( (( (((( ((( (((((( ((((((( ((( ((((((((((( ((( ((( (((( ((((( (( ((( (( xxxxxx $

    '((( ((( ((( (((( ((((((() ((( (((( ((((((( ((( (((( ((((((((( ((( ((((((((( (((((((((( (( ((((( ((((( ((((((((( (((((((( (((((( (((((((:

    "ersion 1$0

    ns unos bhtt:77(ml$unier$net7unos7D7unosb ns (nm bhtt:77(ml$unier$net7(nm71$17(nmb ns cs bhtt:77(ml$unier$net7unos7commit5scrits71$0b ns e(sl e(tension bhtt:77e(slt$org7commonb

    imort b$$7imort7unos$(slb

    match 7 E Fo5scrit5resultsG E "ar Zrc Fget5chassis5in"entoryG E FdetailG

    "ar Zin"entory cs:in"oke3 Zrc 4

    Fe(sl:document hre!b7"ar7tm7in"entory$(mlbG E coy5o! Zin"entory

    M,-K or details on the Fe(sl:documentG element) lease re!er to htt:77...$e(slt$org7e(sl7elements7document7inde($html$

  • 8/16/2019 Copy Paste MasteringAutomation

    31/78

    '(( ((((((( ((((((( (( ((((( F((((((((:(((((G (( (((( ((( ((( (((((( (((( (( (( (((((((( (((( (( (('(((( 11$1$

    '(( (((((((( (( (((( ((( (((((( ((((((( ((( ((((((((((( ((( ((( (((( ((((( (( ((( (( xxxxxx $

    '((( ((( ((( (((( ((((((() ((( (((( ((((((( ((( (((((((( ((((((((( ((( ((((((((( (((((((((( (( ((((((( ((( ((((((((( (((((((( (((((( (((((((:

    "ersion 1$0

    ns unos bhtt:77(ml$unier$net7unos7D7unosb ns (nm bhtt:77(ml$unier$net7(nm71$17(nmb ns cs bhtt:77(ml$unier$net7unos7commit5scrits71$0b ns redirect e(tension borg$aache$(alan$(slt$e(tensions$edirectb

    imort b$$7imort7unos$(slb

    match 7 E Fo5scrit5resultsG E "ar Zrc Fget5chassis5in"entoryG E FdetailG

    "ar Zin"entory cs:in"oke3 Zrc 4

    Fredirect:.rite *leb7"ar7tm7in"entory$(mlbG E coy5o! Zin"entory M,-K or details on the Fredirect:.riteG element) lease re!er to htt:77(ml$aache$org7(alan5

     7e(tensionsli#$html$

    M,-KN or !urther in!ormation on using ile 7, in Junos scrit) lease re!er Chater \.

    WritingtotheSyslogile

    '(( '(((( ((((((( ((( ((((( (( ((( (((((( 37(((7(((7((((((((4 (((( ((((( ((( (((:((((((34 ((((((($ '(((((:((((((34 ((((((( (( ( (((((((( (((((((( ((((((( (((( ((( ((((( (((((((( ((((( (((((((((((7(((((((( ((((( (((((((((( ((( ((( ((((((((( (((((((((( ((((( ( ((((( ((((((((( (((( ((((((((( (( ((((((($ '(( (((((((:

    match 7 E Fo5scrit5resultsG E

    e(r cs:syslog3 be(ternal$in!ob) b-(amle syslog message: fbnsert message herefbb 4 e(r cs:syslog3 bdaemon$de#ugb) bThis messageis !rom b) Zscrit 4 e(r cs:syslog3 12) bThis is a b) buserffb) b.arning$b 4

    WritingtotheTraceotionsile'(( ((( ((((((((( '(((( (( (((((( (((((((((((( ((( (((( (( ((( ((((((((( (((((( ((((($ '(((((:(((((34 ((((((( ((((( ( (((((5((((((((( (((( (( ((((((( ((( (((((( (( ((( (((((((((((( (((($

    '(( ((((((() (( (((( '(((( ((((((((((((( (((((((( ((( (((((((((:

    user]unos sho. system scrits otraceotions E *le oscrits >ag inut >ag rc

    And your scrit included a call to cs:trace34) !or e(amle: e(r cs:trace3bThis is a traceotions

    message !rom scrit: b) Zscrit4

    '((( ((( ((((( ((( ((( ((((((( (((((( (( ((( (((( (((((((((:

    user]unoseremy]2\2051G sho. log oscrits Mar 8 0Y:\2:1\ 2\2051 clear5log^\112_: log*le cleared Mar 8 0Y:\2:18 comlete scritrocessing #egins Mar 8 0Y:\2:18 oening o scrit &7"ar7d#7scrits7o7test$sla(& Mar 8 0Y:\2:18 reading o scrit &test$sla(& Mar 80Y:\2:16 o scrit rocessing #egins Mar 8 0Y:\2:16 running o scrit &test$sla(& Mar 8 0Y:\2:16 oening o scrit&7"ar7d#7scrits7o7test$sla(& Mar 8 0Y:\2:16 reading o scrit &test$sla(& Mar 8 0Y:\2:16 This is a traceotions message !rom scrit:test$sla( Mar 8 0Y:\2:16 o scrit outut Mar 8 0Y:\2:16 #egin dum FK(ml "ersionb1$0bKG Fo5scrit5results(mlns:unosbhtt:77(ml$unier$net7unos7D7unosb (mlns:(nmbhtt:77(ml$ unier$net7(nm71$17(nmb(mlns:csbhtt:77(ml$unier$net7unos7commit5scrits71$0b7G Mar 8 0Y:\2:16 end dumMar 8 0Y:\2:16 insecting o outut &test$sla(& Mar 8 0Y:\2:16 *nished o scrit &test$sla(&

    ?ScratchPadMemory@

    '(((( ((((((( ((( (((( ((( ((((( ((((((((((( (((( ((( '(((( '(((((( '''$ '((( (( ( ((((( (((((((((((( ((((((( (((( ((((((( ((((((() (( (((( (( (((((( (((( (((((((((( ((( ''''5 ((((( ((((((((((((((((($

    '(( ((((((((( ((((( (( (((( ((( (( (((((( (( ((( '(((((( ''':0. String

    1. nteger

  • 8/16/2019 Copy Paste MasteringAutomation

    32/78

    2. nsigned nteger

    3. Counter

    4. CounterY8

    '((( ((( ((((( ( ((((( (( ( '(((((( ''') ((((( (( (((( ( ((((((((( (((((( (( (((( ((( ((((( ((( ((((

    ((((((($ '(( ((((((((( '(((( '''( ((( (((( (( ((((((( ((( '(((((( ''':

    0. Fre=uest5snm5utility5mi#5setGis used to create7set a MB "aria#le and udate the associatetimestam$

    1. Fget5snm5o#ectG is used to retrie"e the "alue o! any S+MP MB) inclusi"e o! tility MB"alues$

    2. Fre=uest5snm5utility5mi#5clearG is used to delete a tility MB "aria#le and its associatedtimestam "alue$

    AO-TI Ralues that are stored in the S+MP tility MB are local only to the routing5engine .here the scritis running$ %ou may need to take this into consideration .hen .riting scrits !or systems e=uied .ithredundant routing5engines$

    M,-KN Junos scrit e(amles !or using the tility MB can #e !ound Chater \.

    Summary

     This chater has co"ered the core SOA' rogramming language concets that are similar to other commonscriting languages$ %ou should e(eriment .ith the e(amles !rom this chater and get more !amiliar .iththe SOA' rogramming aradigm$ A!ter ust a #it o! ractice you .ill ha"e grased the !undamentals o!.riting Junos automation scrits$ The ne(t chater takes it u a notch) co"ering many ?tis and tricks@ as.ell as ad"anced toics that can hel you master your automation acti"ities$

    Chater \

    -ssential SOA' Toics to no.

    %undamental Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .?' %ile

    and Stora"e Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6& 4SS

    Inte"ration Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .+3 @vent 

    Script Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .('+

    Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .(&'

    '((( ((((((( (((((( ((((((( (((((( (((( ((( (((( (( (((( (( (( (((((((((( ((( (((((((( (((( '(((((((((((((( ((((((((($ '(( (((( (( (((( ((((( ((( (((((((( (((( (((( ((((((( (((( (((( (((( ((((

  • 8/16/2019 Copy Paste MasteringAutomation

    33/78

    ((((( (((( ((((( (((( (((( ((( ((((((( (((( (((( ((((( (((( (((((((((:

    0. undamentals

    1. ile and storage

    2. ,SS integration

    3. -"ent ScritWrite notes in the margins) use the on5screen highlighter in Acro#at) or try the eBook tools in your eBookreader j do .hate"er .orks #est to make notes a#out the many essential SOA' !eatures and kno#s thatcan make Junos sing$

    undamental Toics

    irst) lets co"er some !undamental SOA' toics that you .ill use as a !oundation !or !uture scriting$ Theyinclude searching !or error elements) learning comle( 'Path e(ressions) using custom !unctions) learningall you can a#out the cs: !unctions) and dislaying outut !rom Junos commands$

    Searching!or-rror-lements3F(nm:errorG4

    FarentG E FchildG ?te(t@

    7 E FarentG E FchildG ?te(t@ '(( F(((:(((((G ((((((( (( (((((((( (( '(((( (( (((((((( (((( (( ((((( (((((((($ '( (( ((((((((( ((((((( ((( (((( ((((((( (((((((( ((( ((((((((( (( ( (((((( ((((( (((((( (( (( ((((( ((( ((( (((((((( (((((((( (( ((((( (( (($ '(( ((((((() ((((((( (( (( (( ((((( (((((( (((((((( ( (((((() (( (((((((( ((((( (( (((((( ((( ((((((( ((((((((( (((((() (((( (( ( (((((((( ((((((( ((((() ( ((((((((((((((((( ((((() (( ((( (((( (( (((((( ((((($

    '((((( (((( (((( (( ((((( (((( (((((((( ((( (((((((( (((( (( (((((( (((( (((( (( ((((( (((((( (( (((((((((( ((((((((($ '(( F(((:(((((G ((((((( (( (( ( ((((((((( (((((((( (((((((( (( ((( ((((5((((((((((() ((((((((( (( ((((((( (((( (((((((( (( ( ((((((((( (((((( (((( (((((((( (( ((( (((((((( ((( ((((5((($

     The di

  • 8/16/2019 Copy Paste MasteringAutomation

    34/78

    user]unosnr]sr(210G sho. "ersion [ dislay (ml Frc5rely (mlns:unos@htt:77(ml$unier$net7unos710$807unos@GFso!t.are5in!ormationG Fhost5nameGsr(210F7host5nameG Froduct5modelGsr(210hF7roduct5modelG Froduct5nameGsr(210hF7roduct5nameG Fsr7G Fackage5in!ormationGFnameGunosF7nameG FcommentGJ+,S So!t.are elease ^10$85201001Xi#8X11X1$0_F7commentG F7ackage5in!ormationGF7so!t.are5in!ormationGFcliG F#annerGF7#annerG

    F7cliG F7rc5relyG

    '(( ((((5((( (((((((( (( (((((((( (( (((F(((5((((((((5(((((((((((G

     ''' ((((((( ((( ((((( (((( ((((((( (((( (( F((((((((5(((((((((((G$ '(( (((( (((( ((((((K '(((((( (((( ((((5((( ((((( ((((((( (( ( 7(((() ((((( (( ( (((((( (( ((( F(((:(((((G ((((:

    7 E F(nm:errorG E FmessageG ?cs:load5con*guration called .ith in"alid arameters@

    '() ((( (((( ((((( (( ((( (((((( F(((:(((((G ((((:

    F(nm:errorG E FtokenG ?This5s5The5Bad5AP5-lement55sed@ FmessageG ?synta( error@

    '() ((( (((( ((((( (( (( ((((((( (((() ((((( (( ( (((((( (( (((((((( (( ((( F(((:(((((G ((((:

    Fcommit5resultsG EFrouting5engine unos:stylenormalG E FnameG ?re0@ F(nm:errorG E

    FmessageG ?fnssh is not ena#ledfn@ F(nm:errorG EFmessageG ?fn1 error reorted #y commit scritsfn@ F(nm:errorG E

    FmessageG ?fncommit scrit !ailurefn@

    '(( ((((( ((((( ((((((( (( ((( (((((( (( (( ((((((( (((( (( ((( (((:((((5(((((((((((((34 (((((((($ '(((((((( ((((( ((((((( ((( ((((((((( (( ((((((( (( ((((((( ''' ((((((( (( (((:((((((34$ '(( ((( (((((((((( ((((((( ((( ((((((((( (( (((((((((( (( ((((((( ( (((((( ((( (((:(((((((34 (((( (((((((( (( ((((((( ((((((($'((((((((''(((((''(((''((((((((

    '(( (((:((((5(((((((((((((34 (((((((( (( ( (((((( (((((( (( (((((( (((( ((((((((( (((( (((( (( (( ((((((((( F(((:(((((G (((((((($ '( ((( Z((((((( (((((((( (((((((( ((( (((((( (( (((:((((5(((((((((((((34(((( (((((((((((( (((((((( (((( ((( (( (((( (( (((((( ( F(((:(((((G (((((( ((( Z((((((( ((((((((:

    Zresults77(nm:error

    '(( 77 (( ( (((((((( ((( 7((((((((((5((5((((::((((347) ((( ((( ((((((( (((( (( ((( ((((( (((() (( ((( (((((((((((( (((( (( ((((((((:

    Zresults7descendant5or5sel!::node347child::(nm:error

     This location ath .orks great !or con"erted result tree !ragments #ecause the node5sets conte(t node isal.ays the root node o! the 'MO document) so any nodes o! interest are al.ays children o! the node ratherthan the node itsel!$

    '(((5((((

    '(((( Z(((((((77(((:((((( (((( ((( (((((( (((( (((( ((((5(((() ((((((() ((((((( F(((:(((((G (( ((((( ((((((((( ((((5(((( ((((((( (((($ '(( Z(((((((77(((:((((( (((((((( (((( (((( ((((( (( F(((:(((((G (( (((((((( (( ((( ((((((( (((() ((( (( (( (( ((( ((((((( (((( (((((($ '(((((((( (((((( (((( (((((((((((( (((((( ((( (( ((( (((( (((() ((( (((((((( ((((5(((( ((( ((( (( (( (((((( ((((((( (((($ '(((((((( (((() ((( ((((((((( (( (((( (((( (( ((( ((((((( ((((( (((((( (((((( (((((((((( (( ((( ((( 77 (((((((( (((( ((((((((:

    Z(((((((7$$77(((:(((((

     The $$ oerator is short !or arent::node34) so the !ull ath is actually:

    Zresults7arent::node347descendant5or5sel!::node347child::(nm:error

     This .orks .hether the F(nm:errorG message is the conte(t node or a descendant o! the conte(t node) so itis aroriate to use .ith a node5set "aria#le ho.e"er) it doesnt .ork .ith a con"erted result tree!ragment #ecause there is no arent o! the root node so the arent::node34 in the ath results in an emtyresult$

    '''(((((((''((('(((''((''((((

    ' (((((((( (((( (((( ((((( ((( ((( ((((((((( (((((( (((( (((((((((:

    Zresults77(nm:error

    And this .orks !or returned node5sets:

    Zresults7$$77(nm:error

  • 8/16/2019 Copy Paste MasteringAutomation

    35/78

    '(( (((( ((((( ( (((((((( (((( (((( ((((( (( (((( ((( ((((K '((((((() ((((( (($ '((((( (((( (((((((((( (((( ((((( ((( 77 (((((((( (( (((( ((( ((((((( (((( (( ((( ((((( (((($ '((( ((((((((( (((((( ((((( ((( 77 (((( ( ((((5((( ((((((( ((( F(((:(((((G ((((( (( ((( ((((((( (((( (((((( (((( (((((((( (( ((( ((((((( (((() ((( ((((( ((( (((( (((( (((((( (((( ((( ((((( (((( (((((( (((( ((((((($

    '(( ((((((((( (((((((( (((( ((((( ((( (((( ((((((((( (((((( (((( ((((((((( (( (((( (( ((((((((((((5(((() ((((((( ((( F(((:(((((G (((( (( ((( ((((((( (((( (( (((:

    Zresults77sel!::(nm:error'(( (((( (( (( ((((((((:

    Zresults7descendant5or5sel!::node347sel!::(nm:error

     This location ath al.ays .orks #ecause the descendant5or5sel! a(is returns all nodes that are either theconte(t node or its descendants) and the sel! a(is returns the current conte(t node$ So .hether F(nm:errorG is the conte(t node) or is a descendant) it .ill #e selected) making this location ath ideal to use .hensearching !or a F(nm::errorG element in your scrit results$

    Comle('Path-(ressions

    or the *rst e(amle) the goal is to retrie"e the Finter!aceG nodes o! all inter!aces .ith names that #egin.ith e and that do not ha"e a logical unit 100$

    '((((((((''((((('(''((((((((

    '(( (((( ((((((((((( (( (((( (( (((((((((( ((((((( ((( ((( (( ( (((((((( (((((((((:

    Zcon*guration7inter!aces7inter!ace^ starts5.ith3 name) ?!e@ 4 _

    '(((((() ((( (((((( ((((((((((( (((((((( ( (((( (((((((( (((((($ '(( ((((((( (((( (( (((( ((((( ((F(((((((((G) (( ((( ((((((((( (( (( (((((( ( ((((((( (((((((((( (((( (((( (((((( (((( (( ((((( ((( ((((((( F((((G ((((( (((( (((( ( F((((G (( 100$ '((( ((( (( (((((((( (( ((((( ((( (((:(((((34 (((((((()((( ((( (((((((( ((( (((( (((((((( (( ( (((((((( (((() ((( (((( (((((((( (((( (((((( (((((((( (((((((((() ((((( (((((((( ((( (((((((( ((((((( (( ( (((((((( (((( (((( (((( ( ((((((((( (((((( ((((((((((:

    Zcon*guration7inter!aces7inter!ace^starts5.ith3name) ?!e@4_^cs:emty3unit^name ?100@_4_

     This location ath is rocessed #y *rst looking !or any Finter!acesG child nodes) then looking !or anyFinter!aceG child nodes$ The Finter!aceG nodes are su#ected to t.o redicates$ irst) their FnameG c