From daea96645ae6b9fe3d350769ccd126696332217c Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Fri, 16 Dec 2016 15:17:36 +0900 Subject: rpc_cli: Enable to execute a single command This patch enables 'ryu rpc-cli' command to execute a single command not interactively. e.g.) $ ryu rpc-cli --peers=bgp=localhost:50002 \ --command='request bgp operator.show [{"params": ["rib", "ipv4"]}]' This feature is convenient to controle BGPSpeaker states via shell commands, for example. Signed-off-by: IWASE Yusuke Signed-off-by: FUJITA Tomonori --- ryu/cmd/rpc_cli.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ryu/cmd/rpc_cli.py b/ryu/cmd/rpc_cli.py index ac542143..2519c8bb 100755 --- a/ryu/cmd/rpc_cli.py +++ b/ryu/cmd/rpc_cli.py @@ -43,8 +43,12 @@ from ryu.lib import rpc CONF = cfg.CONF CONF.register_cli_opts([ - # eg. rpc-cli --peers=hoge=localhost:9998,fuga=localhost:9999 - cfg.ListOpt('peers', default=[], help='list of peers') + cfg.ListOpt('peers', default=[], + help='List of peers, separated by commas. ' + '(e.g., "hoge=localhost:9998,fuga=localhost:9999")'), + cfg.StrOpt('command', short='c', default=None, + help='Command to be executed as single command. ' + 'The default is None and opens interactive console.'), ]) @@ -229,6 +233,11 @@ def main(args=None, prog=None): host, port = addr.rsplit(':', 1) add_peer(name, host, port) + if CONF.command: + command = Cmd() + command.onecmd(CONF.command) + command.do_EOF() + Cmd().cmdloop() -- cgit v1.2.3