summaryrefslogtreecommitdiff
path: root/src/conf_mode
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-09-04 21:50:04 +0200
committerChristian Poessinger <christian@poessinger.com>2019-09-04 22:03:10 +0200
commit64d58eda4c1ebaa9d346d65d606d2a75694467ee (patch)
tree4f4c9b9720da401863c664a87e68ceda6a645377 /src/conf_mode
parentff34756f534bfc0f09a5ab6db0d36e1bf43546a8 (diff)
downloadvyos-1x-64d58eda4c1ebaa9d346d65d606d2a75694467ee.tar.gz
vyos-1x-64d58eda4c1ebaa9d346d65d606d2a75694467ee.zip
Python/configdict: add list_diff function to compare two lists
A list containing only unique elements not part of the other list is returned. This is usefull to check e.g. which IP addresses need to be removed from the OS.
Diffstat (limited to 'src/conf_mode')
-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
4 files changed, 17 insertions, 23 deletions
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