def create_instance(self): if self.aws_key is None: self.aws_key = self.config.get("aws_key", None) if self.aws_secret_key is None: self.aws_secret_key = self.config.get("aws_secret_key", None) self.conn = aws_util.connect(self.config["region"], self.aws_key, self.aws_secret_key) itype = self.config.get("instance_type", "m1.large") print "Creating a new instance of type", itype # Known images: # ami-bf1d8a8f == Ubuntu 13.04 # ami-ace67f9c == Ubuntu 13.10 # ami-76831f46 == telemetry-base - based on Ubuntu 13.04 with dependencies # already installed # ami-260c9516 == telemetry-server - Based on Ubuntu 13.10, everything is # ready to go, server will be auto-started on boot. Does # NOT auto-start process-incoming. # See if ephemerals have been specified mapping = None if "ephemeral_map" in self.config: mapping = BlockDeviceMapping() for device, ephemeral in self.config["ephemeral_map"].iteritems(): mapping[device] = BlockDeviceType(ephemeral_name=ephemeral) reservation = self.conn.run_instances( self.config.get("image", "ami-bf1d8a8f"), key_name=self.config["ssl_key_name"], instance_type=itype, security_groups=self.config["security_groups"], placement=self.config.get("placement", None), block_device_map=mapping, user_data=self.get_user_data(), instance_profile_name=self.config.get("iam_role"), instance_initiated_shutdown_behavior=self.config.get( "shutdown_behavior", "stop")) instance = reservation.instances[0] default_tags = self.config.get("default_tags", {}) if len(default_tags) > 0: self.conn.create_tags([instance.id], default_tags) # TODO: # - find all instances where Owner = mreid and Application = telemetry-server # - get the highest number # - use the next one (or first unused one) for the current instance name. name_tag = {"Name": self.config["name"]} self.conn.create_tags([instance.id], name_tag) while instance.state == 'pending': print "Instance is pending - Waiting 10s for instance", instance.id, "to start up..." time.sleep(10) instance.update() print "Instance", instance.id, "is", instance.state return instance
def create_instance(self): if self.aws_key is None: self.aws_key = self.config.get("aws_key", None) if self.aws_secret_key is None: self.aws_secret_key = self.config.get("aws_secret_key", None) self.conn = aws_util.connect(self.config["region"], self.aws_key, self.aws_secret_key) itype = self.config.get("instance_type", "m1.large") print "Creating a new instance of type", itype # Known images: # ami-bf1d8a8f == Ubuntu 13.04 # ami-ace67f9c == Ubuntu 13.10 # ami-76831f46 == telemetry-base - based on Ubuntu 13.04 with dependencies # already installed # ami-260c9516 == telemetry-server - Based on Ubuntu 13.10, everything is # ready to go, server will be auto-started on boot. Does # NOT auto-start process-incoming. # See if ephemerals have been specified mapping = None if "ephemeral_map" in self.config: mapping = BlockDeviceMapping() for device, ephemeral in self.config["ephemeral_map"].iteritems(): mapping[device] = BlockDeviceType(ephemeral_name=ephemeral) reservation = self.conn.run_instances( self.config.get("image", "ami-bf1d8a8f"), key_name=self.config["ssl_key_name"], instance_type=itype, security_groups=self.config["security_groups"], placement=self.config.get("placement", None), block_device_map=mapping, user_data=self.get_user_data(), instance_profile_name=self.config.get("iam_role"), instance_initiated_shutdown_behavior=self.config.get("shutdown_behavior", "stop"), ) instance = reservation.instances[0] default_tags = self.config.get("default_tags", {}) if len(default_tags) > 0: self.conn.create_tags([instance.id], default_tags) # TODO: # - find all instances where Owner = mreid and Application = telemetry-server # - get the highest number # - use the next one (or first unused one) for the current instance name. name_tag = {"Name": self.config["name"]} self.conn.create_tags([instance.id], name_tag) while instance.state == "pending": print "Instance is pending - Waiting 10s for instance", instance.id, "to start up..." time.sleep(10) instance.update() print "Instance", instance.id, "is", instance.state return instance
def go(self): print "Using the following config:" print json.dumps(self.config) if "instance_id" in self.config: print "Fetching instance", self.config["instance_id"] self.conn = aws_util.connect(self.config["region"], self.aws_key, self.aws_secret_key) self.instance = aws_util.get_instance(conn, self.config["instance_id"]) else: print "Creating instance..." self.instance = self.create_instance() print "Ready to connect..." try: ssl_host = "@".join((self.ssl_user, self.instance.public_dns_name)) print "To connect to it:" print "ssh -i", self.ssl_key_path, ssl_host if not self.config.get("skip_ssh", False): env.key_filename = self.ssl_key_path env.host_string = ssl_host # Can't connect when using known hosts :( env.disable_known_hosts = True # Long-running commands may time out if we don't set this env.keepalive = 5 if aws_util.wait_for_ssh(self.config.get("ssl_retries", 3)): print "SSH Connection is ready." else: print "Failed to establish SSH Connection to", self.instance.id sys.exit(2) if not self.config.get("skip_bootstrap", False): self.bootstrap_instance(self.instance) self.run(self.instance) except Exception, e: print "Launch Error:", e