def bootstrap(self, *args):
        utils.log("[%s] initializing temp instance to create bootstrap AMI" % self)

        config = {"roles": ["bootstrap", "temp"], "name": "temp0"}
        instance = AWSInstance(self, config)
        instance.create()

        now = datetime.utcnow()
        name = "stamped.base.ami (%s-%s-%s %s.%s.%s)" % (now.year, now.month, now.day, now.hour, now.minute, now.second)
        ami_id = self.conn.create_image(instance.instance_id, name, "Base AMI for Stamped instances")
        image = None

        utils.log("[%s] waiting for AMI %s (%s) to come online" % (self, name, ami_id))
        while True:
            try:
                images = self.conn.get_all_images(image_ids=[ami_id])
                image = images[0]
            except Exception:
                time.sleep(1)

        success = False

        while True:
            image.update()

            if image.state == u"pending":
                time.sleep(2)
            elif image.state == u"available":
                success = True
                break
            else:
                utils.log("[%s] error creating AMI %s (%s) (invalid state: %s)" % (self, name, ami_id, image.state))
                break

        if success:
            utils.log("[%s] successfully created AMI %s (%s)" % (self, name, ami_id))

        utils.log("[%s] cleaning up temp instance %s" % (self, instance))
        instance.terminate()
Beispiel #2
0
        def _create_instance(i):
            cur_conf = conf.copy()
            cur_conf["name"] = "%s%d" % (add, top + i)

            # TODO: this assumes nodes were previously evenly distributed
            # instead, calculate minimal placement each iteration
            placement = placements[i % len(placements)][0]
            cur_conf["placement"] = placement

            # create and bootstrap the new instance
            utils.log(
                "[%s] creating instance %s in availability zone %s" % (self, cur_conf["name"], cur_conf["placement"])
            )
            instance = AWSInstance(self, cur_conf)

            try:
                instance.create()
                instances.append(instance)
            except Exception:
                utils.printException()
                utils.log("error adding instance %s" % instance)
                raise