From 4e1a5c7cf4213fd5617e387a2d4a6d1e9a475c54 Mon Sep 17 00:00:00 2001 From: Viacheslav Date: Fri, 2 Jul 2021 13:43:27 +0000 Subject: conntrack-sync: T3535: Rewrite conf and op modes to XML python style --- python/vyos/template.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'python/vyos/template.py') diff --git a/python/vyos/template.py b/python/vyos/template.py index 527384d0b..560483581 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -121,6 +121,14 @@ def render( ################################## # Custom template filters follow # ################################## +@register_filter('ip_from_cidr') +def ip_from_cidr(prefix): + """ Take an IPv4/IPv6 CIDR host and strip cidr mask. + Example: + 192.0.2.1/24 -> 192.0.2.1, 2001:db8::1/64 -> 2001:db8::1 + """ + from ipaddress import ip_interface + return str(ip_interface(prefix).ip) @register_filter('address_from_cidr') def address_from_cidr(prefix): @@ -316,3 +324,9 @@ def is_file(filename): if os.path.exists(filename): return os.path.isfile(filename) return False + +@register_filter('get_ipv4') +def get_ipv4(interface): + """ Get interface IPv4 addresses""" + from vyos.ifconfig import Interface + return Interface(interface).get_addr_v4() -- cgit v1.2.3