|
|
|
@ -35,9 +35,9 @@ def run_one_region_instances(config, region_number, number_of_instances, instanc |
|
|
|
|
node_name_tag = create_instances( |
|
|
|
|
config, ec2_client, region_number, int(number_of_instances)) |
|
|
|
|
print("Created %s in region %s" % (node_name_tag, region_number)) |
|
|
|
|
return node_name_tag |
|
|
|
|
return node_name_tag, ec2_client |
|
|
|
|
else: |
|
|
|
|
return None |
|
|
|
|
return None, None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_instances(config, ec2_client, region_number, number_of_instances): |
|
|
|
@ -90,27 +90,34 @@ if __name__ == "__main__": |
|
|
|
|
description='This script helps you start instances across multiple regions') |
|
|
|
|
parser.add_argument('--regions', type=str, dest='regions', |
|
|
|
|
default='3', help="Supply a csv list of all regions") |
|
|
|
|
parser.add_argument('--instances', type=str, dest='numInstances', |
|
|
|
|
default='1', help='number of instances') |
|
|
|
|
parser.add_argument('--configuration', type=str, |
|
|
|
|
dest='config', default='configuration.txt') |
|
|
|
|
parser.add_argument('--instances', type=str, dest='num_instance_list', |
|
|
|
|
default='1', help='number of instances in respective of region') |
|
|
|
|
parser.add_argument('--region_config', type=str, dest='region_config', default='configuration.txt') |
|
|
|
|
parser.add_argument('--instance_output', type=str, dest='instance_output', |
|
|
|
|
default='instance_output.txt', help='the file to append or write') |
|
|
|
|
parser.add_argument('--instance_ids_output', type=str, dest='instance_ids_output', |
|
|
|
|
default='instance_ids_output.txt', help='the file to append or write') |
|
|
|
|
parser.add_argument('--append', dest='append', type=bool, default=False, |
|
|
|
|
help='append to the current instance_output') |
|
|
|
|
args = parser.parse_args() |
|
|
|
|
config = utils.read_region_config(args.config) |
|
|
|
|
config = utils.read_region_config(args.region_config) |
|
|
|
|
region_list = args.regions.split(',') |
|
|
|
|
instances_list = args.numInstances.split(',') |
|
|
|
|
assert len(region_list) == len(instances_list), "number of regions: %d != number of instances per region: %d" % (len(region_list), len(instances_list)) |
|
|
|
|
num_instance_list = args.num_instance_list.split(',') |
|
|
|
|
assert(len(region_list) == len(num_instance_list), |
|
|
|
|
"number of regions: %d != number of instances per region: %d" % (len(region_list), len(num_instance_list))) |
|
|
|
|
|
|
|
|
|
with open(args.instance_output, "a" if args.append else "w") as fout: |
|
|
|
|
write_mode = "a" if args.append else "w" |
|
|
|
|
with open(args.instance_output, write_mode) as fout, open(args.instance_ids_output, write_mode) as fout2: |
|
|
|
|
for i in range(len(region_list)): |
|
|
|
|
region_number = region_list[i] |
|
|
|
|
number_of_instances = instances_list[i] |
|
|
|
|
node_name_tag = run_one_region_instances(config, region_number, number_of_instances, InstanceResource.ON_DEMAND) |
|
|
|
|
number_of_instances = num_instance_list[i] |
|
|
|
|
node_name_tag, ec2_client = run_one_region_instances(config, region_number, number_of_instances, InstanceResource.ON_DEMAND) |
|
|
|
|
if node_name_tag: |
|
|
|
|
print("Managed to create instances for region %s" % region_number ) |
|
|
|
|
fout.write("%s %s\n" % (node_name_tag, region_number)) |
|
|
|
|
filters = [{'Name': 'tag:Name','Values': [node_name_tag]}] |
|
|
|
|
instance_ids = utils.get_instance_ids(ec2_client.describe_instances(Filters=filters)) |
|
|
|
|
for instance_id in instance_ids: |
|
|
|
|
fout2.write(instance_id + " " + node_name_tag + " " + region_number) |
|
|
|
|
else: |
|
|
|
|
print("Failed to create instances for region %s" % region_number ) |
|
|
|
|
print("Failed to create instances for region %s" % region_number ) |