Automation

last person joined: 3 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  Support for Arrays?

    Posted 01-04-2011 11:02

    I didn't see any mention for support of arrays in the Day One Booklets. Does the slax language support the use of arrays or hash tables?

     

    For example, I'd like to reduce the litany of interface checks to a comparison of an array of interfaces:

    Pseudo-code:

    @arrayOfInterfaces = "xe-1/0/0", "so-0/0/0", etc...

    foreach $int of @arrayOfInterfaces

       if /interface/$int/disabled

           then error;

     

     

     



  • 2.  RE: Support for Arrays?
    Best Answer

    Posted 01-05-2011 07:21

    No arrays, but you can use node-sets in a similar way:

     

    var $array-interfaces := {

        <interface> "xe-1/0/0";

        <interface> "so-0/0/0";

    }

     

    for-each( $array-interfaces/interface ) {

        <output> "Name is " _ .;

    }

     

    You can even reference them using [1], [2], etc (counting starts at 1):

     

    var $first-interface = $array-interfaces/interface[1];

     

    But be careful using a variable as the index value because it might be stored as a string value, even if it has numeric content, so always cast it to a number just in case:

     

    var $interface = $array-interfaces/interface[ number( $index ) ];

     



  • 3.  RE: Support for Arrays?

    Posted 01-10-2011 10:38

    Thanks!



  • 4.  RE: Support for Arrays?

    Posted 11-08-2012 20:19

    How might we get some information about the set?  For instance, the last index available?  In the example below, it should be 2 (because it starts with 1, and there are 2), but what if the node-set could have any number of elements, and we wanted to see the 'last' element?



  • 5.  RE: Support for Arrays?

    Posted 11-09-2012 05:46

    count( $set ) returns the number of nodes in a node-set. Another option is last() which returns the current context size. So, using the latter, you could do this:

     

    $node-set[ last() ]

     

    and it should return the last node.