Friday, April 18, 2014

Junos Scripting - Is it possible to pass multiple values as part of the same argument?

For example, assume I want to check something only on certain interfaces.  Can I say something like:
op check-intf <argument> [ ge-0/0/0 ge-0/0/1 ge-0/0/2 ]

 If possible, I assume this would be passed as an array.  If so, what is the syntax to for-each over each element?

you should be able to enclose the multiple values in quotes to make a single string.  You could use jcs:split( " ", $argument ) to separate out the different values from the combined string.

jnpr@EX4200-VC1# run op parse objects "ge-1/0/0 ge-1/1/0 ge-1/2/0" 
field: ge-1/0/0
field: ge-1/1/0
field: ge-1/2/0


version 1.0;
ns junos = "*/junos";
ns xnm = "";
ns jcs = "";
import "../import/junos.xsl";
var $arguments = {
            expr $objects;
    <argument> {
       <name> "objects";
       <description> "enter objects";
param $objects;
match / {
    <op-script-results> {
        <output method = "text"> {
            var $field = jcs:split(' ', $objects);        

            for-each ($field) {

               expr "field: " _ . _ "\n";    

No comments:

Post a Comment