def launch_slave(self, master_pub_key):
        init_script = make_init_script(self.config, open("slave-init.sh", "r").read(), master_pub_key=master_pub_key)

        sr = self.conn.request_spot_instances(
            price=self.config["MAX_BID"],
            image_id = self.config["AMI"],
            count = 1,
            type = 'one-time',
            key_name= self.config["KEY_NAME"],
            user_data = init_script,
            instance_type = self.config.get("SLAVE_INSTANCE_TYPE", self.config["INSTANCE_TYPE"]),
            security_groups = self.config["SECURITY_GROUPS"]
        )
        sp = sr[0]
        sp.add_tag(self.config["TAG_KEY"], "slave")
        #This sleep is intentional. Spot request api seems to be eventually consistent
        sleep(15)
        return sp, sp.tags
 def launch_master(self):
     """
     Launches a master instance
     """
     #Kill all instances, this will be fresh cluster
     self.kill_cluster()
     init_script = make_init_script(self.config, open("master-init.sh", "r").read())
     sr = self.conn.request_spot_instances(
         price=self.config["MAX_BID"],
         image_id = self.config["AMI"],
         count = 1,
         type = 'one-time',
         key_name= self.config["KEY_NAME"],
         user_data = init_script,
         instance_type = self.config.get("MASTER_INSTANCE_TYPE", self.config["INSTANCE_TYPE"]),
         security_groups = self.config["SECURITY_GROUPS"]
     )
     sp = sr[0]
     sp.add_tag(self.config["TAG_KEY"], "master")
     #This sleep is intentional. Spot request api seems to be eventually consistent
     sleep(15)
     return sp, sp.tags