You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datalab.apache.org by lf...@apache.org on 2022/06/10 13:39:29 UTC

[incubator-datalab] 01/01: [DATALAB-2853]: added reserve user for connection

This is an automated email from the ASF dual-hosted git repository.

lfrolov pushed a commit to branch DATALAB-2853
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git

commit 336a911878a47621679aca8f1b885d9c1c8f205c
Author: leonidfrolov <fr...@gmail.com>
AuthorDate: Fri Jun 10 16:39:15 2022 +0300

    [DATALAB-2853]: added reserve user for connection
---
 .../src/base/scripts/create_ssh_user.py            |  2 +-
 .../src/general/lib/os/fab.py                      | 31 +++++++++++++---------
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/infrastructure-provisioning/src/base/scripts/create_ssh_user.py b/infrastructure-provisioning/src/base/scripts/create_ssh_user.py
index 183295cf5..3af70e5a9 100644
--- a/infrastructure-provisioning/src/base/scripts/create_ssh_user.py
+++ b/infrastructure-provisioning/src/base/scripts/create_ssh_user.py
@@ -57,7 +57,7 @@ def ensure_ssh_user(initial_user, os_user, sudo_group):
 if __name__ == "__main__":
     print("Configure connections")
     global conn
-    conn = datalab.fab.init_datalab_connection(args.hostname, args.initial_user, args.keyfile)
+    conn = datalab.fab.init_datalab_connection(args.hostname, args.initial_user, args.keyfile, args.os_user)
     print("Creating ssh user: {}".format(args.os_user))
     try:
         ensure_ssh_user(args.initial_user, args.os_user, args.sudo_group)
diff --git a/infrastructure-provisioning/src/general/lib/os/fab.py b/infrastructure-provisioning/src/general/lib/os/fab.py
index 33f1ef2ae..add3157c3 100644
--- a/infrastructure-provisioning/src/general/lib/os/fab.py
+++ b/infrastructure-provisioning/src/general/lib/os/fab.py
@@ -40,22 +40,27 @@ from patchwork import files
 
 
 # general functions for all resources
-def init_datalab_connection(hostname, username, keyfile):
+def init_datalab_connection(hostname, username, keyfile, reserve_user=''):
     try:
         global conn
-        attempt = 0
-        while attempt < 15:
-            logging.info('connection attempt {}'.format(attempt))
-            conn = Connection(host=hostname, user=username, connect_kwargs={'banner_timeout': 200,
-                                                                            'key_filename': keyfile})
-            conn.config.run.echo = True
-            try:
-                conn.run('hostname')
+        if reserve_user:
+            users = [username, reserve_user]
+        else:
+            users = [username]
+        for user in users:
+            attempt = 0
+            while attempt < 15:
+                logging.info('connection attempt {} with user {}'.format(attempt, user))
+                conn = Connection(host=hostname, user=user, connect_kwargs={'banner_timeout': 200,
+                                                                                'key_filename': keyfile})
                 conn.config.run.echo = True
-                return conn
-            except:
-                attempt += 1
-                time.sleep(10)
+                try:
+                    conn.run('hostname')
+                    conn.config.run.echo = True
+                    return conn
+                except:
+                    attempt += 1
+                    time.sleep(10)
         if attempt == 15:
             logging.info('Unable to establish connection')
             raise Exception


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org