diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-11-01 10:46:46 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-11-01 13:51:44 +0100 |
commit | bb76575715682594d4d6d73d8b9e87692bdc6841 (patch) | |
tree | 8c68a41f00708bcd1fdecdd967308e0edcbfe58c /python | |
parent | 68c97eed91204904b7b2314dd9b357069db4eda5 (diff) | |
download | vyos-1x-bb76575715682594d4d6d73d8b9e87692bdc6841.tar.gz vyos-1x-bb76575715682594d4d6d73d8b9e87692bdc6841.zip |
openvpn: T2994: remove workarounds for individual ipv4 and ipv6 keys
Remove workaround which split (local|remote)_address and also subnet keys into
individual keys for the assigned IP address family (4/6).
During template rendering check IP version by introducing new ipv4 and ipv6
Jinja2 filters {% if foo | ipv4 %} or {% if bar | ipv6 %} options.
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/template.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py index 1f1ddc000..621be0695 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -16,7 +16,6 @@ import functools import os -from ipaddress import ip_network from jinja2 import Environment from jinja2 import FileSystemLoader from vyos.defaults import directories @@ -131,6 +130,7 @@ def vyos_address_from_cidr(text): Example: 192.0.2.0/24 -> 192.0.2.0, 2001:db8::/48 -> 2001:db8:: """ + from ipaddress import ip_network return str(ip_network(text).network_address) @@ -140,4 +140,17 @@ def vyos_netmask_from_cidr(text): Example: 192.0.2.0/24 -> 255.255.255.0, 2001:db8::/48 -> ffff:ffff:ffff:: """ + from ipaddress import ip_network return str(ip_network(text).netmask) + +@register_filter("ipv4") +def vyos_ipv4(text): + """ Filter IP address, return True on IPv4 address, False otherwise """ + from ipaddress import ip_interface + return ip_interface(text).version == 4 + +@register_filter("ipv6") +def vyos_ipv6(text): + """ Filter IP address, return True on IPv6 address, False otherwise """ + from ipaddress import ip_interface + return ip_interface(text).version == 6 |