def add_to_haproxy(unit, host, iid): while True: # add it to the chef config output = knife_environment_show(unit.env_name) if util.is_noop(): temp = "debug-knife-file.json" iid2privipv4(iid) else: data = json.loads(output) block = 'haproxy-' + unit.unit_name region_context = unit.region_context host = util.env_prefix(region_context)+unit.env_name+"-"+unit.unit_name+"-"+iid+"."+ region_context.region_config['unit_domain'] ip = iid2privipv4(iid) # print("looking for override/haproxy/"+block+"/servers/ to add host:"+host) data['override_attributes']['haproxy'][block]["servers"].append([host, ip]) temp = util.write_temp_file(json.dumps(data), suffix=".json") util.execute_shell(["knife", "environment", "from", "file", temp]) # verify host is now in output output = knife_environment_show(unit.env_name) print >> sys.stderr, "looking for host="+host+" in output: "+str(output) if util.is_noop(): return if host in output: return else: time.sleep(10)
def run_instance(unit, instance_number): config = unit.config region_config = unit.region_context.region_config region_name = unit.region_context.region args = ["ec2-run-instances", unit.get_ami(), "--instance-initiated-shutdown-behavior", "terminate", "--region", region_config['EC2_REGION'], "-g", unit.env_group_name, "-g", unit.group_name] if 'extra_groups' in config: for group in util.to_list(config['extra_groups']): args.append("-g") args.append(group) args += [ "-t", unit.get_instance_size(), "-k", unit.get_keypair() ] data = unit.get_user_data() if data is not None: data_file = util.write_temp_file("run_"+unit.unit_name+"_"+unit.role_name+"_userdata_", suffix=".json") args += [ "-f", data_file ] azone = unit.get_availability_zone() if azone is not None: args += [ "-z", azone] elif 'default_availability_zone' in region_config: args += [ "-z", region_config['default_availability_zone'] ] output = util.execute_shell(args) if util.is_noop(): iid = "i-debug" else: iid = util.find_element_on_line_starting_with(output[0], "INSTANCE", 1) return iid
def add_instance(unit, instance_number, iid): host = None while True: host = str(util.execute_shell(["iid2hn", iid])[0]).strip() print host if util.is_noop(): host = 'debug.host.example.com' # print "iid2hn returned "+host if host != "pending" and len(host) > 10 and len(host) < 100: break time.sleep(5) # "waiting for $HOST ssh to come up" while True: rval = util.execute_shell_returncode(["nc", "-z", host, "22"]) if rval != 0: time.sleep(5) else: # "$HOST ready for use" break bootstrap(unit, host, iid)