diff options
author | Jernej Jakob <jernej.jakob@gmail.com> | 2020-05-03 20:59:35 +0200 |
---|---|---|
committer | Jernej Jakob <jernej.jakob@gmail.com> | 2020-05-04 22:59:39 +0200 |
commit | 1c93e3895787641a207d09c562f2703fddc77b8f (patch) | |
tree | b1b666f05d80edb4366a6f89d618c3fa53f900c5 /python/vyos/validate.py | |
parent | 5ac80802197e1b5c17db96580b004391bde47bf2 (diff) | |
download | vyos-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/vyos/validate.py')
-rw-r--r-- | python/vyos/validate.py | 22 |
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 |