summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xbin/ryu20
-rw-r--r--ryu/cmd/ryu_base.py75
-rw-r--r--setup.cfg1
3 files changed, 96 insertions, 0 deletions
diff --git a/bin/ryu b/bin/ryu
new file mode 100755
index 00000000..d726b481
--- /dev/null
+++ b/bin/ryu
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2014 YAMAMOTO Takashi <yamamoto at valinux co jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from ryu.cmd.ryu_base import main
+main()
diff --git a/ryu/cmd/ryu_base.py b/ryu/cmd/ryu_base.py
new file mode 100644
index 00000000..9ea75c25
--- /dev/null
+++ b/ryu/cmd/ryu_base.py
@@ -0,0 +1,75 @@
+# Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2014 YAMAMOTO Takashi <yamamoto at valinux co jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import ryu.contrib
+
+from ryu import cfg
+from ryu import utils
+from ryu import version
+import argparse
+import os.path
+import sys
+
+
+subcommands = {
+ 'run': 'ryu.cmd.manager',
+ 'of-config-cli': 'ryu.cmd.of_config_cli',
+ 'rpc-cli': 'ryu.cmd.rpc_cli',
+}
+
+
+class RemainderOpt(cfg.MultiStrOpt):
+ def _get_argparse_kwargs(self, group, **kwargs):
+ kwargs = cfg.MultiStrOpt._get_argparse_kwargs(self, group, **kwargs)
+ kwargs['nargs'] = argparse.REMAINDER
+ return kwargs
+
+
+base_conf = cfg.ConfigOpts()
+base_conf.register_cli_opt(cfg.StrOpt('subcommand', positional=True,
+ required=True,
+ help='[%s]' % '|'.join(
+ subcommands.keys())))
+base_conf.register_cli_opt(RemainderOpt('subcommand_args', default=[],
+ positional=True,
+ help='subcommand specific arguments'))
+
+
+class SubCommand(object):
+ def __init__(self, name, entry):
+ self.name = name
+ self.entry = entry
+
+ def run(self, args):
+ prog = '%s %s' % (os.path.basename(sys.argv[0]), self.name,)
+ self.entry(args=args, prog=prog)
+
+
+def main():
+ try:
+ base_conf(project='ryu', version='ryu %s' % version)
+ except cfg.RequiredOptError, e:
+ base_conf.print_help()
+ raise SystemExit(1)
+ subcmd_name = base_conf.subcommand
+ try:
+ subcmd_mod_name = subcommands[subcmd_name]
+ except KeyError:
+ base_conf.print_help()
+ raise SystemExit('Unknown subcommand %s' % subcmd_name)
+ subcmd_mod = utils.import_module(subcmd_mod_name)
+ subcmd = SubCommand(name=subcmd_name, entry=subcmd_mod.main)
+ subcmd.run(base_conf.subcommand_args)
diff --git a/setup.cfg b/setup.cfg
index 6e6527fa..45f4ca42 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -48,4 +48,5 @@ setup-hooks =
[entry_points]
console_scripts =
ryu-manager = ryu.cmd.manager:main
+ ryu = ryu.cmd.ryu_base:main
rpc-cli = ryu.cmd.rpc_cli:main