Automation

last person joined: yesterday 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
Expand all | Collapse all

SLAX changes JunOS 15.1

  • 1.  SLAX changes JunOS 15.1

    Posted 03-08-2017 05:32

    Hi all,

     

    are there any changes in Version 15.1 or am I doing something wrong?

     

    We run some SLAX-Scripts on our EX2200 for staging (14.1Xsomething).

    The same Script fails badly on our new EX2300 (15.1X53-D55)

     

    For example the function to get the s/n:

     

    <func:function name="ztp:serial-number">
    {
    param $jnx;

    var $cmd = <get-chassis-inventory> { <models>; }
    var $sn = jcs:execute( $jnx, $cmd )//chassis-module/serial-number;

    <func:result select="$sn">;
    }

     

    Are there any changes?

     



  • 2.  RE: SLAX changes JunOS 15.1

    Posted 03-08-2017 07:52

    It's more likely that something changed in the XML response you're getting in $sn.  

    But it's impossible to tell without seeing what the actual error is.

     

    Try dumping $sn and see if what you're loooking for is still ther.   E.g. insert "copy-of $sn;" in the script

    and re-run, piping thru "| display xml"

     

    /doug

     



  • 3.  RE: SLAX changes JunOS 15.1

    Posted 03-09-2017 00:56

    Hi Doug,

     

    the Value ($sn) is empty - so are all my other variables - that's why I ask.

     

    In Version 11,12,13, 14 and 15 with the EX2200, 2200-C, 3300 and 4200 the Script runs fine.

    On the EX2300 for Example (minimum Version is 15) the Script fails - all values are empty - so I think Juniper changed something fundamental regarding the XML response.

     

    Can someone from Juniper please verify this?



  • 4.  RE: SLAX changes JunOS 15.1

     
    Posted 03-09-2017 02:38

    Hi Chris,

     

    What data do you get returned from the cli with

    show chassis hardware | display xml

    The above command should return the same data that you would get from the RPC <get-chassis-inventory> as can be seen from the command:

    show chassis hardware | display xml rpc
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/15.1R4/junos">
        <rpc>
            <get-chassis-inventory>
            </get-chassis-inventory>
        </rpc>
        <cli>
            <banner>{master:0}</banner>
        </cli>
    </rpc-reply>

    Also, what data is returned via NETCONF e.g.

    # ssh netadmin@x.x.x.x -s netconf
    Password:
    <!-- No zombies were killed during the creation of this user interface -->
    <!-- user netadmin, class j-SUPERUSER -->
    <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
      <capabilities>
        <capability>urn:ietf:params:netconf:base:1.0</capability>
        <capability>urn:ietf:params:netconf:capability:candidate:1.0</capability>
        <capability>urn:ietf:params:netconf:capability:confirmed-commit:1.0</capability>
        <capability>urn:ietf:params:netconf:capability:validate:1.0</capability>
        <capability>urn:ietf:params:netconf:capability:url:1.0?scheme=http,ftp,file</capability>
        <capability>urn:ietf:params:xml:ns:netconf:base:1.0</capability>
        <capability>urn:ietf:params:xml:ns:netconf:capability:candidate:1.0</capability>
        <capability>urn:ietf:params:xml:ns:netconf:capability:confirmed-commit:1.0</capability>
        <capability>urn:ietf:params:xml:ns:netconf:capability:validate:1.0</capability>
        <capability>urn:ietf:params:xml:ns:netconf:capability:url:1.0?protocol=http,ftp,file</capability>
        <capability>http://xml.juniper.net/netconf/junos/1.0</capability>
        <capability>http://xml.juniper.net/dmi/system/1.0</capability>
      </capabilities>
      <session-id>4230</session-id>
    </hello>
    ]]>]]>
    <rpc><get-chassis-inventory/></rpc>
    .
    .
    .
    .
    .
    <rpc><close-session/></rpc>
    <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/15.1R4/junos">
    <ok/>
    </rpc-reply>
    ]]>]]>
    <!-- session end at 2017-03-09 10:37:14 UTC -->

    Regards,

    Andy



  • 5.  RE: SLAX changes JunOS 15.1

    Posted 03-13-2017 04:03

    Hi Andy,

     

    I am getting this:

     

    root@switch> show chassis hardware | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/15.1X53/junos">
        <chassis-inventory xmlns="http://xml.juniper.net/junos/15.1X53/junos-chassis">
            <chassis junos:style="inventory">
                <name>Chassis</name>
                <serial-number>JW0217040079</serial-number>
                <description>EX2300-48P</description>
                <chassis-module>
                    <name>Pseudo CB 0</name>
                </chassis-module>
                <chassis-module>
                    <name>Routing Engine 0</name>
                    <part-number>BUILTIN</part-number>
                    <serial-number>BUILTIN</serial-number>
                    <description>RE-EX2300-48P</description>
                    <clei-code>CMMU900ARA</clei-code>
                    <model-number>EX2300-48P</model-number>
                </chassis-module>
                <chassis-module>
                    <name>FPC 0</name>
                    <version>REV 09</version>
                    <part-number>650-059961</part-number>
                    <serial-number>JW0217040079</serial-number>
                    <description>EX2300-48P</description>
                    <clei-code>CMMU900ARA</clei-code>
                    <model-number>EX2300-48P</model-number>
                    <chassis-sub-module>
                        <name>CPU</name>
                        <part-number>BUILTIN</part-number>
                        <serial-number>BUILTIN</serial-number>
                        <description>FPC CPU</description>
                    </chassis-sub-module>
                    <chassis-sub-module>
                        <name>PIC 0</name>
                        <version>REV 09</version>
                        <part-number>BUILTIN</part-number>
                        <serial-number>BUILTIN</serial-number>
                        <description>48x10/100/1000 Base-T</description>
                        <clei-code>CMMU900ARA</clei-code>
                        <model-number>EX2300-48P</model-number>
                    </chassis-sub-module>
                    <chassis-sub-module>
                        <name>PIC 1</name>
                        <version>REV 09</version>
                        <part-number>650-059961</part-number>
                        <serial-number>JW0217040079</serial-number>
                        <description>4x10G SFP/SFP+</description>
                        <clei-code>CMMU900ARA</clei-code>
                        <model-number>EX2300-48P</model-number>
                    </chassis-sub-module>
                </chassis-module>
                <chassis-module>
                    <name>Power Supply 0</name>
                    <description>JPSU-850W-AC-AFO</description>
                </chassis-module>
                <chassis-module>
                    <name>Fan Tray 0</name>
                    <description>Fan Module, Airflow Out (AFO)</description>
                </chassis-module>
                <chassis-module>
                    <name>Fan Tray 1</name>
                    <description>Fan Module, Airflow Out (AFO)</description>
                </chassis-module>
            </chassis>
        </chassis-inventory>
        <cli>
            <banner>{master:0}</banner>
        </cli>
    </rpc-reply>
    

     

     

     

    My Script tries this:

     

    <func:function name="ztp:hardware-type">
    {
       param $jnx;
       
       var $cmd = <get-chassis-inventory> {  <models>; }
       var $model-full = jcs:execute( $jnx, $cmd )//chassis-module/model-number;
       var $model = jcs:split("-", $model-full);
       
       <func:result select="$model[1]">;
    }




    <func:function name="ztp:serial-number"> { param $jnx; var $cmd = <get-chassis-inventory> { <models>; } var $sn = jcs:execute( $jnx, $cmd )//chassis-module/serial-number; <func:result select="$sn">; }

     

    I'm very new to SLAX - learning every day - simply amazing what SLAX can do πŸ˜„

     

    Regards

    Chris



  • 6.  RE: SLAX changes JunOS 15.1

     
    Posted 03-13-2017 04:45

    Thanks Chris,

     

    Give me a little while to take this all in, and I'll try to get back to you later today.

     

    Regards,

    Andy



  • 7.  RE: SLAX changes JunOS 15.1

    Posted 03-13-2017 07:08

    Hi Andy,

    that would be awesome - thank you very much for your help πŸ™‚

     

     



  • 8.  RE: SLAX changes JunOS 15.1

    Posted 03-13-2017 08:47

    The problem appears to be with the output of the  "show chassis hardware models" command -- which is the same as the rpc your script is using (the line <get-chassis-inventory> { models }; "

     

    Look at what i get when I type "show chassis hardware models on a VMX running 15.1:

     

    regress@PE1_RE0> show chassis hardware models
    
    regress@PE1_RE0>
    

    If you want to know why your XML is empty, "there's your problem".  See below for the "fruitless" xml:

    regress@PE1_RE0> 
    
    regress@PE1_RE0> show chassis hardware models | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/15.1D0/junos">
        <chassis-inventory xmlns="http://xml.juniper.net/junos/15.1D0/junos-chassis">
            <chassis junos:style="model-inventory">
                <chassis-module>
                </chassis-module>
                <chassis-module>
                </chassis-module>
                <chassis-module>
                </chassis-module>
                <chassis-module>
                </chassis-module>
            </chassis>
        </chassis-inventory>
        <cli>
            <banner></banner>
        </cli>
    </rpc-reply>
    
    regress@PE1_RE0>

     

    Do you just need the chassis serial number ?     Or something else ?  

     

    /doug



  • 9.  RE: SLAX changes JunOS 15.1

    Posted 03-13-2017 09:04

    Hi Doug,

     

    root@switch> show chassis hardware models | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/15.1X53/junos">
        <xnm:error xmlns="http://xml.juniper.net/xnm/1.1/xnm" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm">
            <message>
                command is not valid on the ex2300-48p
            </message>
        </xnm:error>
        <cli>
            <banner>{master:0}</banner>
        </cli>
    </rpc-reply>
    

    On the EX2200 the Script worked like a charm - don't know why the output was changed - but i guessed something like this.

     

    I need the Serial-Number and the Model (like 2300-24P).

    The Script gets the 2300 part from the 2300-24P to lookup what software to use and gets the S/N to lookup what config to apply.

     

    root@switch> show chassis hardware | display xml
    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/15.1X53/junos">
        <chassis-inventory xmlns="http://xml.juniper.net/junos/15.1X53/junos-chassis">
            <chassis junos:style="inventory">
                <name>Chassis</name>
                <serial-number>JW0217040079</serial-number>
                <description>EX2300-48P</description>
                <chassis-module>
                    <name>Pseudo CB 0</name>
                </chassis-module>
                <chassis-module>
                    <name>Routing Engine 0</name>
                    <part-number>BUILTIN</part-number>
                    <serial-number>BUILTIN</serial-number>
                    <description>RE-EX2300-48P</description>
                    <clei-code>CMMU900ARA</clei-code>
                    <model-number>EX2300-48P</model-number>
                </chassis-module>
                <chassis-module>
                    <name>FPC 0</name>
                    <version>REV 09</version>
                    <part-number>650-059961</part-number>
                    <serial-number>JW0217040079</serial-number>
                    <description>EX2300-48P</description>
                    <clei-code>CMMU900ARA</clei-code>
                    <model-number>EX2300-48P</model-number>
                    <chassis-sub-module>
                        <name>CPU</name>
                        <part-number>BUILTIN</part-number>
                        <serial-number>BUILTIN</serial-number>
                        <description>FPC CPU</description>
                    </chassis-sub-module>
                    <chassis-sub-module>
                        <name>PIC 0</name>
                        <version>REV 09</version>
                        <part-number>BUILTIN</part-number>
                        <serial-number>BUILTIN</serial-number>
                        <description>48x10/100/1000 Base-T</description>
                        <clei-code>CMMU900ARA</clei-code>
                        <model-number>EX2300-48P</model-number>
                    </chassis-sub-module>
                    <chassis-sub-module>
                        <name>PIC 1</name>
                        <version>REV 09</version>
                        <part-number>650-059961</part-number>
                        <serial-number>JW0217040079</serial-number>
                        <description>4x10G SFP/SFP+</description>
                        <clei-code>CMMU900ARA</clei-code>
                        <model-number>EX2300-48P</model-number>
                    </chassis-sub-module>
                </chassis-module>
                <chassis-module>
                    <name>Power Supply 0</name>
                    <description>JPSU-850W-AC-AFO</description>
                </chassis-module>
                <chassis-module>
                    <name>Fan Tray 0</name>
                    <description>Fan Module, Airflow Out (AFO)</description>
                </chassis-module>
                <chassis-module>
                    <name>Fan Tray 1</name>
                    <description>Fan Module, Airflow Out (AFO)</description>
                </chassis-module>
            </chassis>
        </chassis-inventory>
        <cli>
            <banner>{master:0}</banner>
        </cli>
    </rpc-reply>
    

     



  • 10.  RE: SLAX changes JunOS 15.1

    Posted 03-13-2017 09:23

    So it looks like you could get serial-number if you change the

    var $cmd = <get-chassis-inventory> {  <models>; }

    to

    var $cmd = <get-chassis-inventory>;

    in the function ztp:serial-number.    That will stop the error message and actually return some xml output.

     

    The question is, will that be backward-compatible with 14.x or do you need to check Junos version before doing the needful.

     

    re: 'hardware-type'  the info you're looking as <model-number> in function ztp:hardware-type  for *appears* to be kept in <description>.  (I say this based on your previously posted XML output.)   Is that right ?

    If so, then try modifying that function ztp:hardware-type to replace the line

    /var $model-full = jcs:execute( $jnx, $cmd )//chassis-module/model-number; 
    

    with the line

    /var $model-full = jcs:execute( $jnx, $cmd )//chassis-module/description; 

    ...and see if that works.

     

    Same caveat re: backward compatibility applies.

     

    Try that and report back here.

     

    BTW: where do you come by this script ?   Was it written in-house?  Provided by someone at Juniper ?

    /doug

     

     



  • 11.  RE: SLAX changes JunOS 15.1

    Posted 03-13-2017 09:41

    I tried your solution - however changing the line to 

    /var $model-full = jcs:execute( $jnx, $cmd )//chassis-module/description; 

    will report "BUILTIN" as Device-Model - S/N is still empty 😞

     

    BTW: where do you come by this script ?   Was it written in-house?  Provided by someone at Juniper ?

     

    This Script is like Frankenstein - it's made out of 3 sources (Internet, Juniper-intern and a Blog) and I also tweaked it a lot myself to work properly and stable (at the beginning all scripts were a little messy and unreliable so I "fused" them and made them stable) and of course to fit our environment. With the "old-Switches" this is now rock-stable and reliable and helped us reduce the time to stage a Switch dramatically πŸ™‚ It's like every Program - you start small, add more and more and suddenly it could replace you - at least at some point πŸ˜„ πŸ˜„ πŸ˜„



  • 12.  RE: SLAX changes JunOS 15.1
    Best Answer

    Posted 03-13-2017 10:37

    re: Frankenstein  

    If you recall, it didn't end well for Dr. Frankenstien _or_ his creation....

    Just sayin. πŸ˜‰

     

    Some advice

    1. If you know exactly in the XML response where you need to look, then use a more precise xpath expression and don't use the // shortcut.  Your code has a syntactically correct, but non-obvious use of //

     

    2.  When you execute an RPC, check for errors/warnings.  The code you're using expects everthing always works, and doesn't report when that's not the case. 

     

    To that end, noodle on this and see if you can  get it working. 

     

    <func:function name="ztp:hardware-type">
    {
       param $jnx;
       var $cmd = <get-chassis-inventory2>;
       var $res = jcs:execute( $jnx, $cmd );
       var $model-full = $res/chassis/description; 
       var $model = jcs:split("-", $model-full);
       <func:result select="$model[1]">;
    }
    
    

    This DOES NOT include any error checks. To do that in the above, you'd want to see if $res//xnm:error exists after the jcs:execute.   If it does, then something went wrong. I think this would've caught that you were asking for a (newly?) unsupported option on the <get-chassis-information> rpc, with the "models" arg.

     

     

    HTH

    /doug

     

     

     

    Again: if you get this working w/15.1 and find it's broken for 14.* then you'll need to do a version check *first* then invoke the correct version-specific function.

     

    /doug



  • 13.  RE: SLAX changes JunOS 15.1

    Posted 04-04-2017 01:23

    Hi Doug,

     

    holy moly - it works πŸ˜„ πŸ˜„ πŸ˜„

     


    /* ------------------------------------------------- */
    /* this function is used get hardware type */
    /* ------------------------------------------------- */
    <func:function name="ztp:hardware-type">
    {
    param $jnx;
    var $cmd = <get-chassis-inventory>;
    var $res = jcs:execute( $jnx, $cmd );
    var $model-full = $res/chassis/description;
    var $model = jcs:split("-", $model-full);
    <func:result select="$model[1]">;
    }

    /* ------------------------------------------------- */
    /* this function is used get serial number */
    /* ------------------------------------------------- */
    <func:function name="ztp:serial-number">
    {
    param $jnx;
    var $cmd = <get-chassis-inventory>;
    var $res = jcs:execute( $jnx, $cmd );
    var $model-full = $res/chassis/serial-number;
    <func:result select="$model-full[1]">;
    }

     

     

    Now getting everything from the new-Devices and the old-Devices regardless of the Version (tested 12.3 through 16.1) - works like a charm πŸ™‚

    Thank you very much for all your help - let's hope Frankenstein will survive - this time as Frankenstein 2.0 πŸ˜›



  • 14.  RE: SLAX changes JunOS 15.1

    Posted 04-04-2017 07:56

    Excellent!  

    Happy that I could help and glad it worked out for you.

    Best of luck with "your creation".  πŸ˜‰

    /doug