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

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

commit 907fcd66775af34e8e6fff763b6fcd3587310541
Author: leonidfrolov <[email protected]>
AuthorDate: Mon Mar 2 13:31:45 2020 +0200

    [DLAB-1539]: added user tag and custom tag to notebook labels
---
 .../src/general/lib/gcp/meta_lib.py                     |  2 +-
 .../src/general/scripts/gcp/common_prepare_notebook.py  | 17 +++++++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/infrastructure-provisioning/src/general/lib/gcp/meta_lib.py 
b/infrastructure-provisioning/src/general/lib/gcp/meta_lib.py
index d31106e..2cc6197 100644
--- a/infrastructure-provisioning/src/general/lib/gcp/meta_lib.py
+++ b/infrastructure-provisioning/src/general/lib/gcp/meta_lib.py
@@ -256,7 +256,7 @@ class GCPMeta:
                         service_account_email = service_account['email']
                         response = 
service_account_email[:service_account_email.find('@')][-5:]
                 if response == '':
-                    print("No service account with" + service_account_name + 
"display name.")
+                    print("No service account with " + service_account_name + 
" display name.")
                 else:
                     print("Service account " + service_account_name + " has " 
+ response + " index.")
                 return response
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 dedf730..39c93e1 100644
--- 
a/infrastructure-provisioning/src/general/scripts/gcp/common_prepare_notebook.py
+++ 
b/infrastructure-provisioning/src/general/scripts/gcp/common_prepare_notebook.py
@@ -45,7 +45,6 @@ if __name__ == "__main__":
     notebook_config['project_name'] = 
(os.environ['project_name']).lower().replace('_', '-')
     notebook_config['project_tag'] = 
(os.environ['project_name']).lower().replace('_', '-')
     notebook_config['endpoint_tag'] = 
(os.environ['endpoint_name']).lower().replace('_', '-')
-    notebook_config['user_tag'] = 
(os.environ['user_tag']).lower().replace('_', '-')
     notebook_config['region'] = os.environ['gcp_region']
     notebook_config['zone'] = os.environ['gcp_zone']
 
@@ -133,16 +132,26 @@ if __name__ == "__main__":
         data = {"notebook_name": notebook_config['instance_name'], "error": ""}
         json.dump(data, f)
 
-    additional_tags = os.environ['tags'].replace("': u'", ": ").replace("', 
u'", ", ").replace("{u'", "" ).replace("'}", "")
-    print('Additional tags will be added: {}'.format(additional_tags))
+    additional_tags = json.loads(os.environ['tags'].replace("': u'", "\": 
\"").replace("', u'", "\", \"").replace("{u'", "{\"" ).replace("'}", "\"}"))
+
+    if '@' in additional_tags['user_tag']:
+        notebook_config['user_tag'] = 
additional_tags['user_tag'][:additional_tags['user_tag'].find('@')]
+    else:
+        notebook_config['user_tag'] = additional_tags['user_tag']
 
+    notebook_config['custom_tag'] = additional_tags['custom_tag']
+    print('Additional tags will be added: {}'.format(additional_tags))
     notebook_config['labels'] = {"name": notebook_config['instance_name'],
                                  "sbn": notebook_config['service_base_name'],
                                  "project_tag": notebook_config['project_tag'],
                                  "endpoint_tag": 
notebook_config['endpoint_tag'],
                                  "user": notebook_config['user_tag'],
-                                 "product": "dlab",
+                                 "product": "dlab"
                                  }
+
+    if notebook_config['custom_tag'] != '':
+        notebook_config['labels'].update({'custom_tag': 
notebook_config['custom_tag']})
+
     # launching instance for notebook server
     try:
         logging.info('[CREATE NOTEBOOK INSTANCE]')


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to