Configuration Container

The Configuration container is a special type of NestedAttrDict intended to store Python module and feature configurations.

Avoid confusing Python configuration with router configuration. Python configurations tends to be key value pairs that drives a particular piece of infrastructure, telling it how its behavior should be.

# Example
# -------
#   using Configuration() class

from pyats.datastructures import Configuration

# instantiating it
cfg = Configuration()

# loading some INI style config files

# load yaml style config files

# loading python entrypoints
cfg.load_entrypoint(group = '')

# Configuration({
#     'email': Configuration({
#         'smtp': Configuration({
#             'host': '',
#             'port': 25}),
#         'default_domain': ''})})


  • Configuration class inherits all the behaviors of NestedAttrDict

  • Configuration.copy() will walk the entire configuration tree, and all children Configuration nodes will be copied. (Eg - it’s a pseudo deep copy, but will only deep copy its own object type)

  • Configuration.load_cfgs(*files) accepts N INI style files. Internally it uses*files) api, and inherits all of its behavior. Returns the list of files that was loaded successfully.

    • does not raise exception if file doesn’t exist

    • the DEFAULT block in configparser is removed

    • basic data types will be typecasted into Python objects (bool/int/float/None)

  • Configuration.load_yamls(*files) accepts N yaml files. Internally performs a YAML load on each file, and saves the configuration data. The files are read from left to right, hence if any data block is repeated in the files, the right most file’s data takes precedence. Returns the list of files that was loaded successfully.

  • Configuration.load_entrypoint(group) loads a Python entrypoint group. Any loaded group data needs to return a dictionary-like data, which will get updated into this configuration object