]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdown2/ifupdownaddons/cache.py
3 # Copyright 2014-2017 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
10 class MSTPAttrsCache():
14 def get(cls
, bridgename
, default
=None):
15 if bridgename
in MSTPAttrsCache
.bridges
:
16 return MSTPAttrsCache
.bridges
[bridgename
]
21 def set(cls
, bridgename
, attrs
):
22 MSTPAttrsCache
.bridges
[bridgename
] = attrs
26 MSTPAttrsCache
.bridges
= {}
30 """ This class contains methods and instance variables to cache
33 """ { <ifacename> : { 'ifindex': <index>,
37 'kind' : <kind: bridge, bond, vlan>,
38 'linkinfo' : {<attr1> : <attrval1>,
46 def get_attr(cls
, mapList
):
47 return reduce(lambda d
, k
: d
[k
], mapList
, linkCache
.links
)
50 def set_attr(cls
, mapList
, value
):
51 cls
.get_attr(mapList
[:-1])[mapList
[-1]] = value
54 def del_attr(cls
, mapList
):
56 del cls
.get_attr(mapList
[:-1])[mapList
[-1]]
61 def update_attrdict(cls
, mapList
, valuedict
):
63 cls
.get_attr(mapList
[:-1])[mapList
[-1]].update(valuedict
)
65 cls
.get_attr(mapList
[:-1])[mapList
[-1]] = valuedict
69 def append_to_attrlist(cls
, mapList
, value
):
70 cls
.get_attr(mapList
[:-1])[mapList
[-1]].append(value
)
73 def remove_from_attrlist(cls
, mapList
, value
):
75 cls
.get_attr(mapList
[:-1])[mapList
[-1]].remove(value
)
80 def check_attr(cls
, attrlist
, value
=None):
82 cachedvalue
= cls
.get_attr(attrlist
)
84 if cachedvalue
== value
:
106 print 'Dumping link cache'
107 pp
= pprint
.PrettyPrinter(indent
=4)
111 def dump_link(cls
, linkname
):
112 print 'Dumping link %s' % linkname
113 pp
= pprint
.PrettyPrinter(indent
=4)
114 pp
.pprint(cls
.links
.get(linkname
))