1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00
Roopa Prabhu 05ac52f075 addons: vrf: redo iproute2 vrf interface map handling
Ticket: CM-10188, CM-10061
Reviewed By: dsa, nikhil, julien
Testing Done: Tested static routes with vrf names for tables

This patch does the following:
- if a single vrf device is present in the config,
builds the vrf map by reading vrf interfaces from the kernel (with
existing link cache. Builds a shadow vrf only attribute cache)
- reads existing table map and adjusts it if required
- main change is the iproute2 map file on disk is updated
immediately on vrf creation, so that static routes used along with the
vrf slaves can use the vrf name for the table. This also helps dhclient dns
hook script which may use mgmt table name directly.
- cleans up default routes on down

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
2016-03-31 21:56:39 -07:00

93 lines
2.5 KiB
Python

#!/usr/bin/python
#
# Copyright 2014 Cumulus Networks, Inc. All rights reserved.
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
#
import pprint
from collections import OrderedDict
class linkCache():
""" This class contains methods and instance variables to cache
link info """
_shared_state = {}
""" { <ifacename> : { 'ifindex': <index>,
'mtu': <mtu>,
'state' : <state>',
'flags' : <flags>,
'kind' : <kind: bridge, bond, vlan>,
'linkinfo' : {<attr1> : <attrval1>,
<attr2> : <attrval2>,
<ports> : {
} """
links = {}
vrfs = {}
@classmethod
def get_attr(cls, mapList):
return reduce(lambda d, k: d[k], mapList, linkCache.links)
@classmethod
def set_attr(cls, mapList, value):
cls.get_attr(mapList[:-1])[mapList[-1]] = value
@classmethod
def del_attr(cls, mapList):
try:
del cls.get_attr(mapList[:-1])[mapList[-1]]
except:
pass
@classmethod
def update_attrdict(cls, mapList, valuedict):
try:
cls.get_attr(mapList[:-1])[mapList[-1]].update(valuedict)
except:
cls.get_attr(mapList[:-1])[mapList[-1]] = valuedict
pass
@classmethod
def append_to_attrlist(cls, mapList, value):
cls.get_attr(mapList[:-1])[mapList[-1]].append(value)
@classmethod
def remove_from_attrlist(cls, mapList, value):
try:
cls.get_attr(mapList[:-1])[mapList[-1]].remove(value)
except:
pass
@classmethod
def check_attr(cls, attrlist, value=None):
try:
cachedvalue = cls.get_attr(attrlist)
if value:
if cachedvalue == value:
return True
else:
return False
elif cachedvalue:
return True
else:
return False
except:
return False
@classmethod
def invalidate(cls):
cls.links = {}
@classmethod
def dump(cls):
print 'Dumping link cache'
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(cls.links)
@classmethod
def dump_link(cls, linkname):
print 'Dumping link %s' %linkname
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(cls.links.get(linkname))