From d3ac208e936caa172c575c953d3e8582286f70ef Mon Sep 17 00:00:00 2001
From: Jernej Jakob <jernej.jakob@gmail.com>
Date: Sun, 3 May 2020 21:01:50 +0200
Subject: bonding: T2241: disallow adding interfaces with addresses to bond

---
 src/conf_mode/interfaces-bonding.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/conf_mode/interfaces-bonding.py b/src/conf_mode/interfaces-bonding.py
index 7681a8c71..ec9e0bb11 100755
--- a/src/conf_mode/interfaces-bonding.py
+++ b/src/conf_mode/interfaces-bonding.py
@@ -25,6 +25,7 @@ from vyos.ifconfig_vlan import apply_vlan_config, verify_vlan_config
 from vyos.configdict import list_diff, intf_to_dict, add_to_dict
 from vyos.config import Config
 from vyos.util import call, cmd
+from vyos.validate import has_address_configured
 from vyos import ConfigError
 
 default_config_data = {
@@ -213,9 +214,10 @@ def verify(bond):
                                   'belongs to {}'.format(intf, tmp))
 
         # can not add interfaces with an assigned address to a bond
-        if conf.exists('interfaces ethernet ' + intf + ' address'):
-            raise ConfigError('can not enslave interface {} which has an address ' \
-                              'assigned'.format(intf))
+        if has_address_configured(conf, intf):
+            raise ConfigError((
+                f'Cannot add interface "{intf}" to bond "{bond["intf"]}", '
+                f'it has an address assigned!'))
 
         # bond members are not allowed to be bridge members, too
         for tmp in conf.list_nodes('interfaces bridge'):
-- 
cgit v1.2.3