[Xorp-cvs] XORP cvs commit: xorp/cli xorp/rtrmgr
Pavlin Radoslavov
pavlin@icir.org
Fri, 15 Jul 2005 06:33:22 GMT
CVSROOT: /usr/local/share/doc/apache/cvs
Module name: xorp
Changes by: pavlin@xorpc.icir.org 2005-07-15 06:33:22 UTC
XORP CVS repository
Modified files:
cli cli_client.cc cli_client.hh cli_node.cc cli_node.hh
cli_node_net.cc
rtrmgr cli.cc cli.hh xorpsh_main.cc xorpsh_main.hh
Log message:
Fix the xorpsh so now it can be run in non-interactive mode.
Now xorpsh can be used as following in non-interactive mode:
(1) As part of UNIX command-line pipes. E.g.:
echo "show host os" | ./xorpsh
cat filename | ./xorpsh
./xorpsh < filename
(2) As part of a shell script. E.g.:
#!/bin/sh
./xorpsh <<!
show host os
!
(3) The command can be supplied by the new "-c" xorpsh command-line option:
./xorpsh -c "show host os"
(4) As part of an "expect" script. E.g. (example courtesy of Atanu Ghosh):
#!/usr/bin/env python
import time
import sys
import pexpect
child=pexpect.spawn ('./xorpsh')
child.expect('Xorp> ')
child.sendline('show host os')
child.sendeof()
while 1:
line = child.readline()
if not line:
break
print line,
child.close()
Some of the high-level changes are:
* Now the CLI library makes cleaner distinction whether the
CliClient is a network connection (i.e., telnet) or corresponds
to a tty.
* Now the CliClient has two separate file descriptors: one for
reading the commands, and one for writing the output.
* If more input data is received while a previous command is
hasn't completed execution, the new data is buffered inside
the CLI library for later processing.
However, we always check the data for Ctrl-C, and if found
we stop the currently executed program and discard the
buffered input data.
* Improve some of the CLI library API for creating CliClient instances.
* Modify xorpsh so it uses the new imroved CLI API.
* Implement a new -c "command(s)" xorpsh command-line option for
executing xorpsh commands.
Internally, it is implemented by opening a pipe(2): the CliClient
reads from one side of the pipe, while the command(s) are written
to the other side of the pipe.
* Improve the xorpsh shutdown logic. E.g., now it won't exit if
there are still running operational commands.
Note that there are still few more things that need polishing.
E.g., if xorpsh is running in non-interactive mode, then it should
automatically suppress its internal pager for long command
outputs, etc.
[Some of the above changes are based on a patch by
"Michael Larson" <mike AT lrlart.com>]
Revision Changes Path
1.30 +94 -33; commitid: f50142d7528e7ea6; xorp/cli/cli_client.cc
1.16 +62 -18; commitid: f50142d7528e7ea6; xorp/cli/cli_client.hh
1.26 +18 -5; commitid: f50142d7528e7ea6; xorp/cli/cli_node.cc
1.19 +19 -9; commitid: f50142d7528e7ea6; xorp/cli/cli_node.hh
1.37 +185 -75; commitid: f50142d7528e7ea6; xorp/cli/cli_node_net.cc
1.70 +130 -112; commitid: f50142d7528e7ea6; xorp/rtrmgr/cli.cc
1.30 +7 -3; commitid: f50142d7528e7ea6; xorp/rtrmgr/cli.hh
1.43 +108 -25; commitid: f50142d7528e7ea6; xorp/rtrmgr/xorpsh_main.cc
1.24 +8 -4; commitid: f50142d7528e7ea6; xorp/rtrmgr/xorpsh_main.hh