Automation

last person joined: 4 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  JUNOSCRIPT/Slax: how to use a variable in a node

    Posted 11-21-2009 09:26

    I'm trying to get the value of a set policer depending on what encapsulation is set on a unit.  Since family inet has not encapsulation set, I've used the if clause below to set family to 'inet' if no encapsulation is set.  This works well.

     

            var $family = {
               if ($top/interfaces/interface[name == $phyifname]/unit[name == $unit]/encapsulation) {
                 expr $top/interfaces/interface[name == $phyifname]/unit[name == $unit]/encapsulation;
               } else {
                 expr "inet";
               }
            }
            var $policer_in = $top/interfaces/interface[name == $phyifname]/unit[name == $unit]/family[name == $family]/policer/input;
            var $policer_out = $top/interfaces/interface[name == $phyifname]/unit[name == $unit]/family[name == $family]/policer/output;

    The problem comes in the last two lines.  The 'family[name == $family]' doesn't work as I'd expect.  I believe this is because family xxx is its own node (whats the right term for this?), as opposed to a node that expects an argument (ie, name in slax)

     

     

    Can someone set me in the right direction on this?



  • 2.  RE: JUNOSCRIPT/Slax: how to use a variable in a node
    Best Answer

    Posted 11-21-2009 14:33

    You can check the name of the context node by using the name() function.

     

    So something like this might be what you are looking for:

     

    var $policer_in = $top/interfaces/interface[name == $phyifname]/unit[name == $unit]/family/*[name() == $family]/policer/input;



  • 3.  RE: JUNOSCRIPT/Slax: how to use a variable in a node

    Posted 11-21-2009 17:17

    That worked nicely.  What is the * for before [name()... ?

     



  • 4.  RE: JUNOSCRIPT/Slax: how to use a variable in a node

    Posted 11-21-2009 17:23

    * is the wildcard that matches all nodes for the given axis.  The default axis is child, so the * in that location path matches all child nodes of <family> and then the predicate [ ] narrows them down to only child nodes with the same name as the $family variable.