Exemplo n.º 1
0
    def _generate_launch_order(self, reverse=False):
        if self.context.ignore_dependencies:
            return [self.command_stacks]

        graph = self.graph.filtered(self.command_stacks, reverse)
        if self.context.ignore_dependencies:
            return [self.command_stacks]

        launch_order = []
        while graph.graph:
            batch = set()
            for stack in graph:
                if graph.count_dependencies(stack) == 0:
                    batch.add(stack)
            launch_order.append(batch)

            for stack in batch:
                graph.remove_stack(stack)

        if not launch_order:
            raise ConfigFileNotFoundError(
                "No stacks detected from the given path '{}'. Valid stack paths are: {}"
                .format(self.context.command_path, self._valid_stack_paths()))

        return launch_order
Exemplo n.º 2
0
    def construct_stack(self, rel_path):
        """
        Construct a Stack object from a config path with the stack_group
        config as the base config.

        :param rel_path: A relative stack config path from the config folder.
        :type rel_path: str
        """
        if not path.isfile(path.join(self.config_folder, rel_path)):
            raise ConfigFileNotFoundError(
                "Config file not found for '{}'".format(rel_path))
        directory = path.split(rel_path)[0]
        stack_group_config = self.read(path.join(directory, "config.yaml"))
        return self._construct_stack(rel_path, stack_group_config)
Exemplo n.º 3
0
    def read(self, rel_path, base_config=None):
        """
        Reads in configuration from one or more YAML files
        within the Sceptre project folder.

        :param rel_path: Relative path to config to read.
        :type rel_path: str
        :param base_config: Base config to provide defaults.
        :type base_config: dict
        :returns: Config read from config files.
        :rtype: dict
        """
        self.logger.debug("Reading in '%s' files...", rel_path)
        directory_path, filename = path.split(rel_path)
        abs_path = path.join(self.full_config_path, rel_path)

        # Adding properties from class
        config = {
            "project_path": self.context.project_path,
            "stack_group_path": directory_path
        }

        # Adding defaults from base config.
        if base_config:
            config.update(base_config)

        # Check if file exists, but ignore config.yaml as can be inherited.
        if not path.isfile(abs_path)\
                and not filename.endswith(self.context.config_file):
            raise ConfigFileNotFoundError(
                "Config file \"{0}\" not found.".format(rel_path)
            )

        # Parse and read in the config files.
        this_config = self._recursive_read(directory_path, filename, config)

        if "dependencies" in config or "dependencies" in this_config:
            this_config['dependencies'] = \
                CONFIG_MERGE_STRATEGIES['dependencies'](
                    this_config.get("dependencies"),
                    config.get("dependencies")
            )
        config.update(this_config)

        self._check_version(config)

        self.logger.debug("Config: %s", config)
        return config
Exemplo n.º 4
0
    def __generate_execution_order(self, reverse=False):
        if self.context.ignore_dependencies:
            return [self.execute_stacks]

        graph = self.graph.filtered(self.execute_stacks, reverse)

        execute_order = []
        while graph.graph:
            batch = set()
            for stack in graph:
                if graph.count_dependencies(stack) == 0:
                    batch.add(stack)
            execute_order.append(batch)

            for stack in batch:
                graph.remove_stack(stack)

        if not execute_order:
            raise ConfigFileNotFoundError(
                "No stacks detected from the given patterns'{}'. Valid stack patterns are: {}"
                .format(self.__execute_pattern,
                        [item.id for item in self.stacks]))

        return execute_order