summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/vyos/configdict.py8
-rwxr-xr-xsrc/conf_mode/interface-bonding.py11
-rwxr-xr-xsrc/conf_mode/interface-bridge.py12
-rwxr-xr-xsrc/conf_mode/interface-dummy.py10
-rwxr-xr-xsrc/conf_mode/interface-loopback.py7
5 files changed, 25 insertions, 23 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py
index 157011839..a723c5322 100644
--- a/python/vyos/configdict.py
+++ b/python/vyos/configdict.py
@@ -78,3 +78,11 @@ def retrieve_config(path_hash, base_path, config):
config_hash[k][node] = retrieve_config(inner_hash, path + [node], config)
return config_hash
+
+
+def list_diff(first, second):
+ """
+ Diff two dictionaries and return only unique items
+ """
+ second = set(second)
+ return [item for item in first if item not in second]
diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py
index 03d28954d..ba4577900 100755
--- a/src/conf_mode/interface-bonding.py
+++ b/src/conf_mode/interface-bonding.py
@@ -23,6 +23,7 @@ from sys import exit
from netifaces import interfaces
from vyos.ifconfig import BondIf, EthernetIf
+from vyos.configdict import list_diff
from vyos.config import Config
from vyos import ConfigError
@@ -55,9 +56,6 @@ default_config_data = {
'vif_remove': []
}
-def diff(first, second):
- second = set(second)
- return [item for item in first if item not in second]
def get_bond_mode(mode):
if mode == 'round-robin':
@@ -77,6 +75,7 @@ def get_bond_mode(mode):
else:
raise ConfigError('invalid bond mode "{}"'.format(mode))
+
def get_ethertype(ethertype_val):
if ethertype_val == '0x88A8':
return '802.1ad'
@@ -321,7 +320,7 @@ def get_config():
# address is no longer valid and needs to be removed from the bond
eff_addr = conf.return_effective_values('address')
act_addr = conf.return_values('address')
- bond['address_remove'] = diff(eff_addr, act_addr)
+ bond['address_remove'] = list_diff(eff_addr, act_addr)
# Primary device interface
if conf.exists('primary'):
@@ -333,7 +332,7 @@ def get_config():
# interface is no longer present and needs to be removed
eff_intf = conf.list_effective_nodes('vif-s')
act_intf = conf.list_nodes('vif-s')
- bond['vif_s_remove'] = diff(eff_intf, act_intf)
+ bond['vif_s_remove'] = list_diff(eff_intf, act_intf)
if conf.exists('vif-s'):
for vif_s in conf.list_nodes('vif-s'):
@@ -347,7 +346,7 @@ def get_config():
# vif interface is no longer present and needs to be removed
eff_intf = conf.list_effective_nodes('vif')
act_intf = conf.list_nodes('vif')
- bond['vif_remove'] = diff(eff_intf, act_intf)
+ bond['vif_remove'] = list_diff(eff_intf, act_intf)
if conf.exists('vif'):
for vif in conf.list_nodes('vif'):
diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py
index 1d3587114..b165428ee 100755
--- a/src/conf_mode/interface-bridge.py
+++ b/src/conf_mode/interface-bridge.py
@@ -21,8 +21,10 @@ import os
from copy import deepcopy
from sys import exit
from netifaces import interfaces
-from vyos.config import Config
+
from vyos.ifconfig import BridgeIf, Interface
+from vyos.configdict import list_diff
+from vyos.config import Config
from vyos import ConfigError
default_config_data = {
@@ -46,10 +48,6 @@ default_config_data = {
'stp': 0
}
-def diff(first, second):
- second = set(second)
- return [item for item in first if item not in second]
-
def get_config():
bridge = deepcopy(default_config_data)
conf = Config()
@@ -137,13 +135,13 @@ def get_config():
# interfaces is no longer assigend to the bridge and thus can be removed
eff_intf = conf.list_effective_nodes('member interface')
act_intf = conf.list_nodes('member interface')
- bridge['member_remove'] = diff(eff_intf, act_intf)
+ bridge['member_remove'] = list_diff(eff_intf, act_intf)
# Determine interface addresses (currently effective) - to determine which
# address is no longer valid and needs to be removed from the bridge
eff_addr = conf.return_effective_values('address')
act_addr = conf.return_values('address')
- bridge['address_remove'] = diff(eff_addr, act_addr)
+ bridge['address_remove'] = list_diff(eff_addr, act_addr)
# Priority for this bridge
if conf.exists('priority'):
diff --git a/src/conf_mode/interface-dummy.py b/src/conf_mode/interface-dummy.py
index 03afdc668..4a1179672 100755
--- a/src/conf_mode/interface-dummy.py
+++ b/src/conf_mode/interface-dummy.py
@@ -19,8 +19,10 @@
from os import environ
from copy import deepcopy
from sys import exit
-from vyos.config import Config
+
from vyos.ifconfig import DummyIf
+from vyos.configdict import list_diff
+from vyos.config import Config
from vyos import ConfigError
default_config_data = {
@@ -32,10 +34,6 @@ default_config_data = {
'intf': ''
}
-def diff(first, second):
- second = set(second)
- return [item for item in first if item not in second]
-
def get_config():
dummy = deepcopy(default_config_data)
conf = Config()
@@ -70,7 +68,7 @@ def get_config():
# address is no longer valid and needs to be removed from the interface
eff_addr = conf.return_effective_values('address')
act_addr = conf.return_values('address')
- dummy['address_remove'] = diff(eff_addr, act_addr)
+ dummy['address_remove'] = list_diff(eff_addr, act_addr)
return dummy
diff --git a/src/conf_mode/interface-loopback.py b/src/conf_mode/interface-loopback.py
index be47324c1..e2df37655 100755
--- a/src/conf_mode/interface-loopback.py
+++ b/src/conf_mode/interface-loopback.py
@@ -18,7 +18,9 @@
from os import environ
from sys import exit
from copy import deepcopy
+
from vyos.ifconfig import LoopbackIf
+from vyos.configdict import list_diff
from vyos.config import Config
from vyos import ConfigError
@@ -29,9 +31,6 @@ default_config_data = {
'description': '',
}
-def diff(first, second):
- second = set(second)
- return [item for item in first if item not in second]
def get_config():
loopback = deepcopy(default_config_data)
@@ -62,7 +61,7 @@ def get_config():
# address is no longer valid and needs to be removed from the interface
eff_addr = conf.return_effective_values('address')
act_addr = conf.return_values('address')
- loopback['address_remove'] = diff(eff_addr, act_addr)
+ loopback['address_remove'] = list_diff(eff_addr, act_addr)
return loopback