1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00
Roopa Prabhu 15ef32ea14 Move ifupdown2addons into ifupdown2 pacakge
Ticket: CM-3864
Reviewed By:
Testing Done: Tested build and install

open item:
- cleanup stale ifupdown2-addons package files
2014-10-09 16:02:46 -07:00

91 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 = {}
@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))