config

Config module.

class homer.config.HierarchicalConfig(base_path: str, private_base_path: str = '')[source]

Bases: object

Load configuration with hierarchical override based on role, site and device.

Initialize the instance.

Parameters
  • base_path (str) -- the base path from where the configuration files should be loaded. The configuration files that will be loaded, if existing, are: - common.yaml: common key:value pairs - roles.yaml: one key for each role with key:value pairs of role-specific configuration - sites.yaml: one key for each site with key:value pairs of role-specific configuration

  • private_base_path (str, optional) -- the base path from where the private configuration files should be loaded, with the same structure of the above base_path argument. If existing, private configuration files cannot have top level keys in common with the public configuration.

get(device: homer.devices.Device) → Dict[source]

Get the generated configuration for a specific device instance with all the overrides resolved.

Parameters

device (homer.devices.Device) -- the device instance.

Raises

homer.exceptions.HomerError -- if any top level key is present in both the private and public configuration.

Returns

the generated device-specific configuration dictionary. The override order is: common, role, site, device. Public and private configuration are merged together.

Return type

dict

homer.config.load_yaml_config(config_file: str) → Dict[source]

Parse a YAML config file and return it.

Parameters

config_file (str) -- the path of the configuration file.

Returns

the parsed config or an empty dictionary if the file doesn't exists.

Return type

dict

Raises

HomerError -- if failed to load the configuration.