This adds the feature to configure the log levels dynamically via CLI (like a commercial switch).
- I don't like to access the internal of logging module. However, seems that there is no way to know the list of used Loggers. Should we add a wrapper for logging module? - We need to stop creating Logger per file. Too many Loggers now. Logger per software component is better. - Currently, no authentication, no secure connection, no command completion support. All are the future work. = >From e2772ce83cf31a980cc9e4c979b84e6fc7541bcf Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori <[email protected]> Date: Wed, 7 Nov 2012 20:15:07 +0900 Subject: [PATCH] add interactive command line interface This adds CLI for configuring running Ryu daemon. The current feature is configuring the log levels. An example follows: fujita-mac:~ fujita$ telnet 127.0.0.1 2525 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Ryu> ? Undocumented commands: ====================== exit help log Ryu> log show ryu.ofproto.nx_match NOTSET ryu.app.simple_switch NOTSET ryu.controller.handler NOTSET ryu.ofproto.ofproto_v1_0_parser NOTSET ryu.ofproto.ofproto_parser NOTSET ryu.utils NOTSET ryu.controller.controller NOTSET ryu.app.wsgi NOTSET ryu.controller.ofp_handler NOTSET ryu.ofproto.ofproto_v1_2_parser NOTSET ryu.controller.dispatcher NOTSET ryu.base.app_manager NOTSET ryu.controller.mac_to_port NOTSET Ryu> log set ryu.controller.controller DEBUG set ryu.controller.controller loglevel to DEBUG Signed-off-by: FUJITA Tomonori <[email protected]> --- bin/ryu-manager | 5 +++ ryu/controller/cli.py | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 0 deletions(-) create mode 100644 ryu/controller/cli.py diff --git a/bin/ryu-manager b/bin/ryu-manager index 002cc59..de30d23 100755 --- a/bin/ryu-manager +++ b/bin/ryu-manager @@ -32,6 +32,7 @@ from ryu import utils from ryu.app import wsgi from ryu.base.app_manager import AppManager from ryu.controller import controller +from ryu.controller import cli # TODO: # Right now, we have our own patched copy of ovs python bindings @@ -74,6 +75,10 @@ def main(): thr = gevent.spawn_later(0, ctlr) services.append(thr) + cc = cli.CliController() + thr = gevent.spawn_later(0, cc) + services.append(thr) + webapp = wsgi.start_service(app_mgr) if webapp: thr = gevent.spawn_later(0, webapp) diff --git a/ryu/controller/cli.py b/ryu/controller/cli.py new file mode 100644 index 0000000..5185771 --- /dev/null +++ b/ryu/controller/cli.py @@ -0,0 +1,76 @@ +# Copyright (C) 2012 Nippon Telegraph and Telephone Corporation. +# +# 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 socket +import logging +import cmd +from gevent.server import StreamServer + + +class RyuCli(cmd.Cmd): + prompt = "Ryu> " + use_rawinput = False + + def do_log(self, args): + args = args.split() + if len(args) > 0: + if args[0] == 'show': + self.log_show() + elif args[0] == 'set': + self.log_set(args) + else: + self.log_help() + + def log_help(self): + self.stdout.write('log show|set\n') + + def log_show(self): + for name, l in logging.Logger.manager.loggerDict.iteritems(): + if name.startswith('ryu.') and isinstance(l, logging.Logger): + self.stdout.write('%s\t%s\n' % + (name, logging.getLevelName(l.level))) + + def log_set(self, args): + if len(args) != 3: + return + + if not isinstance(logging.getLevelName(args[2]), int): + return + + if args[1] in logging.Logger.manager.loggerDict: + log = logging.getLogger(args[1]) + log.setLevel(args[2]) + self.stdout.write('set %s loglevel to %s\n' % (args[1], args[2])) + + def do_exit(self, args): + return True + + +def client_factory(socket, address): + f = socket.makefile("rb") + try: + RyuCli(stdin=f, stdout=f).cmdloop() + except: + pass + + +class CliController(object): + def __init__(self): + super(CliController, self).__init__() + + def __call__(self): + server = StreamServer(('', 2525), + client_factory) + server.serve_forever() -- 1.7.4.4 ------------------------------------------------------------------------------ LogMeIn Central: Instant, anywhere, Remote PC access and management. Stay in control, update software, and manage PCs from one command center Diagnose problems and improve visibility into emerging IT issues Automate, monitor and manage. Do more in less time with Central http://p.sf.net/sfu/logmein12331_d2d _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
