Junos Automation (Scripting)
Junos Automation (Scripting)

JUISE and jcs:grep problems.

[ Edited ]
‎05-20-2013 07:58 PM

This is a 2 part question:

 

1)

I have an entire op script running perfectly on-box and I have been trying to migrate this off-box and running using JUISE but I have had nothing but problems, so I decided to take one line at the time, move over and execute the script at that point to find out the results. 

 

I found out for example that JUISE would not interprete well a simple <output> command like all my on-box scripts, apparently I had to use "expr jcs: output".

 

Is there somewhere a doc that shows how to migrate perfectly running op scripts off-box running JUISE? I am so frustrated because I feel like nothing I have done in on-box scripts works now if I try to move them out of box.

 

2)

See the EXAMPLE CODE below. This is a snipet of the code that I am migrating, and I got stuck in the use of jcs:grep when declaring the var $lines.  That line as is works fine in the router, but not with JUISE. 

Up until that point if I remove that line the program although not very functional, it works!  I guess that getting guidance on question 1 will help me answer question 2.

 

 

 

EXAMPLE CODE:

 

version 1.0;
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";

import "../import/junos.xsl";

var $arguments={
<argument> {
<name> "item";
<description> "Item being looked for";
}
}

param $item = '';
param $TARGET = "";
param $USER = "";
param $PASSWD = "";


match / {

expr jcs: output ("Connecting ", $USER, "@", $TARGET, "...");
var $jnx = jcs: open( $TARGET, $USER, $PASSWD);
if (not( $jnx )) {
<xsl:message terminate ="yes">"Connection failed please review connection parameters.";
}
expr jcs: output("connected.");


expr jcs: output( "LOADED Dev CONFIG");

if ($item = '') {
<xnm:error> {
<message> "missing mandatory argument 'item'";
}
}

var $pattern = translate($item, "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
var $filename = "/Users/asdfweagasdf/Automation/test.csv";
expr jcs: output ("This is the name of the file:" _ $filename);

var $lines := { call jcs:grep($filename, $pattern); }

expr jcs:close( $jnx );
expr jcs: output("disconnected.");

}

4 REPLIES 4
Junos Automation (Scripting)

Re: JUISE and jcs:grep problems.

[ Edited ]
‎07-01-2013 07:07 PM

I encountered a very similar problem today. My script worked fine on the router but failed when invoked using juise.

 

jeffl@ubuntu:~/development/jeff-slax$ juise @5.1.0.1 show_multicast_route_NGIM.slax
xmlXPathCompiledEval: evaluation failed
runtime error: file show_multicast_route_NGIM.slax line 42 element variable
Failed to evaluate the expression of variable 'resultsShowPIMJoin'.

 

In my case, it appears that juise doesn't like mixing jcs:execute and jcs:invoke. I converted to all jcs:execute calls and juise began running the script without errors again.

Junos Automation (Scripting)

Re: JUISE and jcs:grep problems.

‎07-01-2013 08:21 PM

jcs:grep is attempting jcs:invoke("file show $filename") on router connection, and not reading local file.

 

/Charlie

 

<!--
- jcs:grep($filename, $pattern) :: grep the pattern from the given file
-->
<xsl:template name="jcs:grep">
...

<xsl:variable name="query">
<command>
<xsl:value-of select="concat('file show ', $filename)"/>
</command>
</xsl:variable>
<xsl:variable name="out" select="jcs:invoke($query)"/>
<!-- Read the file -->
...

</xsl:template>

 

 

Junos Automation (Scripting)

Re: JUISE and jcs:grep problems.

‎07-09-2013 04:25 PM

Can I get a copy of your script to diagnose the underlaying issue?  There should be no problem mixing jcs:invoke and jcs:execute.

 

Thanks,

 Phil

 

Junos Automation (Scripting)

Re: JUISE and jcs:grep problems.

‎07-09-2013 04:38 PM

The biggest difference between on-box and off-box scripting is that on-box, you have the CLI to perform XML-to-text rendering, where off the box, there is no rendering.  If your script makes XML, juise will just display that XML.  The rendering libraries are part of JUNOS and juise doesn't have a means of accessing them.

 

Re: <output> and jcsSmiley Surprisedutput:  These two are similar, but operate in distinct ways.  The <output> element is part of the normal CLI's XML-to-text rendering, so when the script is complete, the output XML tree is passed to the CLI, who has rules that render <output> text into straight text.  jcsSmiley Surprisedutput() outputs the text argument immediately, so you'll see the output while the script is running.

 

match / {

    <op-script-results> {

       expr jcsSmiley Surprisedutput("start");

       expr jcs:sleep(4);

       <output> "during";

       expr jcs:sleep(4);

       expr jcsSmiley Surprisedutput("after");

    }

}

 

 You'll see "start" and "after" while the script is running, but "during" only after it's complete.

 

In SLAX-1.1 (JUNOS 12.2 and later) you have the "message" statement, which operates identically to jcsSmiley Surprisedutput, but uses the standard <xsl:message> element.

 

 match / {

    <op-script-results> {

        message "Something like " _ this;

        message {

            if (you/need/logic) {

                expr "put it inside the message statement";

            } else {

               call some:thing();

            }

        }

    }

}

 

Thanks,

 Phil