Commit e755da8c by Tomas Hlavacek

Rework PersistentStorage to support old Python

Remove static methods from PersistentStorage object in order to make it possible to dump/pickle the object on older Python versions.
parent ab45bb55
......@@ -178,11 +178,11 @@ def testULGRescan():
def testULGPersistentStorage():
try:
ps = ulgmodel.PersistentStorage.load()
ps = ulgmodel.loadPersistentStorage()
ps.set('test','teststring')
ps.save()
ps2 = ulgmodel.PersistentStorage.load()
ps2 = ulgmodel.loadPersistentStorage()
if(ps2.get('test') == 'teststring'):
ps2.delete('test')
if(ps2.get('test') == None):
......
......@@ -654,7 +654,7 @@ class BirdRouterRemote(ulgmodel.RemoteRouter,BirdRouter):
key_rt = self.getHost() + self.getName() + self.PS_KEY_RT
ps = ulgmodel.PersistentStorage.load()
ps = ulgmodel.loadPersistentStorage()
ps.set(key_bgp,self.getBGPPeers())
ps.set(key_rt,self.getRoutingTables())
ps.save()
......@@ -663,7 +663,7 @@ class BirdRouterRemote(ulgmodel.RemoteRouter,BirdRouter):
key_bgp = self.getHost() + self.getName() + self.PS_KEY_BGP
key_rt = self.getHost() + self.getName() + self.PS_KEY_RT
ps = ulgmodel.PersistentStorage.load()
ps = ulgmodel.loadPersistentStorage()
self.bgp_peers = ps.get(key_bgp)
self.routing_tables = ps.get(key_rt)
......
......@@ -800,7 +800,7 @@ class CiscoRouter(ulgmodel.RemoteRouter):
key4 = self.getHost() + self.PS_KEY_BGPV4
key6 = self.getHost() + self.PS_KEY_BGPV6
ps = ulgmodel.PersistentStorage.load()
ps = ulgmodel.loadPersistentStorage()
ps.set(key4,self.getBGPIPv4Peers())
ps.set(key6,self.getBGPIPv6Peers())
ps.save()
......@@ -809,7 +809,7 @@ class CiscoRouter(ulgmodel.RemoteRouter):
key4 = self.getHost() + self.PS_KEY_BGPV4
key6 = self.getHost() + self.PS_KEY_BGPV6
ps = ulgmodel.PersistentStorage.load()
ps = ulgmodel.loadPersistentStorage()
self.bgp_ipv4_peers = ps.get(key4)
self.bgp_ipv6_peers = ps.get(key6)
......
......@@ -241,14 +241,14 @@ class JuniperRouter(ulgmodel.RemoteRouter):
def savePersistentInfo(self):
key_bgp = self.getHost() + self.getName() + self.PS_KEY_BGP
ps = ulgmodel.PersistentStorage.load()
ps = ulgmodel.loadPersistentStorage()
ps.set(key_bgp,self.getBGPPeers())
ps.save()
def loadPersistentInfo(self):
key_bgp = self.getHost() + self.getName() + self.PS_KEY_BGP
ps = ulgmodel.PersistentStorage.load()
ps = ulgmodel.loadPersistentStorage()
self.bgp_peers = ps.get(key_bgp)
if(not self.getBGPPeers()):
......
......@@ -64,17 +64,6 @@ class PersistentStorage(object):
pickle.dump(self, f)
f.close()
@staticmethod
def load(filename=defaults.persistent_storage_file):
# TODO: locking
if(os.path.isfile(filename)):
f = open(filename, 'rb')
s = pickle.load(f)
f.close()
return s
else:
return PersistentStorage()
def get(self,key):
return self.data.get(key,None)
......@@ -88,6 +77,18 @@ class PersistentStorage(object):
def getDict(self):
return self.data
def loadPersistentStorage(filename=defaults.persistent_storage_file):
# TODO: locking
if(os.path.isfile(filename)):
f = open(filename, 'rb')
s = pickle.load(f)
f.close()
return s
else:
return PersistentStorage()
class TableDecorator(object):
WHITE = 'white'
RED = 'red'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment