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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for netcfg_builder-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 138622c2f5586bdc63e67ed4535036341441365cfda0a1186dc91278ad3d0c49 |
|
MD5 | 432a9d86b4f764e22fda5693e843cabf |
|
BLAKE2b-256 | c636846b0106c7a487b3efbef6a2f85a6c9950fac13d6d30c7cb5d4c54d6b7c1 |