From 382dec07264ba9b6b5027e15bd88d62278b19775 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Sat, 7 Jul 2018 07:38:39 -0700 Subject: [PATCH] add more option to kill node --- aws-experiment-launch/terminate_instances.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/aws-experiment-launch/terminate_instances.py b/aws-experiment-launch/terminate_instances.py index 0de97a918..ccbc3d6f5 100644 --- a/aws-experiment-launch/terminate_instances.py +++ b/aws-experiment-launch/terminate_instances.py @@ -10,6 +10,8 @@ if __name__ == "__main__": parser.add_argument('--instance_output', type=str, dest='instance_output', default='instance_output.txt', help='the file contains node_name_tag and region number of created instances.') + parser.add_argument('--node_name_tag', type=str, dest='node_name_tag') + parser.add_argument('--region_number', type=str, dest='region_number') parser.add_argument('--region_config', type=str, dest='region_config', default='configuration.txt') args = parser.parse_args() @@ -17,7 +19,15 @@ if __name__ == "__main__": if not args.instance_output or not os.path.isfile(args.instance_output): print "%s is not existed" % args.instance_output sys.exit(1) - if args.instance_output: + 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) + print "waiting until instances with tag %s died." % args.node_name_tag + waiter = ec2_client.get_waiter('instance_terminated') + waiter.wait(InstanceIds=instance_ids) + elif args.instance_output: with open(args.instance_output, "r") as fin: for line in fin.readlines(): items = line.split(" ")