Add first approximation of vxlan_tunnels

This commit is contained in:
Pim van Pelt
2022-03-15 22:21:36 +00:00
parent 05b3c5c157
commit 686cd45158
4 changed files with 114 additions and 1 deletions

View File

@ -29,6 +29,7 @@ from validator.loopback import validate_loopbacks
from validator.bondethernet import validate_bondethernets
from validator.interface import validate_interfaces
from validator.bridgedomain import validate_bridgedomains
from validator.vxlan_tunnel import validate_vxlan_tunnels
from yamale.validators import DefaultValidators, Validator
import ipaddress
@ -121,6 +122,12 @@ class Validator(object):
if not rv:
ret_rv = False
rv, msgs = validate_vxlan_tunnels(yaml)
if msgs:
ret_msgs.extend(msgs)
if not rv:
ret_rv = False
if ret_rv:
self.logger.debug("Semantics correctly validated")
return ret_rv, ret_msgs

57
validator/vxlan_tunnel.py Normal file
View File

@ -0,0 +1,57 @@
#
# Copyright (c) 2022 Pim van Pelt
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import logging
import validator.interface as interface
class NullHandler(logging.Handler):
def emit(self, record):
pass
def get_by_name(yaml, ifname):
""" Return the VXLAN by name, if it exists. Return None otherwise. """
try:
if ifname in yaml['vxlan_tunnels']:
return yaml['vxlan_tunnels'][ifname]
except:
pass
return None
def vni_unique(yaml, vni):
""" Return True if the VNI is unique amongst all VXLANs """
if not 'vxlan_tunnels' in yaml:
return True
ncount = 0
for ifname, iface in yaml['vxlan_tunnels'].items():
if iface['vni'] == vni:
ncount = ncount + 1
if ncount > 1:
return False
return True
def validate_vxlan_tunnels(yaml):
result = True
msgs = []
logger = logging.getLogger('vppcfg.validator')
logger.addHandler(NullHandler())
if not 'vxlan_tunnels' in yaml:
return result, msgs
for ifname, iface in yaml['vxlan_tunnels'].items():
logger.debug("vxlan_tunnel %s: %s" % (ifname, iface))
return result, msgs