in lib/muchos/ec2.py [0:0]
def launch(self):
if self.active_nodes():
exit(
"ERROR - There are already instances "
"running for {0} cluster".format(self.config.cluster_name)
)
if path.isfile(self.config.hosts_path):
exit(
"ERROR - A hosts file already exists at {0}. "
"Please delete before running launch again".format(
self.config.hosts_path
)
)
self.config.verify_launch()
print("Launching {0} cluster".format(self.config.cluster_name))
if self.config.has_option("ec2", "security_group_id"):
sg_id = self.config.get("ec2", "security_group_id")
else:
sg_id = self.create_security_group()
instance_d = {}
for (hostname, services) in list(self.config.nodes().items()):
instance = self.launch_node(hostname, services, sg_id)
instance_d[instance["InstanceId"]] = hostname
num_running = len(self.get_status(["running"]))
num_expected = len(self.config.nodes())
while num_running != num_expected:
print(
"{0} of {1} nodes have started. "
"Waiting another 5 sec..".format(num_running, num_expected)
)
time.sleep(5)
num_running = len(self.get_status(["running"]))
with open(self.config.hosts_path, "w") as hosts_file:
for instance in self.get_status(["running"]):
public_ip = ""
if "PublicIpAddress" in instance:
public_ip = instance["PublicIpAddress"]
private_ip = instance["PrivateIpAddress"]
hostname = instance_d[instance["InstanceId"]]
print(
"{0} {1} {2}".format(hostname, private_ip, public_ip),
file=hosts_file,
)
print(
"All {0} nodes have started. Created hosts file at {1}".format(
num_expected, self.config.hosts_path
)
)