Skip to main content

Network Config Builder

Project description

Network Config Builder

As a network automation engineer I need to template build network device configurations. I want to use Jinja2 as my templating language. I want to be able to use the Jinaj include directive so that I can include relative template files. I want the ability to dynamically create variable collections for each host using native Python, and have a tool that correlates these variables based on a priority ordering.

This repostory provides such a tool.

$ netcfg-builder --template <template-file.j2> -e <extra-variables>

When -e <varname>=<value>, then the variable name varname is defined with the value <value>.

For example, define a varialbe called varsdir that has the value /usr/local/myvars.

$ netcfg-build --template <template-file> -e vardirs=/usr/local/lib/myvars

When <extra-varialbes> is a .py file, that file needs to decorator functions; each of these functions will be called in priority order. Priority 0 is first.

For example:

from pathlib import Path
from netcfg_builder.variables import ingest, load_directory

@ingest(0)
def load_variables(tvars: dict, **extras):
    varsdir = Path(extras['varsdir'])
    tvars.update(load_directory(varsdir.joinpath('common')))
    tvars.update(load_directory(varsdir.joinpath(extras['hostname'])))

The first parameter, tvars to the decordated function is current set of template variables. The second parameter, **extras are any extra variables defined on the command line.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netcfg-builder-0.3.0.tar.gz (6.3 kB view hashes)

Uploaded Source

Built Distribution

netcfg_builder-0.3.0-py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page