summaryrefslogtreecommitdiff
path: root/python/vyos/validate.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-11-13 14:50:09 +0100
committerChristian Poessinger <christian@poessinger.com>2020-11-13 14:50:11 +0100
commit6962bc53fa246f3e5c081ffec5f996fcb821273b (patch)
treec5eb5ffb11cb9dd633c39e8ddafde27083e8acf1 /python/vyos/validate.py
parent943a4a5016cfc75a352bb3711b5c4c8bfe32b740 (diff)
downloadvyos-1x-6962bc53fa246f3e5c081ffec5f996fcb821273b.tar.gz
vyos-1x-6962bc53fa246f3e5c081ffec5f996fcb821273b.zip
vyos.template: provide general is_ip(v4|v6) helpers
We had two places were the is_ip, is_ipv4 and is_ipv6 helpers had been defined. All places now have been converged into vyos.template as they are used both in the Jinja2 templates and also in our scripts.
Diffstat (limited to 'python/vyos/validate.py')
-rw-r--r--python/vyos/validate.py16
1 files changed, 4 insertions, 12 deletions
diff --git a/python/vyos/validate.py b/python/vyos/validate.py
index 74b8adcfc..84a7bc2de 100644
--- a/python/vyos/validate.py
+++ b/python/vyos/validate.py
@@ -25,21 +25,10 @@ from vyos.util import cmd
# parameters with default will be left unset
# all other paramters will receive the value to check
-def is_ip(addr):
- """ Check addr if it is an IPv4 or IPv6 address """
- return is_ipv4(addr) or is_ipv6(addr)
-
-def is_ipv4(addr):
- from vyos.template import vyos_ipv4
- return vyos_ipv4(addr)
-
-def is_ipv6(addr):
- from vyos.template import vyos_ipv6
- return vyos_ipv6(addr)
-
def is_ipv6_link_local(addr):
""" Check if addrsss is an IPv6 link-local address. Returns True/False """
from ipaddress import IPv6Address
+ from vyos.template import is_ipv6
addr = addr.split('%')[0]
if is_ipv6(addr):
if IPv6Address(addr).is_link_local:
@@ -51,6 +40,7 @@ def _are_same_ip(one, two):
from socket import AF_INET
from socket import AF_INET6
from socket import inet_pton
+ from vyos.template import is_ipv4
# compare the binary representation of the IP
f_one = AF_INET if is_ipv4(one) else AF_INET6
s_two = AF_INET if is_ipv4(two) else AF_INET6
@@ -68,6 +58,7 @@ def _is_intf_addr_assigned(intf, address, netmask=''):
It can check both a single IP address (e.g. 192.0.2.1 or a assigned CIDR
address 192.0.2.1/24.
"""
+ from vyos.template import is_ipv4
# check if the requested address type is configured at all
# {
@@ -138,6 +129,7 @@ def is_subnet_connected(subnet, primary=False):
"""
from ipaddress import ip_address
from ipaddress import ip_network
+ from vyos.template import is_ipv6
# determine IP version (AF_INET or AF_INET6) depending on passed address
addr_type = netifaces.AF_INET