You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by dm...@apache.org on 2019/10/04 09:56:44 UTC

[incubator-dlab] 01/01: [DLAB-1107] Added parameter for notebook image creation for test purpose

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

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

commit 4bb9e0ac44a703316cdaa5fcbbf4a24f21200e28
Author: Demyan Mysakovets <de...@gmail.com>
AuthorDate: Fri Oct 4 12:56:29 2019 +0300

    [DLAB-1107] Added parameter for notebook image creation for test purpose
---
 infrastructure-provisioning/scripts/deploy_dlab.py |  2 ++
 .../src/general/conf/dlab.ini                      |  4 +++-
 .../src/general/scripts/aws/jupyter_configure.py   | 24 ++++++++++++++++++++--
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/infrastructure-provisioning/scripts/deploy_dlab.py b/infrastructure-provisioning/scripts/deploy_dlab.py
index 342e696..5e8c8d4 100644
--- a/infrastructure-provisioning/scripts/deploy_dlab.py
+++ b/infrastructure-provisioning/scripts/deploy_dlab.py
@@ -47,6 +47,8 @@ parser.add_argument('--aws_zone', type=str, default='', help='AWS zone')
 parser.add_argument('--azure_region', type=str, default='', help='Azure region')
 parser.add_argument('--gcp_region', type=str, default='', help='GCP region')
 parser.add_argument('--gcp_zone', type=str, default='', help='GCP zone')
+parser.add_argument('--image_creation', type=str, default='', help='Enable or Disable creating image at first time')
+parser.add_argument('--shared_image_enabled', type=str, default='', help='Enable or Disable shared images')
 parser.add_argument('--conf_os_family', type=str, default='',
                     help='Operating system type. Available options: debian, redhat')
 parser.add_argument('--conf_cloud_provider', type=str, default='',
diff --git a/infrastructure-provisioning/src/general/conf/dlab.ini b/infrastructure-provisioning/src/general/conf/dlab.ini
index 6c7dd45..f54b098 100644
--- a/infrastructure-provisioning/src/general/conf/dlab.ini
+++ b/infrastructure-provisioning/src/general/conf/dlab.ini
@@ -45,7 +45,9 @@ pypi_mirror = pypi.doubanio.com
 ### Name of own GitLab SSL certificate
 gitlab_certfile = dlab-gitlab.crt
 ###Enable or Disable creating image at first time
-shared_image_enabled = true
+#image_creation =
+###Enable or Disable shared images
+#shared_image_enabled =
 ### CIDR of VPC
 vpc_cidr = '172.31.0.0/16'
 ### CIDR of second VPC
diff --git a/infrastructure-provisioning/src/general/scripts/aws/jupyter_configure.py b/infrastructure-provisioning/src/general/scripts/aws/jupyter_configure.py
index 1c362c8..8b88cff 100644
--- a/infrastructure-provisioning/src/general/scripts/aws/jupyter_configure.py
+++ b/infrastructure-provisioning/src/general/scripts/aws/jupyter_configure.py
@@ -69,7 +69,21 @@ if __name__ == "__main__":
     notebook_config['tag_name'] = '{}-Tag'.format(notebook_config['service_base_name'])
     notebook_config['dlab_ssh_user'] = os.environ['conf_os_user']
     notebook_config['shared_image_enabled'] = os.environ['conf_shared_image_enabled']
+    notebook_config['image_creation'] = os.environ['conf_image_creation']
     notebook_config['ip_address'] = get_instance_ip_address(notebook_config['tag_name'], notebook_config['instance_name']).get('Private')
+    notebook_config['shared_image_tags'] = {"Name": ""os.environ['full_image_name'],
+                               "SBN": os.environ['conf_service_base_name'],
+                               "Endpoint":
+                               "Project": os.environ['project_name'],
+                               "Image": os.environ['image_name'],
+                               "FIN": os.environ['full_image_name'],
+                               os.environ['conf_billing_tag_key']: os.environ['conf_billing_tag_value']}
+    notebook_config['tags'] = {"Name": image_conf['full_image_name'],
+                              "SBN": image_conf['service_base_name'],
+                              "Project": image_conf['project_name'],
+                              "Image": image_conf['image_name'],
+                              "FIN": image_conf['full_image_name'],
+                              os.environ['conf_billing_tag_key']: os.environ['conf_billing_tag_value']}
 
     # generating variables regarding EDGE proxy on Notebook instance
     instance_hostname = get_instance_hostname(notebook_config['tag_name'], notebook_config['instance_name'])
@@ -265,11 +279,11 @@ if __name__ == "__main__":
         remove_ec2(notebook_config['tag_name'], notebook_config['instance_name'])
         sys.exit(1)
 
-    if notebook_config['shared_image_enabled'] == 'true':
+    if notebook_config['image_creation'] == 'true':
         try:
             print('[CREATING AMI]')
             ami_id = get_ami_id_by_name(notebook_config['expected_image_name'])
-            if ami_id == '':
+            if ami_id == '' && notebook_config['shared_image_enabled']:
                 print("Looks like it's first time we configure notebook server. Creating image.")
                 try:
                     os.environ['conf_additional_tags'] = os.environ['conf_additional_tags'] + ';project_tag:{0};endpoint_tag:{1};'.format(os.environ['project_name'], os.environ['endpoint_name'])
@@ -280,6 +294,12 @@ if __name__ == "__main__":
                                                       image_name=notebook_config['expected_image_name'])
                 if image_id != '':
                     print("Image was successfully created. It's ID is {}".format(image_id))
+            else:
+                image_id = create_image_from_instance(tag_name=notebook_config['tag_name'],
+                                                      instance_name=notebook_config['instance_name'],
+                                                      image_name=notebook_config['expected_image_name'])
+                if image_id != '':
+                    print("Image was successfully created. It's ID is {}".format(image_id))
         except Exception as err:
             print('Error: {0}'.format(err))
             append_result("Failed creating image.", str(err))


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