]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdownaddons/cache.py
3 # Copyright 2014 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
8 from collections
import OrderedDict
11 """ This class contains methods and instance variables to cache
16 """ { <ifacename> : { 'ifindex': <index>,
20 'kind' : <kind: bridge, bond, vlan>,
21 'linkinfo' : {<attr1> : <attrval1>,
27 def get_attr(cls
, mapList
):
28 return reduce(lambda d
, k
: d
[k
], mapList
, linkCache
.links
)
31 def set_attr(cls
, mapList
, value
):
32 cls
.get_attr(mapList
[:-1])[mapList
[-1]] = value
35 def del_attr(cls
, mapList
):
37 del cls
.get_attr(mapList
[:-1])[mapList
[-1]]
42 def update_attrdict(cls
, mapList
, valuedict
):
44 cls
.get_attr(mapList
[:-1])[mapList
[-1]].update(valuedict
)
46 cls
.get_attr(mapList
[:-1])[mapList
[-1]] = valuedict
50 def append_to_attrlist(cls
, mapList
, value
):
51 cls
.get_attr(mapList
[:-1])[mapList
[-1]].append(value
)
54 def remove_from_attrlist(cls
, mapList
, value
):
56 cls
.get_attr(mapList
[:-1])[mapList
[-1]].remove(value
)
61 def check_attr(cls
, attrlist
, value
=None):
63 cachedvalue
= cls
.get_attr(attrlist
)
65 if cachedvalue
== value
:
82 print 'Dumping link cache'
83 pp
= pprint
.PrettyPrinter(indent
=4)
87 def dump_link(cls
, linkname
):
88 print 'Dumping link %s' %linkname
89 pp
= pprint
.PrettyPrinter(indent
=4)
90 pp
.pprint(cls
.links
.get(linkname
))