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

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


The following commit(s) were added to refs/heads/DATALAB-2409 by this push:
     new 80b4548  [DATALAB-2409] - [AWS] SSN prepare refactored
80b4548 is described below

commit 80b4548cf321e0a25b337620343b9174f8ab4fa1
Author: bodnarmykola <[email protected]>
AuthorDate: Tue Jul 27 13:46:23 2021 +0300

    [DATALAB-2409] - [AWS] SSN prepare refactored
---
 .../src/general/lib/aws/actions_lib.py             |  2 +-
 .../src/general/scripts/aws/ssn_prepare.py         | 29 +++++++++++-----------
 .../scripts/aws/ssn_terminate_aws_resources.py     | 13 ++++++----
 3 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/infrastructure-provisioning/src/general/lib/aws/actions_lib.py 
b/infrastructure-provisioning/src/general/lib/aws/actions_lib.py
index 57d1236..c8d6ffc 100644
--- a/infrastructure-provisioning/src/general/lib/aws/actions_lib.py
+++ b/infrastructure-provisioning/src/general/lib/aws/actions_lib.py
@@ -1168,7 +1168,7 @@ def remove_sgroups(tag_value):
         ec2 = boto3.resource('ec2')
         client = boto3.client('ec2')
         tag_name = os.environ['conf_service_base_name']
-        print('removing sg with tag key {} and tag value {}'.format(tag_name, 
tag_value))
+        print('Removing SG with tag key: {} and tag value: 
{}'.format(tag_name, tag_value))
         sgs = ec2.security_groups.filter(
             Filters=[{'Name': 'tag:{}'.format(tag_name), 'Values': 
[tag_value]}])
         if sgs:
diff --git a/infrastructure-provisioning/src/general/scripts/aws/ssn_prepare.py 
b/infrastructure-provisioning/src/general/scripts/aws/ssn_prepare.py
index 9ca4e12..5f6a36e 100644
--- a/infrastructure-provisioning/src/general/scripts/aws/ssn_prepare.py
+++ b/infrastructure-provisioning/src/general/scripts/aws/ssn_prepare.py
@@ -359,20 +359,21 @@ if __name__ == "__main__":
 
     #creating route53 records
     try:
-        if ssn_conf['network_type'] == 'private':
-            ssn_conf['instance_ip'] = 
datalab.meta_lib.get_instance_ip_address(ssn_conf['tag_name'],
-                                                                               
ssn_conf['instance_name']).get('Private')
-        else:
-            ssn_conf['instance_ip'] = 
datalab.meta_lib.get_instance_ip_address(ssn_conf['tag_name'],
-                                                                               
ssn_conf['instance_name']).get('Public')
-        logging.info('[CREATING ROUTE53 RECORD]')
-        try:
-            
datalab.actions_lib.create_route_53_record(os.environ['ssn_hosted_zone_id'],
-                                                       
os.environ['ssn_hosted_zone_name'],
-                                                       
os.environ['ssn_subdomain'], ssn_conf['instance_ip'])
-        except:
-            traceback.print_exc()
-            raise Exception
+        if 'ssn_hosted_zone_id' in os.environ and 'ssn_hosted_zone_name' in 
os.environ and 'ssn_subdomain' in os.environ:
+            if ssn_conf['network_type'] == 'private':
+                ssn_conf['instance_ip'] = 
datalab.meta_lib.get_instance_ip_address(ssn_conf['tag_name'],
+                                                                               
    ssn_conf['instance_name']).get('Private')
+            else:
+                ssn_conf['instance_ip'] = 
datalab.meta_lib.get_instance_ip_address(ssn_conf['tag_name'],
+                                                                               
    ssn_conf['instance_name']).get('Public')
+            logging.info('[CREATING ROUTE53 RECORD]')
+            try:
+                
datalab.actions_lib.create_route_53_record(os.environ['ssn_hosted_zone_id'],
+                                                           
os.environ['ssn_hosted_zone_name'],
+                                                           
os.environ['ssn_subdomain'], ssn_conf['instance_ip'])
+            except:
+                traceback.print_exc()
+                raise Exception
     except Exception as err:
         logging.error('Error: {0}'.format(err))
         datalab.fab.append_result("Failed to create route53 record", str(err))
diff --git 
a/infrastructure-provisioning/src/general/scripts/aws/ssn_terminate_aws_resources.py
 
b/infrastructure-provisioning/src/general/scripts/aws/ssn_terminate_aws_resources.py
index 72ad38f..802a5d1 100644
--- 
a/infrastructure-provisioning/src/general/scripts/aws/ssn_terminate_aws_resources.py
+++ 
b/infrastructure-provisioning/src/general/scripts/aws/ssn_terminate_aws_resources.py
@@ -80,14 +80,17 @@ if __name__ == "__main__":
 
     print("Removing security groups")
     try:
-        datalab.actions_lib.remove_sgroups(args.de_se_sg)
-        datalab.actions_lib.remove_sgroups(args.de_sg)
-        datalab.actions_lib.remove_sgroups(args.nb_sg)
-        datalab.actions_lib.remove_sgroups(args.edge_sg)
+        try:
+            datalab.actions_lib.remove_sgroups(args.de_se_sg)
+            datalab.actions_lib.remove_sgroups(args.de_sg)
+            datalab.actions_lib.remove_sgroups(args.nb_sg)
+            datalab.actions_lib.remove_sgroups(args.edge_sg)
+        except:
+            print("There are no SG for compute resources")
         try:
             datalab.actions_lib.remove_sgroups(args.tag_name)
         except:
-            print("There is no pre-defined SSN SG")
+            print("There is SSN SG")
     except Exception as err:
         datalab.fab.append_result("Failed to remove security groups.", 
str(err))
         sys.exit(1)

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

Reply via email to