Re: [j-nsp] sequential commands in SLAX
Hi Martin, I believe that jcs:invoke() is just a shortcut for jcs:open(), jcs:execute() and jcs:close(), so you get a new connection each time you execute jcs:invoke(). Regards, Wojciech 2016-01-14 10:23 GMT+01:00 Martin T: > Hi, > > while I am aware of jcs:open() function, which allows one to execute > commands on other routing-engine, I was wondering if following logic > is also possible in SLAX: > > $ cat login_to_other_re.slax > version 1.0; > > ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0;; > import "../import/junos.xsl"; > > match / { >{ > > /* rlogin to second RE */ > var $cmd_login_other_re = "request routing-engine login > other-routing-engine"; > var $cmd_login_other_re_results = jcs:invoke( $cmd_login_other_re ); > > /* print out the name of the second RE */ > $junos-context//routing-engine-name; > > /* exit rlogin session */ > var $cmd_quit_other_re = "quit"; > var $cmd_quit_other_re_results = jcs:invoke( $cmd_quit_other_re ); > > } > } > $ > > > Why doesn't such approach work? > > > thanks, > Martin > ___ > juniper-nsp mailing list juniper-nsp@puck.nether.net > https://puck.nether.net/mailman/listinfo/juniper-nsp > ___ juniper-nsp mailing list juniper-nsp@puck.nether.net https://puck.nether.net/mailman/listinfo/juniper-nsp
Re: [j-nsp] sequential commands in SLAX
Wojciech, I didn't know that, thanks! However, I also tried with jcs:open(), jcs:execute() and jcs:close() but this didn't change anything: $ cat login_to_other_re.slax version 1.0; ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0;; import "../import/junos.xsl"; match / { { /* open local management session */ var $connection = jcs:open(); /* rlogin to second RE */ var $cmd_login_other_re = "request routing-engine login other-routing-engine"; var $cmd_login_other_re_results = jcs:execute( $connection, $cmd_login_other_re ); /* print out the name of the second RE */ $junos-context//routing-engine-name; /* exit rlogin session */ var $cmd_quit_other_re = "quit"; var $cmd_quit_other_re_results = jcs:execute( $connection, $cmd_quit_other_re ); /* close management session */ expr jcs:close( $connection ); } } $ thanks, Martin On 1/14/16, Wojciech Janiszewskiwrote: > Hi Martin, > > I believe that jcs:invoke() is just a shortcut for jcs:open(), > jcs:execute() and jcs:close(), so you get a new connection each time you > execute jcs:invoke(). > > Regards, > Wojciech > > 2016-01-14 10:23 GMT+01:00 Martin T : > >> Hi, >> >> while I am aware of jcs:open() function, which allows one to execute >> commands on other routing-engine, I was wondering if following logic >> is also possible in SLAX: >> >> $ cat login_to_other_re.slax >> version 1.0; >> >> ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0;; >> import "../import/junos.xsl"; >> >> match / { >>{ >> >> /* rlogin to second RE */ >> var $cmd_login_other_re = "request routing-engine login >> other-routing-engine"; >> var $cmd_login_other_re_results = jcs:invoke( $cmd_login_other_re ); >> >> /* print out the name of the second RE */ >> $junos-context//routing-engine-name; >> >> /* exit rlogin session */ >> var $cmd_quit_other_re = "quit"; >> var $cmd_quit_other_re_results = jcs:invoke( $cmd_quit_other_re ); >> >> } >> } >> $ >> >> >> Why doesn't such approach work? >> >> >> thanks, >> Martin >> ___ >> juniper-nsp mailing list juniper-nsp@puck.nether.net >> https://puck.nether.net/mailman/listinfo/juniper-nsp >> > ___ juniper-nsp mailing list juniper-nsp@puck.nether.net https://puck.nether.net/mailman/listinfo/juniper-nsp
Re: [j-nsp] sequential commands in SLAX
Martin T writes: >/* rlogin to second RE */ >var $cmd_login_other_re = "request routing-engine login >other-routing-engine"; >var $cmd_login_other_re_results = jcs:invoke( $cmd_login_other_re ); If you want to talk to the other RE (or any remote host), you'll need jcs:open() which returns a connection. To talk to the other RE, you'll need to know its hostname or ip address. var $other-re = "re2"; var $conn = jcs:open($other-re); var $res = jcs:execute($conn, $rpc); ... >/* print out the name of the second RE */ > $junos-context//routing-engine-name; The $junos-context will remain the local machine's context values. >/* exit rlogin session */ >var $cmd_quit_other_re = "quit"; >var $cmd_quit_other_re_results = jcs:invoke( $cmd_quit_other_re ); >Why doesn't such approach work? The API is layered tightly over the CLI, but it's not the CLI. It's meant to be mode-less and RPC oriented. Instead of passing commands over a terminal, you pass RPCs to the host's MGD directly and get XML back. Details are available in the "Day One" guides: http://www.juniper.net/us/en/training/jnbooks/day-one/automation-series/ Thanks, Phil ___ juniper-nsp mailing list juniper-nsp@puck.nether.net https://puck.nether.net/mailman/listinfo/juniper-nsp