From 1c93e3895787641a207d09c562f2703fddc77b8f Mon Sep 17 00:00:00 2001 From: Jernej Jakob Date: Sun, 3 May 2020 20:59:35 +0200 Subject: validate: T2241: add func that checks if an interface has a configured address --- python/vyos/validate.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'python') 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 -- cgit v1.2.3