summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJernej Jakob <jernej.jakob@gmail.com>2020-05-03 20:59:35 +0200
committerJernej Jakob <jernej.jakob@gmail.com>2020-05-04 22:59:39 +0200
commit1c93e3895787641a207d09c562f2703fddc77b8f (patch)
treeb1b666f05d80edb4366a6f89d618c3fa53f900c5 /python
parent5ac80802197e1b5c17db96580b004391bde47bf2 (diff)
downloadvyos-1x-1c93e3895787641a207d09c562f2703fddc77b8f.tar.gz
vyos-1x-1c93e3895787641a207d09c562f2703fddc77b8f.zip
validate: T2241: add func that checks if an interface has a configured address
Diffstat (limited to 'python')
-rw-r--r--python/vyos/validate.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/python/vyos/validate.py b/python/vyos/validate.py
index eb3f8bf52..e083604c5 100644
--- a/python/vyos/validate.py
+++ b/python/vyos/validate.py
@@ -282,3 +282,25 @@ def is_member(conf, interface, intftype=None):
old_level = conf.set_level(old_level)
return ret_val
+def has_address_configured(conf, intf):
+ """
+ Checks if interface has an address configured.
+ Checks the following config nodes:
+ 'address', 'ipv6 address eui64', 'ipv6 address autoconf'
+
+ Returns True if interface has address configured, False if it doesn't.
+ """
+ from vyos.ifconfig import Section
+ ret = False
+
+ old_level = conf.get_level()
+ conf.set_level([])
+
+ intfpath = 'interfaces ' + Section.get_config_path(intf)
+ if ( conf.exists(f'{intfpath} address') or
+ conf.exists(f'{intfpath} ipv6 address autoconf') or
+ conf.exists(f'{intfpath} ipv6 address eui64') ):
+ ret = True
+
+ conf.set_level(old_level)
+ return ret