Junos Automation (Scripting)
Junos Automation (Scripting)

XML API vs. <command> element for operational commands

[ Edited ]
‎05-31-2013 10:26 AM
For operational commands that map to an API elements, is there any advantage to using the API instead of the command element in a SLAX op script? Jeff L.
2 REPLIES 2
Junos Automation (Scripting)
Solution
Accepted by topic author Jeff_L
‎08-26-2015 01:27 AM

Re: XML API vs. <command> element for operational commands

‎07-09-2013 06:00 PM

Using the RPC gives you some protection against ambiguities and future CLI changes. If you say:

 

param $target;

var $command = <command> "ping " _ $target;

 

and someone runs your script as "op foo target wait" then you'll get a parse error, since "wait" is a valid CLI token.  But if you said:

 

var $command = <ping> {

    <host> $target;

}

 

then there's no parse issue regardless of your argument.  In most cases, this is a fairly minor issue, but the "belt and suspenders" part of me always wants to avoid errors, so the rigidity of the specific RPC wins over the flexibility of <command> RPC in most of my scripts.

 

Thanks,

 Phil

 

Junos Automation (Scripting)

Re: XML API vs. <command> element for operational commands

‎07-10-2013 04:35 AM

Phil,

 

The potential for parsing errors with command line arguments never occured to me. I'll use the RPC.

 

Thanks for the detailed answer.


Jeff L.