From 1eec530e943d0c8bd99bff070cc74d894a00c79d Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Fri, 13 Jul 2018 01:16:30 -0700 Subject: [PATCH] add more capability for terminating instances --- aws-experiment-launch/terminate_instances.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/aws-experiment-launch/terminate_instances.py b/aws-experiment-launch/terminate_instances.py index 7203b88b8..6fe03acaf 100644 --- a/aws-experiment-launch/terminate_instances.py +++ b/aws-experiment-launch/terminate_instances.py @@ -41,13 +41,18 @@ if __name__ == "__main__": LOGGER.info("%s is not existed" % args.instance_output) sys.exit(1) if args.region_number and args.node_name_tag: - ec2_client, session = utils.create_ec2_client(args.region_number, args.region_config) - filters = [{'Name': 'tag:Name','Values': [args.node_name_tag]}] - instance_ids = utils.get_instance_ids(ec2_client.describe_instances(Filters=filters)) - ec2_client.terminate_instances(InstanceIds=instance_ids) - LOGGER.info("waiting until instances with tag %s died." % args.node_name_tag) - waiter = ec2_client.get_waiter('instance_terminated') - waiter.wait(InstanceIds=instance_ids) + region_number_items = args.region_number.split(",") + node_name_tag_items = args.node_name_tag.split(",") + thread_pool = [] + for i in range(len(region_number_items)): + region_number = region_number_items[i] + node_name_tag = node_name_tag_items[i] + t = threading.Thread(target=terminate_instances_by_region, args=(region_number, args.region_config, node_name_tag)) + t.start() + thread_pool.append(t) + for t in thread_pool: + t.join() + LOGGER.info("done.") elif args.instance_output: with open(args.instance_output, "r") as fin: thread_pool = []