Example #1
0
    def run(self):
        """For each file in noseOfYeti/specs, output nodes to represent each spec file"""
        with hp.a_temp_file() as fle:
            fle.write(dedent("""
                ---
                environments: { dev: {account_id: "123"} }
                stacks: { app: {} }
            """).encode('utf-8'))
            fle.seek(0)
            collector = Collector()
            collector.prepare(fle.name, {'bespin': {'extra': ""}, "command": None, "bash": None})

        section = nodes.section()
        section['ids'].append("available-tasks")

        title = nodes.title()
        title += nodes.Text("Default tasks")
        section += title

        for name, task in sorted(collector.configuration['task_finder'].tasks.items(), key=lambda x: len(x[0])):

            lines = [name] + ["  {0}".format(line.strip()) for line in task.description.split('\n')]
            viewlist = ViewList()
            for line in lines:
                viewlist.append(line, name)
            self.state.nested_parse(viewlist, self.content_offset, section)

        return [section]
Example #2
0
    def execute(self, args, extra_args, cli_args, logging_handler):
        collector = Collector(configuration_file=args.bespin_config.name)
        collector.configuration["$@"] = extra_args

        if "term_colors" in collector.configuration:
            self.setup_logging_theme(logging_handler, colors=collector.configuration["term_colors"])

        collector.prepare(cli_args)
        collector.configuration["task_runner"](collector.configuration["bespin"].chosen_task)
Example #3
0
    def execute(self, args_obj, args_dict, extra_args, logging_handler):
        collector = Collector()
        args_dict["bespin"]["extra"] = extra_args

        collector.prepare(args_obj.bespin_config.name, args_dict)
        if "term_colors" in collector.configuration:
            self.setup_logging_theme(logging_handler, colors=collector.configuration["term_colors"])

        collector.configuration["task_runner"](collector.configuration["bespin"].chosen_task)
Example #4
0
    def execute(self, args_obj, args_dict, extra_args, logging_handler):
        collector = Collector()
        args_dict["bespin"]["extra"] = extra_args

        collector.prepare(args_obj.bespin_config.name, args_dict)
        if "term_colors" in collector.configuration:
            self.setup_logging_theme(
                logging_handler, colors=collector.configuration["term_colors"])

        collector.configuration["task_runner"](
            collector.configuration["bespin"].chosen_task)
Example #5
0
    def run(self):
        """For each file in noseOfYeti/specs, output nodes to represent each spec file"""
        with hp.a_temp_file() as fle:
            fle.write(
                dedent("""
                ---
                environments: { dev: {account_id: "123"} }
                stacks: { app: {} }
            """).encode('utf-8'))
            fle.seek(0)
            collector = Collector()
            collector.prepare(fle.name, {
                'bespin': {
                    'extra': ""
                },
                "command": None,
                "bash": None
            })

        section = nodes.section()
        section['ids'].append("available-tasks")

        title = nodes.title()
        title += nodes.Text("Default tasks")
        section += title

        for name, task in sorted(
                collector.configuration['task_finder'].tasks.items(),
                key=lambda x: len(x[0])):

            lines = [name] + [
                "  {0}".format(line.strip())
                for line in task.description.split('\n')
            ]
            viewlist = ViewList()
            for line in lines:
                viewlist.append(line, name)
            self.state.nested_parse(viewlist, self.content_offset, section)

        return [section]
Example #6
0
    def run(self, collector, stack, available_actions, tasks, **extras):
        """Run this task"""
        task_action = available_actions[self.action]
        self.set_description(available_actions)
        configuration = collector.configuration.wrapped()

        if self.options:
            if stack:
                configuration.update({"stacks": {stack: self.options}})
            else:
                configuration.update(self.options)

        configuration.update(configuration["args_dict"].as_dict(),
                             source="<cli>")

        if self.overrides:
            overrides = {}
            for key, val in self.overrides.items():
                overrides[key] = val
                if isinstance(val, MergedOptions):
                    overrides[key] = dict(val.items())
            configuration.update(overrides)

        if task_action.needs_stack:
            environment = configuration["bespin"].environment
            if not environment:
                raise BadOption("Please specify an environment",
                                available=list(
                                    configuration.get("environments",
                                                      {}).keys()))
            if configuration["environments"].get(environment) is None:
                raise BadOption(
                    "No configuration found for specified environment",
                    environment=environment,
                    available=list(configuration["environments"].keys()))

            self.find_stack(stack, configuration)
            stack = configuration["stacks"][stack]

        bespin = configuration["bespin"]
        info = {"done": False}

        def set_credentials():
            if info["done"]:
                return
            info["done"] = True

            environment = configuration["bespin"].environment
            if not environment:
                raise BadOption("Please specify an environment",
                                available=list(
                                    configuration["environments"].keys()))
            if environment not in configuration["environments"]:
                raise BadOption("Please specify a defined environment",
                                available=list(
                                    configuration["environments"].keys()))
            region = configuration["environments"][environment].region

            no_assume_role = configuration["bespin"].no_assume_role
            if self.options and "no_assume_role" in self.options:
                no_assume_role = self.options["no_assume_role"]
            assume_role = NotSpecified if no_assume_role else configuration[
                "bespin"].assume_role

            credentials = Credentials(
                region, configuration["environments"][environment].account_id,
                assume_role)
            bespin.credentials = credentials

        bespin.set_credentials = set_credentials
        if task_action.needs_credentials:
            bespin.set_credentials()

        artifact = configuration["bespin"].chosen_artifact or None
        if task_action.needs_artifact and not artifact:
            raise BadOption("Please specify an artifact")

        from bespin.collector import Collector
        new_collector = Collector()
        new_collector.configuration = configuration
        new_collector.configuration_file = collector.configuration_file
        return task_action(collector,
                           stack=stack,
                           artifact=artifact,
                           tasks=tasks,
                           **extras)
Example #7
0
    def run(self, collector, stack, available_actions, tasks, **extras):
        """Run this task"""
        task_action = available_actions[self.action]
        self.set_description(available_actions)
        configuration = collector.configuration.wrapped()

        if self.options:
            if stack:
                configuration.update({"stacks": {stack: self.options}})
            else:
                configuration.update(self.options)

        configuration.update(configuration["cli_args"].as_dict(), source="<cli>")

        if self.overrides:
            overrides = {}
            for key, val in self.overrides.items():
                overrides[key] = val
                if isinstance(val, MergedOptions):
                    overrides[key] = dict(val.items())
            configuration.update(overrides)

        if task_action.needs_stack:
            environment = configuration["bespin"].environment
            if not environment:
                raise BadOption("Please specify an environment", available=list(configuration.get("environments", {}).keys()))
            if configuration["environments"].get(environment) is None:
                raise BadOption("No configuration found for specified environment", environment=environment, available=list(configuration["environments"].keys()))

            self.find_stack(stack, configuration)
            stack = configuration["stacks"][stack]

        bespin = configuration["bespin"]
        info = {"done": False}
        def set_credentials():
            if info["done"]:
                return
            info["done"] = True

            environment = configuration["bespin"].environment
            if not environment:
                raise BadOption("Please specify an environment", available=list(configuration["environments"].keys()))
            if environment not in configuration["environments"]:
                raise BadOption("Please specify a defined environment", available=list(configuration["environments"].keys()))
            region = configuration["environments"][environment].region

            no_assume_role = configuration["bespin"].no_assume_role
            if self.options and "no_assume_role" in self.options:
                no_assume_role = self.options["no_assume_role"]
            assume_role = NotSpecified if no_assume_role else configuration["bespin"].assume_role

            credentials = Credentials(
                  region
                , configuration["environments"][environment].account_id
                , assume_role
                )
            bespin.credentials = credentials
        bespin.set_credentials = set_credentials
        if task_action.needs_credentials:
            bespin.set_credentials()

        artifact = configuration["bespin"].chosen_artifact or None
        if task_action.needs_artifact and not artifact:
            raise BadOption("Please specify an artifact")

        from bespin.collector import Collector
        new_collector = Collector()
        new_collector.configuration = configuration
        new_collector.configuration_file = collector.configuration_file
        return task_action(collector, stack=stack, artifact=artifact, tasks=tasks, **extras)