Prune Step1: remove addresses and set down, any interface not in the YAML config

This commit is contained in:
Pim van Pelt
2022-03-24 17:16:29 +00:00
parent 29a8bae899
commit fe2e63ac0e
2 changed files with 57 additions and 11 deletions

View File

@ -14,6 +14,10 @@
#
# -*- coding: utf-8 -*-
import logging
import config.interface as interface
import config.bondethernet as bondethernet
import config.vxlan_tunnel as vxlan_tunnel
import config.lcp as lcp
from vpp.vppapi import VPPApi
class Reconciler():
@ -22,6 +26,7 @@ class Reconciler():
self.logger.addHandler(logging.NullHandler())
self.vpp = VPPApi()
self.cfg = cfg
def readconfig(self):
return self.vpp.readconfig()
@ -38,9 +43,24 @@ class Reconciler():
def prune_addresses(self, ifname, address_list):
""" Remove all addresses from interface ifname, except those in address_list """
idx = self.vpp.config['interface_names'][ifname].sw_if_index
for a in self.vpp.config['interface_addresses'][idx]:
self.logger.info("> set interface ip address del %s %s" % (ifname, a))
def prune(self):
return False
ret = True
if not self.prune_addresses_set_interface_down():
self.logger.warning("Could not prune addresses and set interfaces down from VPP that are not in the config")
ret = False
return ret
def prune_addresses_set_interface_down(self):
for ifname in self.vpp.get_qinx_interfaces() + self.vpp.get_dot1x_interfaces() + self.vpp.get_bondethernets() + self.vpp.get_vxlan_tunnels() + self.vpp.get_phys():
if not ifname in interface.get_interfaces(self.cfg):
self.logger.info("> set interface state %s down" % ifname)
self.prune_addresses(ifname, [])
return True
def create(self):
return False

View File

@ -143,23 +143,49 @@ class VPPApi():
self.dump_phys()
self.dump_subints()
def get_qinx_interfaces(self):
qinx_subints = [self.config['interfaces'][x].interface_name for x in self.config['interfaces'] if self.config['interfaces'][x].interface_dev_type in ['dpdk','bond'] and self.config['interfaces'][x].sub_id>0 and self.config['interfaces'][x].sub_inner_vlan_id>0]
return qinx_subints
def get_dot1x_interfaces(self):
dot1x_subints = [self.config['interfaces'][x].interface_name for x in self.config['interfaces'] if self.config['interfaces'][x].interface_dev_type in ['dpdk','bond'] and self.config['interfaces'][x].sub_id>0 and self.config['interfaces'][x].sub_inner_vlan_id==0]
return dot1x_subints
def get_phys(self):
phys = [self.config['interfaces'][x].interface_name for x in self.config['interfaces'] if self.config['interfaces'][x].interface_dev_type=='dpdk' and self.config['interfaces'][x].sub_id==0]
return phys
def get_bondethernets(self):
bonds = [self.config['bondethernets'][x].interface_name for x in self.config['bondethernets']]
return bonds
def get_vxlan_tunnels(self):
vxlan_tunnels = [self.config['interfaces'][x].interface_name for x in self.config['interfaces'] if self.config['interfaces'][x].interface_dev_type in ['VXLAN']]
return vxlan_tunnels
def get_lcp_by_interface(self, sw_if_index):
for idx, lcp in self.config['lcps'].items():
if lcp.phy_sw_if_index == sw_if_index:
return lcp
return None
def dump_phys(self):
phys = [self.config['interfaces'][x].sw_if_index for x in self.config['interfaces'] if self.config['interfaces'][x].interface_dev_type=='dpdk' and self.config['interfaces'][x].sub_id==0]
for idx in phys:
iface = self.config['interfaces'][idx]
self.logger.info("%s idx=%d" % (iface.interface_name, idx))
phys = self.get_phys()
for ifname in phys:
iface = self.config['interface_names'][ifname]
self.logger.info("%s idx=%d" % (iface.interface_name, iface.sw_if_index))
def dump_subints(self):
self.logger.info("*** QinX ***")
qinx_subints = [self.config['interfaces'][x].sw_if_index for x in self.config['interfaces'] if self.config['interfaces'][x].interface_dev_type in ['dpdk','bond'] and self.config['interfaces'][x].sub_id>0 and self.config['interfaces'][x].sub_inner_vlan_id>0]
for idx in qinx_subints:
iface = self.config['interfaces'][idx]
subints = self.get_qinx_interfaces()
for ifname in subints:
iface = self.config['interfaces_names'][ifname]
self.logger.info("%s idx=%d encap=%s" % (iface.interface_name, idx, self.get_encapsulation(iface)))
self.logger.info("*** .1q/.1ad ***")
subints = [self.config['interfaces'][x].sw_if_index for x in self.config['interfaces'] if self.config['interfaces'][x].interface_dev_type in ['dpdk','bond'] and self.config['interfaces'][x].sub_id>0 and self.config['interfaces'][x].sub_inner_vlan_id==0]
for idx in subints:
iface = self.config['interfaces'][idx]
subints = self.get_dot1x_interfaces()
for ifname in subints:
iface = self.config['interface_names'][ifname]
self.logger.info("%s idx=%d encap=%s" % (iface.interface_name, idx, self.get_encapsulation(iface)))
def dump_bridgedomains(self):