def __init__ (self, conf_file, cidr_block): #Loads the conf file provided as cmd line argument self.conf = self.__load_conf (conf_file); #Extracts CIDR from dictionary self.cidr_block = self.conf["cidr"]; #Create connections self.ec2_conn = awsConn.create_ec2_conn_singapore (); self.vpc_conn = awsConn.create_vpc_conn_singapore (); #Create a private subnet for participant self.private_subnet = self.__create_private_subnet (); #Extracting Participant ID, CIDR='172.16.[participant_id].0/24' self.participant_id = self.conf["cidr"].split(".")[2]; #Creating instances in private subnet of participant self.controller_ip, self.compute_ip, self.cloud_instances =self.__run_cloud_instances (); #Creates a dictionary for storing the IDs of instances created self.conf_participant = self.__populate_conf_participant(); #Store the conf in a file self.__persist_conf_participant(); print '=============================================================' print '=== AWS machines successfully setup ===' print '=============================================================' print '=== Jump Host IP: ', self.conf["eip_address"]; print '=== Controller IP: ', self.controller_ip; print '=== Compute IP: ', self.compute_ip; print '============================================================='
def __init__(self, conf_file, cidr_block): #Loads the conf file provided as cmd line argument self.conf = self.__load_conf(conf_file) #Extracts CIDR from dictionary self.cidr_block = self.conf["cidr"] #Create connections self.ec2_conn = awsConn.create_ec2_conn_singapore() self.vpc_conn = awsConn.create_vpc_conn_singapore() #Create a private subnet for participant self.private_subnet = self.__create_private_subnet() #Extracting Participant ID, CIDR='172.16.[participant_id].0/24' self.participant_id = self.conf["cidr"].split(".")[2] #Creating instances in private subnet of participant self.controller_ip, self.compute_ip, self.cloud_instances = self.__run_cloud_instances( ) #Creates a dictionary for storing the IDs of instances created self.conf_participant = self.__populate_conf_participant() #Store the conf in a file self.__persist_conf_participant() print '=============================================================' print '=== AWS machines successfully setup ===' print '=============================================================' print '=== Jump Host IP: ', self.conf["eip_address"] print '=== Controller IP: ', self.controller_ip print '=== Compute IP: ', self.compute_ip print '============================================================='
def __init__(self, name, expected_participants): """ Dictionary 'conf' holds IDs for VPC resources It would be serialized before the script exits It could be used to add private subnets to the VPC and free-up VPC resources """ self.conf = { "name": name } self.expected_participants = expected_participants #Creates connection to the services in singapore region using awsConn self.ec2_conn = awsConn.create_ec2_conn_singapore() self.vpc_conn = awsConn.create_vpc_conn_singapore() #Create VPC self.vpc = self.__create_vpc() #Create a public subnet for the resources to be connected with internet self.public_subnet = self.__create_public_subnet() #Creates an Internet Gateway for the VPC self.ig = self.__create_attach_internet_gateway() #Gets the main Routing table of VPC self.main_rtable = self.__get_main_rtable() #Creates a custom Routing table for the subnet self.custom_rtable, self.custom_rtable_assoc = \ self.__create_custom_rtable() # Creating security groups for both NAT and private instances and adding rules for the traffic self.sg_nat = self.__create_sg_nat() self.sg_private = self.__create_sg_private() #Starts the NAT instance with the SG created above self.nat_instance = self.__run_nat_instance() #This will allocate a public IP to our VPC self.eip = self.__allocate_eip_nat() #This will create a route to NAT such that all traffic from private will go to NAT self.__create_route_to_nat() #Add all the ID's in conf dictionary self.__populate_conf() #Store the conf dictionary to files self.__persist_conf()
def __init__ (self, name, expected_participants): """ Dictionary 'conf' holds IDs for VPC resources It would be serialized before the script exits It could be used to add private subnets to the VPC and free-up VPC resources """ self.conf = {"name" : name}; self.expected_participants = expected_participants; #Creates connection to the services in singapore region using awsConn self.ec2_conn = awsConn.create_ec2_conn_singapore(); self.vpc_conn = awsConn.create_vpc_conn_singapore(); #Create VPC self.vpc = self.__create_vpc(); #Create a public subnet for the resources to be connected with internet self.public_subnet = self.__create_public_subnet(); #Creates an Internet Gateway for the VPC self.ig = self.__create_attach_internet_gateway(); #Gets the main Routing table of VPC self.main_rtable = self.__get_main_rtable(); #Creates a custom Routing table for the subnet self.custom_rtable, self.custom_rtable_assoc = \ self.__create_custom_rtable(); # Creating security groups for both NAT and private instances and adding rules for the traffic self.sg_nat = self.__create_sg_nat(); self.sg_private = self.__create_sg_private(); #Starts the NAT instance with the SG created above self.nat_instance = self.__run_nat_instance(); #This will allocate a public IP to our VPC self.eip = self.__allocate_eip_nat(); #This will create a route to NAT such that all traffic from private will go to NAT self.__create_route_to_nat(); #Add all the ID's in conf dictionary self.__populate_conf(); #Store the conf dictionary to files self.__persist_conf();
def __init__ (self, conf_file): try: with open (conf_file, 'r') as fp: self.conf = json.load(fp); self.ec2_conn = awsConn.create_ec2_conn_singapore(); self.vpc_conn = awsConn.create_vpc_conn_singapore(); self.__release(); except IOError: print 'IOError: Conf file not found'; sys.exit(-1); except KeyError as e: print conf_file + " does not contain key " + e.args[0]; print "Make sure Conf file is valid and contains all resource ids"; sys.exit(-1);
def __init__(self, conf_file): try: with open(conf_file, 'r') as fp: self.conf = json.load(fp) self.ec2_conn = awsConn.create_ec2_conn_singapore() self.vpc_conn = awsConn.create_vpc_conn_singapore() self.__release() except IOError: print 'IOError: Conf file not found' sys.exit(-1) except KeyError as e: print conf_file + " does not contain key " + e.args[0] print "Make sure Conf file is valid and contains all resource ids" sys.exit(-1)
def __init__(self, conf_file): try: with open(conf_file, 'r') as fp: self.conf = json.load(fp) #Creates the connection to aws EC2 and VPC service self.ec2_conn = awsConn.create_ec2_conn_singapore() self.vpc_conn = awsConn.create_vpc_conn_singapore() #Extract instance and subnet IDS from the config file self.instance_ids = self.conf['instance_ids'].split(',') self.private_subnet = self.conf['private_subnet'] self.__release() except IOError: print 'IOError: Participant conf file not found' sys.exit(-1) except KeyError as e: print conf_file + "does not contain key " + e.args[0] print "Make sure Conf file is valid and contains all resource ids" sys.exit(-1)
def __init__ (self, conf_file): try: with open (conf_file, 'r') as fp: self.conf = json.load(fp); #Creates the connection to aws EC2 and VPC service self.ec2_conn = awsConn.create_ec2_conn_singapore(); self.vpc_conn = awsConn.create_vpc_conn_singapore(); #Extract instance and subnet IDS from the config file self.instance_ids = self.conf['instance_ids'].split(','); self.private_subnet = self.conf['private_subnet']; self.__release(); except IOError: print 'IOError: Participant conf file not found'; sys.exit(-1); except KeyError as e: print conf_file + "does not contain key " + e.args[0]; print "Make sure Conf file is valid and contains all resource ids"; sys.exit(-1);
def wait_for_instances(instances, state='running', ec2_conn=None): """ If there isn't any instance created, create the instance to singapore region """ if ec2_conn == None: ec2_conn = awsConn.create_ec2_conn_singapore() while True: """ Gets all EC2 instances based on their IDs provided. """ reservation = ec2_conn.get_all_instances(instance_ids=instances) """ Checks the state of each instance one by one """ if all(instance.state == state for instance in reservation[0].instances): time.sleep(20) return else: print 'Waiting for instances to be in ' + state + ' state' time.sleep(5)
def wait_for_instances (instances, state='running', ec2_conn=None): """ If there isn't any instance created, create the instance to singapore region """ if ec2_conn == None: ec2_conn = awsConn.create_ec2_conn_singapore(); while True: """ Gets all EC2 instances based on their IDs provided. """ reservation = ec2_conn.get_all_instances ( instance_ids=instances); """ Checks the state of each instance one by one """ if all(instance.state == state for instance in reservation[0].instances): time.sleep(20); return; else: print 'Waiting for instances to be in ' + state + ' state'; time.sleep(5);