rebuilt YAML version
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
import pprint
|
||||||
|
import os
|
||||||
|
|
||||||
|
from yaml import safe_load
|
||||||
|
try:
|
||||||
|
from yaml import CLoader as Loader
|
||||||
|
except ImportError:
|
||||||
|
from yaml import Loader
|
||||||
|
|
||||||
|
def main(args: list) -> None:
|
||||||
|
template_filepath = args.template
|
||||||
|
input_filepath = args.input
|
||||||
|
output_filepath = args.output
|
||||||
|
|
||||||
|
with open(input_filepath, 'r') as file:
|
||||||
|
devices = safe_load(file)
|
||||||
|
|
||||||
|
template_path = os.path.dirname(os.path.abspath(template_filepath))
|
||||||
|
template_filename = os.path.basename(template_filepath)
|
||||||
|
|
||||||
|
env = Environment(loader=FileSystemLoader(template_path))
|
||||||
|
template = env.get_template(template_filename)
|
||||||
|
|
||||||
|
#Path("./output").mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
### Specify output file - current write to script working directory
|
||||||
|
#filename = "./output/bdr_output.config"
|
||||||
|
|
||||||
|
### open output file mode="w" for create/truncate
|
||||||
|
output = open(output_filepath, mode="w", encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
for host, keys in devices.items():
|
||||||
|
device = "{"
|
||||||
|
for key, value in keys.items():
|
||||||
|
device += "'{}':'{}', ".format(key,value)
|
||||||
|
device += "'hostname':'{}' }}".format(host)
|
||||||
|
#pprint.pprint(device)
|
||||||
|
|
||||||
|
device_dict = eval(device)
|
||||||
|
#pprint.pprint(device_dict)
|
||||||
|
content = template.render( device_dict )
|
||||||
|
|
||||||
|
#print('{}\n'.format(content))
|
||||||
|
output.write('{}\n'.format(content))
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Arguments for '
|
||||||
|
'Config_builder.py')
|
||||||
|
parser.add_argument('-template',
|
||||||
|
help='Template config with JINJA markup',
|
||||||
|
required=True
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument('-input',
|
||||||
|
help='YAML file with devices and config variables',
|
||||||
|
required=True
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument('-output',
|
||||||
|
help='Output File',
|
||||||
|
required=True
|
||||||
|
)
|
||||||
|
|
||||||
|
custom_args = parser.parse_known_args()[0]
|
||||||
|
|
||||||
|
main(custom_args)
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
set devices device {{hostname}} config community-set 12684-SITE-COMMUNITY set 12684:40{{SiteCode}}3
|
||||||
|
set devices device {{hostname}} config community-set 12684-REGION-COMMUNITY set 12684:40{{RegionCode}}3
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "#L-CTN Roaming Prefixes"
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "10.194.0.0/16 le 29"
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "10.195.0.0/16 le 32"
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "10.196.0.0/16 le 32"
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "212.165.224.0/20 le 32"
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "210.5.255.0/24 le 32"
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "216.236.192.0/19 le 32"
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "216.226.228.0/24 le 32"
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "64.110.160.0/19 le 32"
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "216.252.128.0/20 le 32"
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "103.157.76.0/24 le 32"
|
||||||
|
set devices device {{hostname}} config prefix-set PL-ROAMING-BGP-IP set "212.165.160.0/20 le 32"
|
||||||
|
set devices device {{hostname}} config prefix-set DEFAULT set 0.0.0.0/0
|
||||||
|
set devices device {{hostname}} config route-policy V1698_IN value " if destination in DEFAULT then\r\n drop\r\n elseif destination in PL-ROAMING-BGP-IP then\r\n set community 12684-SITE-COMMUNITY additive\r\n set community 12684-REGION-COMMUNITY additive\r\n set community SITE-COMMUNITY additive\r\n endif\r\n"
|
||||||
@@ -23,11 +23,13 @@ set services infra-crt {{device}} interface loopback-interface lo0 {{unit["name"
|
|||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
|
{#-
|
||||||
set services infra-crt {{device}} isis
|
set services infra-crt {{device}} isis
|
||||||
set services infra-crt {{device}} ldp
|
set services infra-crt {{device}} ldp
|
||||||
set services infra-crt {{device}} rsvp
|
set services infra-crt {{device}} rsvp
|
||||||
set services infra-crt {{device}} mpls-te
|
set services infra-crt {{device}} mpls-te
|
||||||
set services infra-crt {{device}} service-policy
|
set services infra-crt {{device}} service-policy
|
||||||
|
#}
|
||||||
|
|
||||||
{# Aggregate-interface declaration - protocol declaration for AEs is same as standard core-interfaces #}
|
{# Aggregate-interface declaration - protocol declaration for AEs is same as standard core-interfaces #}
|
||||||
{%- for key,aggregate_interface in interfaces["aggregate-interface"].items() %}
|
{%- for key,aggregate_interface in interfaces["aggregate-interface"].items() %}
|
||||||
|
|||||||
Reference in New Issue
Block a user