From 2f96eee421df9580b112bd1485624e7c9fbceca9 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 26 Jun 2020 22:42:28 +0200 Subject: 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. --- src/conf_mode/interfaces-dummy.py | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'src') 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 -- cgit v1.2.3