From: Guillermo Herrero Date: Tue, 16 Jan 2018 11:03:19 +0000 (+0100) Subject: generate_config: Add netmask jinja filter X-Git-Tag: 6.0.0~23^2 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F89%2F50689%2F5;p=pharos.git generate_config: Add netmask jinja filter - Add custom filter to convert integer prefix network mask to IP format network mask string Change-Id: I13d6a2725b93132f858b64d7f93de3a4e0dc5961 Signed-off-by: Guillermo Herrero --- diff --git a/config/utils/generate_config.py b/config/utils/generate_config.py index cf558e28..4e0d893d 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