You can't pass ssh.py to run command any more. If you need ssh CLI,
update the bgp config file and then:

ryu run —-config-file /path/to/ryu.conf 
/path/to/ryu/ryu/services/protocols/application.py

Signed-off-by: FUJITA Tomonori <[email protected]>
---
 ryu/services/protocols/bgp/application.py     |  3 ++
 ryu/services/protocols/bgp/bgp_sample_conf.py |  9 +++++
 ryu/services/protocols/bgp/bgpspeaker.py      |  6 +--
 ryu/services/protocols/bgp/operator/ssh.py    | 55 ++++++++++++---------------
 4 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/ryu/services/protocols/bgp/application.py 
b/ryu/services/protocols/bgp/application.py
index 786c1ed..43aac8b 100644
--- a/ryu/services/protocols/bgp/application.py
+++ b/ryu/services/protocols/bgp/application.py
@@ -47,6 +47,7 @@ from ryu.services.protocols.bgp.rtconf import neighbors
 from ryu.services.protocols.bgp.rtconf import vrfs
 from ryu.services.protocols.bgp.utils.dictconfig import dictConfig
 from ryu.services.protocols.bgp.utils.validation import is_valid_ipv4
+from ryu.services.protocols.bgp.operator import ssh
 
 LOG = logging.getLogger('bgpspeaker.application')
 CONF = cfg.CONF
@@ -92,6 +93,8 @@ class RyuBGPSpeaker(RyuApp):
             if getattr(settings, 'BGP', None):
                 self._start_core(settings)
 
+            if getattr(settings, 'SSH', None) is not None:
+                hub.spawn(ssh.SSH_CLI_CONTROLLER.start, None, **settings.SSH)
         # Start Network Controller to server RPC peers.
         t = hub.spawn(net_ctrl.NET_CONTROLLER.start, *[],
                       **{net_ctrl.NC_RPC_BIND_IP: self.bind_ip,
diff --git a/ryu/services/protocols/bgp/bgp_sample_conf.py 
b/ryu/services/protocols/bgp/bgp_sample_conf.py
index cf20cce..b380156 100644
--- a/ryu/services/protocols/bgp/bgp_sample_conf.py
+++ b/ryu/services/protocols/bgp/bgp_sample_conf.py
@@ -36,6 +36,15 @@ BGP = {
 
 }
 
+
+# SSH = {
+#     'ssh_port': 4990,
+#     'ssh_host': 'localhost',
+#     'ssh_hostkey': '/etc/ssh_host_rsa_key',
+#     'ssh_username': 'ryu',
+#     'ssh_password': 'ryu'
+# }
+
 # =============================================================================
 # Logging configuration.
 # =============================================================================
diff --git a/ryu/services/protocols/bgp/bgpspeaker.py 
b/ryu/services/protocols/bgp/bgpspeaker.py
index 8e29015..a2993be 100644
--- a/ryu/services/protocols/bgp/bgpspeaker.py
+++ b/ryu/services/protocols/bgp/bgpspeaker.py
@@ -18,7 +18,6 @@
 
 import netaddr
 from ryu.lib import hub
-from ryu.base import app_manager
 from ryu.services.protocols.bgp.operator import ssh
 
 from ryu.services.protocols.bgp.core_manager import CORE_MANAGER
@@ -137,11 +136,8 @@ class BGPSpeaker(object):
         self._core_start(settings)
         self._init_signal_listeners()
         self._best_path_change_handler = best_path_change_handler
-
         if ssh_console:
-            app_mgr = app_manager.AppManager.get_instance()
-            ssh_cli = app_mgr.instantiate(ssh.Cli)
-            ssh_cli.start()
+            hub.spawn(ssh.SSH_CLI_CONTROLLER.start)
 
     def _notify_best_path_changed(self, path, is_withdraw):
         if not path.source:
diff --git a/ryu/services/protocols/bgp/operator/ssh.py 
b/ryu/services/protocols/bgp/operator/ssh.py
index 86b233f..1693b56 100644
--- a/ryu/services/protocols/bgp/operator/ssh.py
+++ b/ryu/services/protocols/bgp/operator/ssh.py
@@ -20,31 +20,27 @@ import logging
 import paramiko
 import sys
 from copy import copy
-from oslo.config import cfg
 import os.path
 
+CONF = {
+    "ssh_port": 4990,
+    "ssh_host": "localhost",
+    "ssh_hostkey": None,
+    "ssh_username": "ryu",
+    "ssh_password": "ryu",
+}
+
 from ryu.lib import hub
 from ryu import version
-from ryu.base import app_manager
 from ryu.services.protocols.bgp.operator.command import Command
 from ryu.services.protocols.bgp.operator.command import CommandsResponse
 from ryu.services.protocols.bgp.operator.commands.root import RootCmd
 from ryu.services.protocols.bgp.operator.internal_api import InternalApi
 from ryu.services.protocols.bgp.operator.command import STATUS_OK
+from ryu.services.protocols.bgp.base import Activity
 
 LOG = logging.getLogger('bgpspeaker.cli')
 
-CONF = cfg.CONF
-CONF.register_opts([
-    cfg.ListOpt('cli-transports', default=[], help='cli transports to enable'),
-    cfg.StrOpt('cli-ssh-host', default='localhost',
-               help='cli ssh listen host'),
-    cfg.IntOpt('cli-ssh-port', default=4990, help='cli ssh listen port'),
-    cfg.StrOpt('cli-ssh-hostkey', help='cli ssh host key file'),
-    cfg.StrOpt('cli-ssh-username', default='ryu', help='cli ssh username'),
-    cfg.StrOpt('cli-ssh-password', default='ryu', help='cli ssh password')
-])
-
 
 class SshServer(paramiko.ServerInterface):
     TERM = "ansi"
@@ -86,8 +82,8 @@ Hello, this is Ryu BGP speaker (version %s).
         transport.start_server(server=self)
 
     def _find_ssh_server_key(self):
-        if CONF.cli_ssh_hostkey:
-            return paramiko.RSAKey.from_private_key_file(CONF.cli_ssh_hostkey)
+        if CONF["ssh_hostkey"]:
+            return paramiko.RSAKey.from_private_key_file(ssh_hostkey)
         elif os.path.exists("/etc/ssh_host_rsa_key"):
             # OSX
             return paramiko.RSAKey.from_private_key_file(
@@ -103,8 +99,8 @@ Hello, this is Ryu BGP speaker (version %s).
         return paramiko.AUTH_SUCCESSFUL
 
     def check_auth_password(self, username, password):
-        if username == CONF.cli_ssh_username and \
-                password == CONF.cli_ssh_password:
+        if username == CONF["ssh_username"] and \
+                password == CONF["ssh_password"]:
             return paramiko.AUTH_SUCCESSFUL
         return paramiko.AUTH_FAILED
 
@@ -467,21 +463,20 @@ class SshServerFactory(object):
         SshServer(sock, addr)
 
 
-class Cli(app_manager.RyuApp):
-    def __init__(self, *args, **kwargs):
-        super(Cli, self).__init__(*args, **kwargs)
-        something_started = False
+class Cli(Activity):
+    def __init__(self):
+        super(Cli, self).__init__()
 
-    def start(self):
-        LOG.info("starting ssh server at %s:%d",
-                 CONF.cli_ssh_host, CONF.cli_ssh_port)
-        t = hub.spawn(self._ssh_thread)
-        something_started = True
-        return t
+    def _run(self, *args, **kwargs):
+        for k, v in kwargs.items():
+            if k in CONF:
+                CONF[k] = v
 
-    def _ssh_thread(self):
+        LOG.info("starting ssh server at %s:%d", CONF["ssh_host"],
+                 CONF["ssh_port"])
         factory = SshServerFactory()
-        server = hub.StreamServer((CONF.cli_ssh_host,
-                                   CONF.cli_ssh_port),
+        server = hub.StreamServer((CONF["ssh_host"], CONF["ssh_port"]),
                                   factory.streamserver_handle)
         server.serve_forever()
+
+SSH_CLI_CONTROLLER = Cli()
-- 
1.8.5.2 (Apple Git-48)


------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to