This is an automated email from the ASF dual-hosted git repository. lfrolov pushed a commit to branch DLAB-54-dev in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
commit 6212366858d7ce280c5c681e685a64bd4814d52e Author: leonidfrolov <frolovl...@gmail.com> AuthorDate: Thu Jun 11 20:01:22 2020 +0300 [DLAB-54]: changed code to create use and delete custom images --- .../general/scripts/gcp/common_create_notebook_image.py | 8 +++++--- .../src/general/scripts/gcp/common_prepare_notebook.py | 16 ++++++++++------ .../scripts/gcp/common_terminate_notebook_image.py | 12 +++++++----- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/infrastructure-provisioning/src/general/scripts/gcp/common_create_notebook_image.py b/infrastructure-provisioning/src/general/scripts/gcp/common_create_notebook_image.py index 2359e27..c7b4b0a 100644 --- a/infrastructure-provisioning/src/general/scripts/gcp/common_create_notebook_image.py +++ b/infrastructure-provisioning/src/general/scripts/gcp/common_create_notebook_image.py @@ -33,6 +33,8 @@ import os if __name__ == "__main__": try: image_conf = dict() + GCPMeta = dlab.meta_lib.GCPMeta() + GCPActions = dlab.actions_lib.GCPActions() try: image_conf['exploratory_name'] = (os.environ['exploratory_name']).replace('_', '-').lower() except: @@ -46,11 +48,11 @@ if __name__ == "__main__": image_conf['instance_name'] = os.environ['notebook_instance_name'] image_conf['instance_tag'] = '{}-tag'.format(image_conf['service_base_name']) image_conf['application'] = os.environ['application'] - image_conf['image_name'] = os.environ['notebook_image_name'] - image_conf['expected_primary_image_name'] = '{}-{}-{}-{}-primary-{}'.format( + image_conf['image_name'] = os.environ['notebook_image_name'].replace('_', '-').lower() + image_conf['expected_primary_image_name'] = '{}-{}-{}-{}-primary-image-{}'.format( image_conf['service_base_name'], image_conf['project_name'], image_conf['endpoint_name'], os.environ['application'], image_conf['image_name']) - image_conf['expected_secondary_image_name'] = '{}-{}-{}-{}-secondary-{}'.format( + image_conf['expected_secondary_image_name'] = '{}-{}-{}-{}-secondary-image-{}'.format( image_conf['service_base_name'], image_conf['project_name'], image_conf['endpoint_name'], os.environ['application'], image_conf['image_name']) image_conf['image_labels'] = {"sbn": image_conf['service_base_name'], diff --git a/infrastructure-provisioning/src/general/scripts/gcp/common_prepare_notebook.py b/infrastructure-provisioning/src/general/scripts/gcp/common_prepare_notebook.py index c83208b..d616350 100644 --- a/infrastructure-provisioning/src/general/scripts/gcp/common_prepare_notebook.py +++ b/infrastructure-provisioning/src/general/scripts/gcp/common_prepare_notebook.py @@ -113,12 +113,13 @@ if __name__ == "__main__": notebook_config['service_base_name'], notebook_config['endpoint_name'], os.environ['application']) notebook_config['expected_secondary_image_name'] = '{}-{}-{}-secondary-image'.format( notebook_config['service_base_name'], notebook_config['endpoint_name'], os.environ['application']) - notebook_config['notebook_primary_image_name'] = \ - (lambda x: os.environ['notebook_primary_image_name'] if x != 'None' - else notebook_config['expected_primary_image_name'])(str(os.environ.get('notebook_primary_image_name'))) + notebook_config['notebook_primary_image_name'] = (lambda x: '{0}-{1}-{2}-{3}-primary-image-{4}'.format( + notebook_config['service_base_name'], notebook_config['project_name'], notebook_config['endpoint_name'], + os.environ['application'], os.environ['notebook_image_name'].replace('_', '-').lower()) if (x != 'None' and x != '') + else notebook_config['expected_primary_image_name'])(str(os.environ.get('notebook_image_name'))) print('Searching pre-configured images') notebook_config['primary_image_name'] = GCPMeta.get_image_by_name( - notebook_config['expected_primary_image_name']) + notebook_config['notebook_primary_image_name']) if notebook_config['primary_image_name'] == '': notebook_config['primary_image_name'] = os.environ['gcp_{}_image_name'.format(os.environ['conf_os_family'])] else: @@ -126,9 +127,12 @@ if __name__ == "__main__": notebook_config['primary_image_name'].get('name'))) notebook_config['primary_image_name'] = 'global/images/{}'.format( notebook_config['primary_image_name'].get('name')) - + notebook_config['notebook_secondary_image_name'] = (lambda x: '{0}-{1}-{2}-{3}-secondary-image-{4}'.format( + notebook_config['service_base_name'], notebook_config['project_name'], notebook_config['endpoint_name'], + os.environ['application'], os.environ['notebook_image_name'].replace('_', '-').lower()) if (x != 'None' and x != '') + else notebook_config['expected_secondary_image_name'])(str(os.environ.get('notebook_image_name'))) notebook_config['secondary_image_name'] = GCPMeta.get_image_by_name( - notebook_config['expected_secondary_image_name']) + notebook_config['notebook_secondary_image_name']) if notebook_config['secondary_image_name'] == '': notebook_config['secondary_image_name'] = 'None' else: diff --git a/infrastructure-provisioning/src/general/scripts/gcp/common_terminate_notebook_image.py b/infrastructure-provisioning/src/general/scripts/gcp/common_terminate_notebook_image.py index 373a426..a869a38 100644 --- a/infrastructure-provisioning/src/general/scripts/gcp/common_terminate_notebook_image.py +++ b/infrastructure-provisioning/src/general/scripts/gcp/common_terminate_notebook_image.py @@ -32,6 +32,8 @@ import os if __name__ == "__main__": try: image_conf = dict() + GCPMeta = dlab.meta_lib.GCPMeta() + GCPActions = dlab.actions_lib.GCPActions() image_conf['image_name'] = os.environ['notebook_image_name'] image_conf['service_base_name'] = os.environ['conf_service_base_name'] = dlab.fab.replace_multi_symbols( os.environ['conf_service_base_name'][:20], '-', True) @@ -39,16 +41,16 @@ if __name__ == "__main__": image_conf['endpoint_tag'] = image_conf['endpoint_name'] image_conf['project_name'] = os.environ['project_name'] image_conf['project_tag'] = os.environ['project_name'] - image_conf['expected_primary_image_name'] = '{}-{}-{}-{}-primary-{}'.format( + image_conf['expected_primary_image_name'] = '{}-{}-{}-{}-primary-image-{}'.format( image_conf['service_base_name'], image_conf['project_name'], image_conf['endpoint_name'], os.environ['application'], image_conf['image_name']) - image_conf['expected_secondary_image_name'] = '{}-{}-{}-{}-secondary-{}'.format( + image_conf['expected_secondary_image_name'] = '{}-{}-{}-{}-secondary-image-{}'.format( image_conf['service_base_name'], image_conf['project_name'], image_conf['endpoint_name'], os.environ['application'], image_conf['image_name']) - primary_image_id = dlab.meta_lib.GCPMeta.get_image_by_name(image_conf['expected_primary_image_name']) + primary_image_id = GCPMeta.get_image_by_name(image_conf['expected_primary_image_name']) if primary_image_id != '': - dlab.actions_lib.GCPActions.remove_image(notebook_config['expected_primary_image_name']) - dlab.actions_lib.GCPActions.remove_image(notebook_config['expected_secondary_image_name']) + GCPActions.remove_image(notebook_config['expected_primary_image_name']) + GCPActions.remove_image(notebook_config['expected_secondary_image_name']) with open("/root/result.json", 'w') as result: res = {"notebook_image_name": image_conf['full_image_name'], "status": "terminated", --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org For additional commands, e-mail: commits-h...@dlab.apache.org