Signed-off-by: FUJITA Tomonori <fujita.tomon...@lab.ntt.co.jp>
---
 ryu/services/protocols/bgp/operator/ssh.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/ryu/services/protocols/bgp/operator/ssh.py 
b/ryu/services/protocols/bgp/operator/ssh.py
index ac93791..86b233f 100644
--- a/ryu/services/protocols/bgp/operator/ssh.py
+++ b/ryu/services/protocols/bgp/operator/ssh.py
@@ -21,6 +21,7 @@ import paramiko
 import sys
 from copy import copy
 from oslo.config import cfg
+import os.path
 
 from ryu.lib import hub
 from ryu import version
@@ -79,11 +80,25 @@ Hello, this is Ryu BGP speaker (version %s).
 
         transport = paramiko.Transport(sock)
         transport.load_server_moduli()
-        host_key = paramiko.RSAKey.from_private_key_file(CONF.cli_ssh_hostkey)
+        host_key = self._find_ssh_server_key()
         transport.add_server_key(host_key)
         self.transport = transport
         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)
+        elif os.path.exists("/etc/ssh_host_rsa_key"):
+            # OSX
+            return paramiko.RSAKey.from_private_key_file(
+                "/etc/ssh_host_rsa_key")
+        elif os.path.exists("/etc/ssh/ssh_host_rsa_key"):
+            # Linux
+            return paramiko.RSAKey.from_private_key_file(
+                "/etc/ssh/ssh_host_rsa_key")
+        else:
+            return paramiko.RSAKey.generate(1024)
+
     def check_auth_none(self, username):
         return paramiko.AUTH_SUCCESSFUL
 
-- 
1.8.5.2 (Apple Git-48)


------------------------------------------------------------------------------
The best possible search technologies are now affordable for all companies.
Download your FREE open source Enterprise Search Engine today!
Our experts will assist you in its installation for $59/mo, no commitment.
Test it for FREE on our Cloud platform anytime!
http://pubads.g.doubleclick.net/gampad/clk?id=145328191&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to