Пример #1
0
def apply_yaml_file(data, filename):
    """Applies changes from a YAML file to configuration

    :param data: configuration datastructure
    :param filename: name of the YAML file, - is taken to mean standard input
    :returns tuple of human readable and parsed datastructure after changes
    """
    changed_data = copy.deepcopy(data)

    if filename == '-':
        new_options = yaml.safe_load(sys.stdin)
    else:
        with open(filename) as fd:
            new_options = yaml.safe_load(fd)

    patch_config(changed_data, new_options)

    return format_config_for_editing(changed_data), changed_data
Пример #2
0
def apply_yaml_file(data, filename):
    """Applies changes from a YAML file to configuration

    :param data: configuration datastructure
    :param filename: name of the YAML file, - is taken to mean standard input
    :returns tuple of human readable and parsed datastructure after changes
    """
    changed_data = copy.deepcopy(data)

    if filename == '-':
        new_options = yaml.safe_load(sys.stdin)
    else:
        with open(filename) as fd:
            new_options = yaml.safe_load(fd)

    patch_config(changed_data, new_options)

    return format_config_for_editing(changed_data), changed_data
Пример #3
0
 def do_PATCH_config(self):
     request = self._read_json_content()
     if request:
         cluster = self.server.patroni.ha.dcs.get_cluster()
         data = cluster.config.data.copy()
         if patch_config(data, request):
             value = json.dumps(data, separators=(',', ':'))
             if not self.server.patroni.ha.dcs.set_config_value(value, cluster.config.index):
                 return self.send_error(409)
         self._write_json_response(200, data)
Пример #4
0
 def do_PATCH_config(self):
     request = self._read_json_content()
     if request:
         cluster = self.server.patroni.dcs.get_cluster()
         data = cluster.config.data.copy()
         if patch_config(data, request):
             value = json.dumps(data, separators=(',', ':'))
             if not self.server.patroni.dcs.set_config_value(value, cluster.config.index):
                 return self.send_error(409)
         self._write_json_response(200, data)
Пример #5
0
    def _load_config_path(self, path):
        """
        If path is a file, loads the yml file pointed to by path.
        If path is a directory, loads all yml files in that directory in alphabetical order
        """
        if os.path.isfile(path):
            files = [path]
        elif os.path.isdir(path):
            files = [os.path.join(path, f) for f in sorted(os.listdir(path))
                     if (f.endswith('.yml') or f.endswith('.yaml')) and os.path.isfile(os.path.join(path, f))]
        else:
            logger.error('config path %s is neither directory nor file', path)
            raise ConfigParseError('invalid config path')

        overall_config = {}
        for fname in files:
            with open(fname) as f:
                config = yaml.safe_load(f)
                patch_config(overall_config, config)
        return overall_config
Пример #6
0
 def _load_config_file(self):
     """Loads config.yaml from filesystem and applies some values which were set via ENV"""
     with open(self._config_file) as f:
         config = yaml.safe_load(f)
         patch_config(config, self.__environment_configuration)
         return config
Пример #7
0
 def _load_config_file(self):
     """Loads config.yaml from filesystem and applies some values which were set via ENV"""
     with open(self._config_file) as f:
         config = yaml.safe_load(f)
         patch_config(config, self.__environment_configuration)
         return config
Пример #8
0
 def _load_config_file(self):
     """Loads config.yaml from filesystem and applies some values which were set via ENV"""
     config = self._load_config_path(self._config_file)
     patch_config(config, self.__environment_configuration)
     return config