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, default: '') -- 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:

common, role, site, device. Public and private configuration are merged together.

Return type:

The generated device-specific configuration dictionary. The override order is

homer.config.ip_address_constructor(loader: yaml.loader.SafeLoader, node: yaml.nodes.ScalarNode) str | ipaddress.IPv4Address | ipaddress.IPv6Address[source]

Casts a string into a ipaddress.ip_address object.

Parameters:
  • loader (yaml.loader.SafeLoader) -- YAML loaded on which to apply the constructor.

  • node (yaml.nodes.ScalarNode) -- string to be casted.

Return type:

typing.Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]

Returns:

An IPv4 or IPv6 Network or Interface object if able to convert it, the original string otherwise.

homer.config.ip_network_constructor(loader: yaml.loader.SafeLoader, node: yaml.nodes.ScalarNode) str | ipaddress.IPv4Network | ipaddress.IPv6Network | ipaddress.IPv4Interface | ipaddress.IPv6Interface[source]

Casts a string into a ipaddress.ip_network or ip_interface object.

Parameters:
  • loader (yaml.loader.SafeLoader) -- YAML loaded on which to apply the constructor.

  • node (yaml.nodes.ScalarNode) -- string to be casted.

Return type:

typing.Union[str, ipaddress.IPv4Network, ipaddress.IPv6Network, ipaddress.IPv4Interface, ipaddress.IPv6Interface]

Returns:

An IPv4 or IPv6 Network or Interface object if able to convert it, the original string otherwise.

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.

Return type:

typing.Dict

Returns:

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

Raises:

homer.exceptions.HomerError -- if failed to load the configuration.