summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2021-08-09 13:56:42 -0500
committerGitHub <noreply@github.com>2021-08-09 13:56:42 -0500
commit3203f2a6d4958eb97f1c678ee7054a1f9c210a41 (patch)
treee89e25b7c54a5dfa9a1685c3ed3be8a9c3e16863
parent2aa75521a829712256c3c34685e60a9d36b33791 (diff)
parent852d056fbd6ab701a45258669d1eca7866360b18 (diff)
downloadvyos-1x-3203f2a6d4958eb97f1c678ee7054a1f9c210a41.tar.gz
vyos-1x-3203f2a6d4958eb97f1c678ee7054a1f9c210a41.zip
Merge pull request #958 from sever-sever/T3730
template: T3730: Add bracketize_ipv6 filter
-rw-r--r--python/vyos/template.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py
index 560483581..b58f641e1 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -139,6 +139,13 @@ def address_from_cidr(prefix):
from ipaddress import ip_network
return str(ip_network(prefix).network_address)
+@register_filter('bracketize_ipv6')
+def bracketize_ipv6(address):
+ """ Place a passed IPv6 address into [] brackets, do nothing for IPv4 """
+ if is_ipv6(address):
+ return f'[{address}]'
+ return address
+
@register_filter('netmask_from_cidr')
def netmask_from_cidr(prefix):
""" Take CIDR prefix and convert the prefix length to a "subnet mask".