示例#1
0
def sanity_check_plan(collector, stack, artifact, **kwargs):
    """sanity check a predefined list of stacks in order"""
    plan = artifact if artifact else stack
    checked = []
    builder = Builder()

    stacks = collector.configuration["stacks"]
    for stack in Plan.find_stacks(collector.configuration, stacks, plan):
        builder.sanity_check(stacks[stack], stacks, checked=checked)
示例#2
0
def deploy_all(collector, **kwargs):
    stacks = collector.configuration["stacks"]
    made = []
    checked = []
    deployer = Deployer()

    # XXX: does this need more order logic other than layers?
    for index, layer in enumerate(Builder().layered(stacks)):
        for _, stack in layer:
            deployer.deploy_stack(stack, stacks, made=made, checked=checked)
示例#3
0
def show(collector, **kwargs):
    """
    Show what stacks we have in layered order.

    When combined with the ``--flat`` option, the stacks are shown as a flat
    list instead of in layers.
    """
    configuration = collector.configuration
    flat = configuration.get("bespin.flat", False)
    only_pushable = configuration.get("bespin.only_pushable", False)

    stacks = configuration["stacks"]
    for index, layer in enumerate(Builder().layered(stacks, only_pushable=only_pushable)):
        if flat:
            for _, stack in layer:
                print(stack.stack_name)
        else:
            print("Layer {0}".format(index))
            for _, stack in layer:
                print("    {0}".format(stack.display_line()))
            print("")
示例#4
0
    def deploy_stack(self,
                     stack,
                     stacks,
                     made=None,
                     ignore_deps=False,
                     checked=None,
                     start=None,
                     is_dependency=False):
        """Deploy a stack and all it's dependencies"""
        if start is None:
            start = datetime.utcnow()

        made = [] if made is None else made
        checked = [] if checked is None else checked
        if stack.name in made:
            return

        Builder().sanity_check(stack,
                               stacks,
                               ignore_deps=ignore_deps,
                               checked=checked)
        made.append(stack.name)

        if stack.name not in stacks:
            raise NoSuchStack(looking_for=stack.name, available=stacks.keys())

        sent_by = "bespin=={0}({1})".format(
            VERSION, os.environ.get("USER", "<unknown_user>"))
        if not is_dependency and stack.notify_stackdriver:
            if stack.stackdriver is NotSpecified:
                raise BespinError(
                    "Need to specify stackdriver options when specifying notify_stackdriver"
                )
            stack.stackdriver.create_event(
                "{0}-{1} - Deploying cloudformation".format(
                    stack.stack_name,
                    stack.stackdriver.format_version(stack.env)), sent_by)

        if not ignore_deps and not stack.ignore_deps:
            for dependency in stack.dependencies(stacks):
                self.deploy_stack(stacks[dependency],
                                  stacks,
                                  made=made,
                                  ignore_deps=True,
                                  checked=checked,
                                  start=start,
                                  is_dependency=True)

        # Should have all our dependencies now
        log.info("Making stack for '%s' (%s)", stack.name, stack.stack_name)
        self.build_stack(stack)

        if any(stack.build_after):
            for dependency in stack.build_after:
                self.deploy_stack(stacks[dependency],
                                  stacks,
                                  made=made,
                                  ignore_deps=True,
                                  checked=checked,
                                  start=start,
                                  is_dependency=True)

        if not is_dependency and stack.notify_stackdriver:
            stack.stackdriver.create_event(
                "{0}-{1} - Finished cloudformation".format(
                    stack.stack_name,
                    stack.stackdriver.format_version(stack.env)), sent_by)

        if stack.artifact_retention_after_deployment:
            Builder().clean_old_artifacts(stack)

        self.confirm_deployment(stack, start)
示例#5
0
def validate_templates(collector, **kwargs):
    """Validates all stack templates and parameters against CloudFormation"""
    stacks = collector.configuration["stacks"]
    for index, layer in enumerate(Builder().layered(stacks)):
        for _, stack in layer:
            stack.validate_template_params()
示例#6
0
def sanity_check(collector, stack, **kwargs):
    """Sanity check a stack and it's dependencies"""
    Builder().sanity_check(stack, collector.configuration["stacks"])
    log.info("All the stacks are sane!")
示例#7
0
def clean_old_artifacts(collector, stack, **kwargs):
    """Cleanup old artifacts"""
    Builder().clean_old_artifacts(stack)
示例#8
0
def publish_artifacts(collector, stack, **kwargs):
    """Build and publish an artifact"""
    Builder().publish_artifacts(stack)