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)
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)
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("")
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)
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()
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!")
def clean_old_artifacts(collector, stack, **kwargs): """Cleanup old artifacts""" Builder().clean_old_artifacts(stack)
def publish_artifacts(collector, stack, **kwargs): """Build and publish an artifact""" Builder().publish_artifacts(stack)