You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by my...@apache.org on 2020/05/25 09:04:25 UTC

[incubator-dlab] branch DLAB-1835 created (now 3a49853)

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

mykolabodnar pushed a change to branch DLAB-1835
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git.


      at 3a49853  [DLAB-1835]: Host resolving fixes

This branch includes the following new commits:

     new 3a49853  [DLAB-1835]: Host resolving fixes

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



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


[incubator-dlab] 01/01: [DLAB-1835]: Host resolving fixes

Posted by my...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mykolabodnar pushed a commit to branch DLAB-1835
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git

commit 3a4985322f63f71e2b7890fca2e913678c89f965
Author: bodnarmykola <bo...@gmail.com>
AuthorDate: Mon May 25 12:03:43 2020 +0300

    [DLAB-1835]: Host resolving fixes
---
 .../src/base/scripts/create_ssh_user.py                  | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/infrastructure-provisioning/src/base/scripts/create_ssh_user.py b/infrastructure-provisioning/src/base/scripts/create_ssh_user.py
index 482eb2c..5a866aa 100644
--- a/infrastructure-provisioning/src/base/scripts/create_ssh_user.py
+++ b/infrastructure-provisioning/src/base/scripts/create_ssh_user.py
@@ -35,6 +35,14 @@ parser.add_argument('--sudo_group', type=str, default='')
 args = parser.parse_args()
 
 
+def resolving_hosts(initial_user):
+    if not exists('/home/{}/.hosts_resolved'.format(initial_user)):
+        host = sudo('curl http://169.254.169.254/latest/meta-data/local-hostname').split('\n')[1]
+        host_short = host.split('.')[0]
+        private_ip = sudo('curl http://169.254.169.254/latest/meta-data/local-ipv4').split('\n')[1]
+        sudo('echo "{} {} {}" >> /etc/hosts'.format(private_ip, host, host_short))
+        sudo('touch /home/{}/.hosts_resolved'.format(initial_user))
+
 def ensure_ssh_user(initial_user, os_user, sudo_group):
     if not exists('/home/{}/.ssh_user_ensured'.format(initial_user)):
         sudo('useradd -m -G {1} -s /bin/bash {0}'.format(os_user, sudo_group))
@@ -48,13 +56,19 @@ def ensure_ssh_user(initial_user, os_user, sudo_group):
         sudo('mkdir /home/{}/.ensure_dir'.format(os_user))
         sudo('touch /home/{}/.ssh_user_ensured'.format(initial_user))
 
-
 if __name__ == "__main__":
     print("Configure connections")
     env['connection_attempts'] = 100
     env.key_filename = [args.keyfile]
     env.host_string = '{}@{}'.format(args.initial_user, args.hostname)
 
+    print("Resolving hosts")
+    try:
+        resolving_hosts(args.initial_user)
+    except Exception as err:
+        print('Failed to resolve hosts', str(err))
+        sys.exit(1)
+
     print("Creating ssh user: {}".format(args.os_user))
     try:
         ensure_ssh_user(args.initial_user, args.os_user, args.sudo_group)


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