ubi-config¶
A library for loading UBI configuration
Quick Start¶
Install ubi-config from PyPI:
pip install ubi-config
If you want to load UBI configuration from default repo, set the default url in your environment:
export DEFAULT_UBI_REPO='https://some/url/'
In your python code, simply call the function get_loader
without passing
any argument and call load
on the returned object with the configuration
file name. No matter which branch is the config file in, it will load it
for you.
from ubiconfig import get_loader
default_loader = get_loader()
config = default_loader.load("ubi7_config_file.yaml")
# the returned config is an UbiConfig instance, wraps all types of UBI configuration
modules = config.modules
module_name = modules[0].name
print(module_name)
# the returned Load object can be reused to load other configuration file in the
# same repo
config = default_loader.load("ubi8_config_file.yaml")
content_sets = config.content_sets
More Use Cases¶
Except the above usage, there are some other use cases:
Load all configuration files from a repo by
load_all
:
from ubiconfig import get_loader
loader = get_loader()
configs = loader.load_all()
# returns a list of UbiConfig objects
Load configuration files from a directory and all its subdirectories by passing a local path:
from ubiconfig import get_loader
local_loader = get_loader("/my/config/dir")
config = local_loader.load("path/to/local_ubi7_config.yaml")
ubiconfig
¶
-
ubiconfig.
get_loader
(source=None)¶ Get a Loader instance which is used to load configurations.
source
should be provided as one of the following:- URL
A URL of a remote git repo containing UBI config files. Currently, only Gitlab is supported. See Configuration git repository structure
- local path
A path to a local directory containing UBI config files. See Configuration files format
None
If none/omitted, the value of the
DEFAULT_UBI_REPO
environment variable is used. If this is unset, an exception is raised.
After the loader is constructed, it can be used to load config files when given relative paths to config files.
# use default config source >>> loader = get_loader() >>> config_ubi7 = loader.load('ubi7.yaml') >>> config_ubi7.content_sets.rpm.input # loader can be used repeatedly >>> config_ubi8 = loader.load('ubi8.yaml') # or use a local directory >>> loader = get_loader('/my/config/dir) >>> config = loader.load('path/to/configfile.yaml')
-
ubiconfig.
validate_config
(data, schema=None)¶ Validate the data according to the schema
If no schema is provided,
DEFAULT_SCHEMA
is used
-
class
ubiconfig.
UbiConfig
(cs, pkgs, mds, file_name, version)¶ Wrap all UBI related configurations Examples to access different configurations:
- Modules:
config.modules[0].whitelist[0].name
- Packages:
config.packages.whitelist[0].name config.packages.blacklist[0].name
- ContentSets:
config.content_sets.rpm.input config.content_sets.debuginfo.output
- Parameters
cs –
ContentSetsMapping
pkgs –
Packages
mds –
Modules
filename – filename used as identifier
-
classmethod
load_from_dict
(data, file_name, version=None)¶ Create new instance of UbiConfig and load it from provided dictonary with following format:
{ "modules": {}, "packages": { "include": ["package-name-.*"], "exclude": ["package-name-.*"], "arches": ["arch"] }, "content_sets": {}, }
See also
ubiconfig.config_types.content_sets.ContentSetsMapping.load_from_dict()
ubiconfig.config_types.modules.Modules.load_from_dict()
-
class
ubiconfig.
Loader
¶ Load UBI configuration.
Don’t construct instances of this class directly; use the
get_loader()
function.-
load
(file_name, version=None)¶ Load a single configuration file and return a
UbiConfig
object.The given file_name should be a relative path to a YAML file in the loader’s config source (e.g. relative path to file within a git repo or local directory).
version is an option argument to specify the version of config file to load, if it’s None, then use default, e.g. ubi7, ubi8
-
ubiconfig.config_types.packages
¶
ubiconfig.config_types.modules
¶
-
class
ubiconfig.config_types.modules.
Modules
(include)¶ group of modules
-
class
ubiconfig.config_types.modules.
Module
(name, stream, profiles=None)¶ Define a single module
ubiconfig.config_types.content_sets
¶
-
class
ubiconfig.config_types.content_sets.
ContentSetsMapping
(rpm, srpm, debuginfo)¶ - Parameters
-
classmethod
load_from_dict
(data)¶ Create instances of
ContentSetsMapping
from a dictionary- Parameters
data (dict) – dictionary with data of following format
{ "rpm": {"input": "<input_content_set>", "output":"<output_content_set>"}, "srpm": {"input": "<input_content_set>", "output":"<output_content_set>"}, "debuginfo": {"input": "<input_content_set>", "output":"<output_content_set>"} }
-
class
ubiconfig.config_types.content_sets.
Rpm
(input_content, output_content)¶ Input-output rpm content sets mapping
-
class
ubiconfig.config_types.content_sets.
Srpm
(input_content, output_content)¶ Input-output srpm content sets mapping
-
class
ubiconfig.config_types.content_sets.
Debuginfo
(input_content, output_content)¶ Input-output debuginfo content sets mapping
Configuration files format¶
Loaded configuration files has to be presented in following format
content_sets:
rpm:
output: <output-content-set>
input: <input-content-set>
srpm:
output: <output-content-set>
input: <input-content-set>
debuginfo:
output: <output-content-set>
input: <input-content-set>
arches:
- <arch-for-all-content-sets>
- <arch-for-all-content-sets>
packages:
include:
- <whitelisted-package-full-name>
- <whitelisted-package-name-regular-expresion-.*>
# Blacklist of packages to exclude
exclude:
- <whitelisted-package-full-name>
- <whitelisted-package-name-regular-expresion-.*>
modules:
include:
- name: <module-name>
stream: <module-stream>
See also load_all()
, load()
, get_loader()
Configuration git repository structure¶
When git repository as passed as source for config data to load()
or load_all()
it has to be have following structure:
- <branch-x-root-dir>:
<configuration-file-1>.yaml
<configuration-file-1>.yaml
<configuration-file-1>.yaml
<configuration-file-1>.yaml
See also: Configuration files format