summaryrefslogtreecommitdiff
path: root/src/conf_mode
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-06-26 22:42:28 +0200
committerChristian Poessinger <christian@poessinger.com>2020-06-26 23:58:31 +0200
commit2f96eee421df9580b112bd1485624e7c9fbceca9 (patch)
tree4d5aaeb887263ccdd0a17324097759db035e6831 /src/conf_mode
parent323445d7f11abb0e7c2b3c88ca631a732e62c369 (diff)
downloadvyos-1x-2f96eee421df9580b112bd1485624e7c9fbceca9.tar.gz
vyos-1x-2f96eee421df9580b112bd1485624e7c9fbceca9.zip
ifconfig: T2653: add common vyos.configverify helpers
While moving towards a general interface abstraction based on get_config_dict() and the use of vyos.ifconfig.Interfaces().update() it also makes sense, to split out common verification code to a common util file - instead of duplicating the code, which is infact one of the main forces drivind this transition. vyos.configverify will hold common functions called via verify() from our src/conf_mode scripts so we do not need to copy/paste general verifications methods.
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-xsrc/conf_mode/interfaces-dummy.py29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/conf_mode/interfaces-dummy.py b/src/conf_mode/interfaces-dummy.py
index e95635835..676211428 100755
--- a/src/conf_mode/interfaces-dummy.py
+++ b/src/conf_mode/interfaces-dummy.py
@@ -16,13 +16,16 @@
import os
-from netifaces import interfaces
from sys import exit
from vyos.config import Config
+from vyos.configverify import verify_bridge_vrf
+from vyos.configverify import verify_bridge_address
+from vyos.configverify import verify_bridge_delete
from vyos.ifconfig import DummyIf
from vyos.validate import is_member
-from vyos import ConfigError, airbag
+from vyos import ConfigError
+from vyos import airbag
airbag.enable()
def get_config():
@@ -55,27 +58,11 @@ def get_config():
def verify(dummy):
if dummy['deleted']:
- if 'is_bridge_member' in dummy.keys():
- raise ConfigError(
- 'Interface "{ifname}" cannot be deleted as it is a '
- 'member of bridge "{is_bridge_member}"!'.format(**dummy))
-
+ verify_bridge_delete(dummy)
return None
- if 'vrf' in dummy.keys():
- if dummy['vrf'] not in interfaces():
- raise ConfigError('VRF "{vrf}" does not exist'.format(**dummy))
-
- if 'is_bridge_member' in dummy.keys():
- raise ConfigError(
- 'Interface "{ifname}" cannot be both a member of VRF "{vrf}" '
- 'and bridge "{is_bridge_member}"!'.format(**dummy))
-
- # check if both keys are part of the dictionary
- if {'is_bridge_member', 'address'} <= set(dummy):
- raise ConfigError(
- f'Cannot assign address to interface "{ifname}" as it is a '
- f'member of bridge "{is_bridge_member}"!'.format(**dummy))
+ verify_bridge_vrf(dummy)
+ verify_bridge_address(dummy)
return None