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 configurationprivate_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
-
homer.config.
ip_address_constructor
(loader: yaml.constructor.BaseConstructor, node: str) → Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address][source]¶ Casts a string into a ipaddress.ip_address object.
- Parameters
loader (yaml loader) -- YAML loaded on which to apply the constructor
node -- (str): string to be casted
- Returns
an IPv4 or v6 address object str: if not possible, return the original string
- Return type
ipaddress
-
homer.config.
ip_network_constructor
(loader: yaml.constructor.BaseConstructor, node: str) → Union[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) -- YAML loaded on which to apply the constructor
node -- (str): string to be casted
- Returns
an IPv4 or v6 Network or Interface object str: if not possible, return the original string
- Return type
ipaddress
-
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
- Raises
HomerError -- if failed to load the configuration.