From 8cd1bd9134912cc11d6738d29f1d4f78dafd8d50 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Fri, 6 Jul 2018 09:29:08 -0700 Subject: [PATCH] update utils --- aws-experiment-launch/utils/utils.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/aws-experiment-launch/utils/utils.py b/aws-experiment-launch/utils/utils.py index af6d95ac7..ce10076dd 100644 --- a/aws-experiment-launch/utils/utils.py +++ b/aws-experiment-launch/utils/utils.py @@ -12,11 +12,11 @@ REGION_HUMAN_NAME = 'region_human_name' INSTANCE_TYPE = 't2.micro' REGION_AMI = 'region_ami' -def read_configuration_file(region_config='configuration.txt'): +def read_region_config(region_config='configuration.txt'): config = {} with open(region_config, 'r') as f: for myline in f: - mylist = myline.strip().split(',') + mylist = [item.strip() for item in myline.strip().split(',')] region_num = mylist[0] config[region_num] = {} config[region_num][REGION_NAME] = mylist[1] @@ -26,6 +26,12 @@ def read_configuration_file(region_config='configuration.txt'): config[region_num][REGION_AMI] = mylist[5] return config +def get_ip_list(response): + if response.get('Instances', None): + return [instance.get('PublicIpAddress', None) for instance in response['Instances']] + else: + return [] + def collect_public_ips(region_number, node_name_tag, region_config): config = read_configuration_file(region_config) region_name = config[region_number][REGION_NAME] @@ -75,6 +81,13 @@ def get_availability_zones(ec2_client): all_zones = [info['ZoneName'] for info in response.get('AvailabilityZones') if info['State'] == 'available'] return all_zones +def get_one_availability_zone(ec2_client): + all_zones = get_availability_zones(ec2_client) + if len(all_zones) > 0: + return all_zones[0] + else: + return None + # used for testing only. # if __name__ == "__main__": # ip_list = collect_public_ips('4', "4-NODE-23-36-01-2018-07-05", "configuration.txt")