|
|
@ -38,11 +38,12 @@ def run_one_region_instances(config, region_number, number_of_instances, instanc |
|
|
|
ec2_client = session.client('ec2') |
|
|
|
ec2_client = session.client('ec2') |
|
|
|
|
|
|
|
|
|
|
|
if instance_resource == InstanceResource.ON_DEMAND: |
|
|
|
if instance_resource == InstanceResource.ON_DEMAND: |
|
|
|
return create_instances( |
|
|
|
node_name_tag = create_instances( |
|
|
|
config, ec2_client, region_number, int(number_of_instances)) |
|
|
|
config, ec2_client, region_number, int(number_of_instances)) |
|
|
|
print("Created %s in region %s" % (node_name_tag, region_number)) |
|
|
|
print("Created %s in region %s" % (node_name_tag, region_number)) |
|
|
|
|
|
|
|
return node_name_tag |
|
|
|
else: |
|
|
|
else: |
|
|
|
return False |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_instances(config, ec2_client, region_number, number_of_instances): |
|
|
|
def create_instances(config, ec2_client, region_number, number_of_instances): |
|
|
@ -85,10 +86,10 @@ def create_instances(config, ec2_client, region_number, number_of_instances): |
|
|
|
ip_list = utils.collect_public_ips_from_ec2_client(ec2_client, node_name_tag) |
|
|
|
ip_list = utils.collect_public_ips_from_ec2_client(ec2_client, node_name_tag) |
|
|
|
if len(ip_list) == number_of_instances: |
|
|
|
if len(ip_list) == number_of_instances: |
|
|
|
print("Created %d instances" % number_of_instances) |
|
|
|
print("Created %d instances" % number_of_instances) |
|
|
|
return True |
|
|
|
return node_name_tag |
|
|
|
count = count + 1 |
|
|
|
count = count + 1 |
|
|
|
print("Can not create %d instances" % number_of_instances) |
|
|
|
print("Can not create %d instances" % number_of_instances) |
|
|
|
return False |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|
parser = argparse.ArgumentParser( |
|
|
|
parser = argparse.ArgumentParser( |
|
|
@ -99,16 +100,21 @@ if __name__ == "__main__": |
|
|
|
default='1', help='number of instances') |
|
|
|
default='1', help='number of instances') |
|
|
|
parser.add_argument('--configuration', type=str, |
|
|
|
parser.add_argument('--configuration', type=str, |
|
|
|
dest='config', default='configuration.txt') |
|
|
|
dest='config', default='configuration.txt') |
|
|
|
|
|
|
|
parser.add_argument('--instance_output', type=str, |
|
|
|
|
|
|
|
dest='instance_output', default='instance_output.txt') |
|
|
|
args = parser.parse_args() |
|
|
|
args = parser.parse_args() |
|
|
|
config = utils.read_region_config(args.config) |
|
|
|
config = utils.read_region_config(args.config) |
|
|
|
region_list = args.regions.split(',') |
|
|
|
region_list = args.regions.split(',') |
|
|
|
instances_list = args.numInstances.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)) |
|
|
|
assert len(region_list) == len(instances_list), "number of regions: %d != number of instances per region: %d" % (len(region_list), len(instances_list)) |
|
|
|
|
|
|
|
|
|
|
|
for i in range(len(region_list)): |
|
|
|
with open(args.instance_output, "w") as fout: |
|
|
|
region_number = region_list[i] |
|
|
|
for i in range(len(region_list)): |
|
|
|
number_of_instances = instances_list[i] |
|
|
|
region_number = region_list[i] |
|
|
|
if run_one_region_instances(config, region_number, number_of_instances, InstanceResource.ON_DEMAND): |
|
|
|
number_of_instances = instances_list[i] |
|
|
|
print("Managed to create instances for region %s" % region_number ) |
|
|
|
node_name_tag = run_one_region_instances(config, region_number, number_of_instances, InstanceResource.ON_DEMAND) |
|
|
|
else: |
|
|
|
if node_name_tag: |
|
|
|
print("Failed to create instances for region %s" % region_number ) |
|
|
|
print("Managed to create instances for region %s" % region_number ) |
|
|
|
|
|
|
|
fout.write("%s %s\n" % (node_name_tag, region_number)) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
print("Failed to create instances for region %s" % region_number ) |
|
|
|