val = loader.construct_scalar(node) return env[val] def load_clients(stream): """ Loads client configurations from a YAML document stream. :param stream: YAML stream. :type stream: file :return: A dictionary of client configuration objects. :rtype: dict[unicode, dockerfabric.apiclient.DockerClientConfiguration] """ return _load_clients(stream, configuration_class=DockerClientConfiguration) def load_clients_file(filename): """ Loads client configurations from a YAML file. :param filename: YAML file name. :type filename: unicode :return: A dictionary of client configuration objects. :rtype: dict[unicode, dockerfabric.apiclient.DockerClientConfiguration] """ return _load_clients_file(filename, configuration_class=DockerClientConfiguration) yaml.add_constructor('!env_lazy', expand_env_lazy, yaml.SafeLoader) yaml.add_constructor('!env', expand_env, yaml.SafeLoader)
Substitutes a variable read from a YAML node with a MsgPack ExtType value referring to data stored in a pillar. :param loader: YAML loader. :type loader: yaml.loader.SafeLoader :param node: Document node. :type node: ScalarNode :return: Corresponding value stored in the pillar. :rtype: msgpack.ExtType """ val = loader.construct_scalar(node) return ExtType(_ext_types['pillar'], val.encode('utf-8')) def expand_grain_lazy(loader, node): """ Substitutes a variable read from a YAML node with a MsgPack ExtType value referring to data stored in a grain. :param loader: YAML loader. :type loader: yaml.loader.SafeLoader :param node: Document node. :type node: ScalarNode :return: Corresponding value stored in the grain. :rtype: msgpack.ExtType """ val = loader.construct_scalar(node) return ExtType(_ext_types['grain'], val.encode('utf-8')) yaml.add_constructor('!pillar', expand_pillar_lazy, SaltYamlSafeLoader) yaml.add_constructor('!grain', expand_pillar_lazy, SaltYamlSafeLoader)