diff options
author | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2018-01-22 16:49:34 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-01-22 16:49:34 +0000 |
commit | 9e19db65bb0e9e25b4d059bd58a0ff433badd3bc (patch) | |
tree | e64aa8eaae36a331b0c16293d912bd6358deec2a /config/utils | |
parent | 4815ccae3e8552f698c265a4cb0607f6ca14bdd4 (diff) | |
parent | 7933d0ed6781f78776100ee1f5293fb049dfcec0 (diff) |
Merge "generate_config: Add netmask jinja filter"
Diffstat (limited to 'config/utils')
-rwxr-xr-x | config/utils/generate_config.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/config/utils/generate_config.py b/config/utils/generate_config.py index d9358223..5dbdb7d1 100755 --- a/config/utils/generate_config.py +++ b/config/utils/generate_config.py @@ -39,6 +39,15 @@ def ipaddr_index(base_address, index): base_address_str = str(base_address) return ipaddress.ip_address(base_address_str) + int(index) +# Custom filter to transform a prefix netmask to IP address format netmask +def netmask(prefix): + """Get netmask from prefix length integer""" + try: + prefix_str = unicode(prefix) + except NameError as ex: + prefix_str = str(prefix) + return ipaddress.IPv4Network("1.0.0.0/"+prefix_str).netmask + # Custom filter to convert between processor architecture # (as reported by $(uname -m)) and DPKG-style architecture def dpkg_arch(arch, to_dpkg=True): @@ -50,6 +59,7 @@ def dpkg_arch(arch, to_dpkg=True): ENV = Environment(loader=FileSystemLoader(os.path.dirname(ARGS.jinja2))) ENV.filters['ipaddr_index'] = ipaddr_index +ENV.filters['netmask'] = netmask ENV.filters['dpkg_arch'] = dpkg_arch # Run `eyaml decrypt` on the whole file, but only if PDF data is encrypted |