changeset 36:727fd98b7b78

Retry connecting to the switch
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Wed, 13 Feb 2013 16:27:33 +0100
parents 2bbc58bc81e7
children 3edbc32c07f5
files srxproxy.py
diffstat 1 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/srxproxy.py	Wed Feb 13 16:23:33 2013 +0100
+++ b/srxproxy.py	Wed Feb 13 16:27:33 2013 +0100
@@ -77,15 +77,25 @@
     netconf_password = FLAGS.netconf_server_password
     netconf_ruleset = FLAGS.netconf_rule_set
     LOG.debug('Connecting to %s:%s', netconf_ip, netconf_port)
-    with manager.connect_ssh(
-            netconf_ip,
-            port=netconf_port,
-            unknown_host_cb=lambda host, fingerprint: True,
-            username=netconf_user,
-            password=netconf_password,
-            allow_agent=False,
-            look_for_keys=False,
-        ) as m:
+    for retry in xrange(netconf_retries):
+        try:
+            m = manager.connect_ssh(
+                netconf_ip,
+                port=netconf_port,
+                unknown_host_cb=lambda host, fingerprint: True,
+                username=netconf_user,
+                password=netconf_password,
+                allow_agent=False,
+                look_for_keys=False,
+            )
+        except Exception as e:
+            LOG.warning("Failed to connect %s:%s (%s)", netconf_ip, netconf_port, e)
+        else:
+            break
+        eventlet.sleep(2**retry + 1)
+    else:
+        raise e
+    with m as m:
         assert ':url' in m.server_capabilities
         LOG.debug('Starting private edit')
         for retry in xrange(netconf_retries):