templates

Templates module.

class homer.templates.DeviceConfigurationBase(config: dict)[source]

Bases: ABC

abstract A base class for all the device configurations.

Initialize the instance.

Parameters:

config (dict) -- the generated configuration.

property config: dict

Return the configuration in a format defined by the renderer called.

class homer.templates.JinjaDeviceConfiguration(config: dict)[source]

Bases: DeviceConfigurationBase

The device configuration returned as a string combining the ACLs and other config.

Initialize the instance.

Parameters:

config (dict) -- the generated configuration.

class homer.templates.JinjaRenderer(base_path: str, base_private_path: str = '')[source]

Bases: RendererBase

Load and render templates using Jinja.

Initialize the instance.

Parameters:
  • base_path (str) -- the base path to initialize the Jinja2 environment with. All templates path must be relative to this base path.

  • base_private_path (str, optional) -- a secondary base path to initialize the Jinja2 environment with. Templates that are not found in base_path will be looked up in this secondary private location.

render(template_name: str, data: Mapping, acls: list) homer.templates.DeviceConfigurationBase[source]

Render a template with the given data.

Parameters:
  • template_name (str) -- the name of the template to load without the file extension.

  • data (dict) -- the dictionary of variables to pass to Jinja2 for replacement.

  • acls (list) -- a list of ACLs to configure on the device, in a Junos specific format.

Raises:

homer.exceptions.HomerError -- on error.

Returns:

the rendered template on success. None: on failure.

Return type:

str

subdir: str = 'templates'

The base path sub-directory where the configuration bits are.

class homer.templates.PythonRenderer(base_path: str, base_private_path: str = '')[source]

Bases: RendererBase

Generate the configuration using Python modules.

Initialize the instance.

Parameters:
  • base_path (str) -- the base path where the configuration data is.

  • base_private_path (str, optional) -- a secondary private base path where the configuration data is. If things are not found in base_path they will be looked up in this secondary private location.

render(template_name: str, data: Mapping, acls: list) homer.templates.DeviceConfigurationBase[source]

Render a template with the given data.

Parameters:
  • template_name (str) -- the name of the template to load without the file extension.

  • data (dict) -- the dictionary of variables to pass to the JSON-RPC modules.

  • acls (list) -- a list of ACLs to configure on the device, in a Nokia SRL specific format.

Raises:

homer.exceptions.HomerError -- on error.

Returns:

the rendered template on success.

Return type:

dict

subdir: str = 'modules'

The base path sub-directory where the configuration bits are.

class homer.templates.RendererBase(base_path: str, base_private_path: str = '')[source]

Bases: ABC

abstract Base class for the configuration renderers.

Initialize the instance.

Parameters:
  • base_path (str) -- the base path where the configuration data is.

  • base_private_path (str, optional) -- a secondary private base path where the configuration data is. If things are not found in base_path they will be looked up in this secondary private location.

abstract render(template_name: str, data: Mapping, acls: list) homer.templates.DeviceConfigurationBase[source]

Render a template with the given data.

Parameters:
  • template_name (str) -- the name of the template to load without the file extension.

  • data (dict) -- the dictionary of variables available for the configuration.

  • acls (list) -- a list of ACLs to configure on the device, in a vendor specific format.

Raises:

homer.exceptions.HomerError -- on error.

Returns:

the rendered template on success. None: on failure.

Return type:

str

subdir: str

The base path sub-directory where the configuration bits are.