You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datalab.apache.org by my...@apache.org on 2021/08/02 09:07:10 UTC
[incubator-datalab] branch DATALAB-2409 updated: [DATALAB-2409] -
[AWS] SSN termination script refactored
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 522cab5 [DATALAB-2409] - [AWS] SSN termination script refactored
522cab5 is described below
commit 522cab5bc7b4f076f648887a1181475a78c48ec4
Author: bodnarmykola <bo...@gmail.com>
AuthorDate: Mon Aug 2 12:06:51 2021 +0300
[DATALAB-2409] - [AWS] SSN termination script refactored
---
.../scripts/aws/ssn_terminate_aws_resources.py | 52 ++++++++++++----------
1 file changed, 29 insertions(+), 23 deletions(-)
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 802a5d1..3078e19 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
@@ -23,7 +23,6 @@
import argparse
import boto3
-import datalab.ssn_lib
import os
import sys
@@ -42,7 +41,14 @@ tag2 = args.service_base_name + '-secondary-tag'
##############
if __name__ == "__main__":
- print('Terminating EMR cluster')
+ # configuring logs
+ local_log_filename = "{}_{}.log".format(os.environ['conf_resource'], os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" + local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ handlers=[logging.StreamHandler(), logging.FileHandler(local_log_filepath)])
+
+ logging.info('Terminating EMR cluster')
try:
clusters_list = datalab.meta_lib.get_emr_list(args.tag_name)
if clusters_list:
@@ -52,21 +58,21 @@ if __name__ == "__main__":
cluster = cluster.get("Cluster")
emr_name = cluster.get('Name')
datalab.actions_lib.terminate_emr(cluster_id)
- print("The EMR cluster {} has been terminated successfully".format(emr_name))
+ logging.info("The EMR cluster {} has been terminated successfully".format(emr_name))
else:
- print("There are no EMR clusters to terminate.")
+ logging.info("There are no EMR clusters to terminate.")
except Exception as err:
datalab.fab.append_result("Failed to terminate EMR cluster.", str(err))
sys.exit(1)
- print("Deregistering notebook's AMI")
+ logging.info("Deregistering notebook's AMI")
try:
datalab.actions_lib.deregister_image()
except Exception as err:
datalab.fab.append_result("Failed to deregister images.", str(err))
sys.exit(1)
- print("Terminating EC2 instances")
+ logging.info("Terminating EC2 instances")
try:
datalab.actions_lib.remove_ec2(args.tag_name, '*')
except Exception as err:
@@ -74,11 +80,11 @@ if __name__ == "__main__":
sys.exit(1)
if 'ssn_hosted_zone_id' in os.environ and 'ssn_hosted_zone_name' in os.environ and 'ssn_subdomain' in os.environ:
- print("Removing Route53 records")
+ logging.info("Removing Route53 records")
datalab.actions_lib.remove_route_53_record(os.environ['ssn_hosted_zone_id'], os.environ['ssn_hosted_zone_name'],
os.environ['ssn_subdomain'])
- print("Removing security groups")
+ logging.info("Removing security groups")
try:
try:
datalab.actions_lib.remove_sgroups(args.de_se_sg)
@@ -86,44 +92,44 @@ if __name__ == "__main__":
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")
+ logging.info("There are no SG for compute resources")
try:
datalab.actions_lib.remove_sgroups(args.tag_name)
except:
- print("There is SSN SG")
+ logging.info("There is SSN SG")
except Exception as err:
datalab.fab.append_result("Failed to remove security groups.", str(err))
sys.exit(1)
- print("Removing private subnet")
+ logging.info("Removing private subnet")
try:
datalab.actions_lib.remove_subnets('*')
except Exception as err:
datalab.fab.append_result("Failed to remove subnets.", str(err))
sys.exit(1)
- print("Removing peering connection")
+ logging.info("Removing peering connection")
try:
datalab.actions_lib.remove_peering('*')
except Exception as err:
datalab.fab.append_result("Failed to remove peering connections.", str(err))
sys.exit(1)
- print("Removing s3 buckets")
+ logging.info("Removing s3 buckets")
try:
datalab.actions_lib.remove_s3()
except Exception as err:
datalab.fab.append_result("Failed to remove buckets.", str(err))
sys.exit(1)
- print("Removing IAM roles, profiles and policies")
+ logging.info("Removing IAM roles, profiles and policies")
try:
datalab.actions_lib.remove_all_iam_resources('all')
except Exception as err:
datalab.fab.append_result("Failed to remove IAM roles, profiles and policies.", str(err))
sys.exit(1)
- print("Removing route tables")
+ logging.info("Removing route tables")
try:
datalab.actions_lib.remove_route_tables(args.tag_name)
datalab.actions_lib.remove_route_tables(tag2)
@@ -131,45 +137,45 @@ if __name__ == "__main__":
datalab.fab.append_result("Failed to remove route tables.", str(err))
sys.exit(1)
- print("Removing SSN subnet")
+ logging.info("Removing SSN subnet")
try:
datalab.actions_lib.remove_subnets(args.service_base_name + '-subnet')
except Exception as err:
datalab.fab.append_result("Failed to remove SSN subnet.", str(err))
sys.exit(1)
- print("Removing SSN VPC")
+ logging.info("Removing SSN VPC")
try:
vpc_id = datalab.meta_lib.get_vpc_by_tag(args.tag_name, args.service_base_name)
if vpc_id != '':
try:
datalab.actions_lib.remove_vpc_endpoints(vpc_id)
except:
- print("There is no such VPC Endpoint")
+ logging.info("There is no such VPC Endpoint")
try:
datalab.actions_lib.remove_internet_gateways(vpc_id, args.tag_name, args.service_base_name)
except:
- print("There is no such Internet gateway")
+ logging.info("There is no such Internet gateway")
datalab.actions_lib.remove_route_tables(args.tag_name, True)
datalab.actions_lib.remove_vpc(vpc_id)
else:
- print("There is no pre-defined SSN VPC")
+ logging.info("There is no pre-defined SSN VPC")
except Exception as err:
datalab.fab.append_result("Failed to remove SSN VPC.", str(err))
sys.exit(1)
- print("Removing notebook VPC")
+ logging.info("Removing notebook VPC")
try:
vpc_id = datalab.meta_lib.get_vpc_by_tag(tag2, args.service_base_name)
if vpc_id != '':
try:
datalab.actions_lib.remove_vpc_endpoints(vpc_id)
except:
- print("There is no such VPC Endpoint")
+ logging.info("There is no such VPC Endpoint")
datalab.actions_lib.remove_route_tables(tag2, True)
datalab.actions_lib.remove_vpc(vpc_id)
else:
- print("There is no pre-defined notebook VPC")
+ logging.info("There is no pre-defined notebook VPC")
except Exception as err:
datalab.fab.append_result("Failed to remove wecondary VPC.", str(err))
sys.exit(1)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org