Commit 1e70a814 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

store config in (binary) database on exit, read on start. database file...

store config in (binary) database on exit, read on start. database file currently hardcoded as /tmp/parkinglot.db


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/f2f200910@170 e5f2f494-b856-4b98-b285-d166d9295462
parent 5bf90174
import ISC import ISC
import pickle
class ConfigData: class ConfigData:
def __init__(self): def __init__(self):
self.zones = {} self.zones = {}
...@@ -32,14 +33,16 @@ class ConfigManager: ...@@ -32,14 +33,16 @@ class ConfigManager:
def read_config(self, filename): def read_config(self, filename):
print("Reading config") print("Reading config")
try: try:
file = open(filename, 'r'); file = open(filename, 'rb');
self.config = pickle.load(file) self.config = pickle.load(file)
except IOError as ioe: except IOError as ioe:
print("No config file found, starting with empty config") print("No config file found, starting with empty config")
except EOFError as eofe:
print("Config file empty, starting with empty config")
def write_config(self, filename): def write_config(self, filename):
print("Writing config") print("Writing config")
file = open(filename, 'w'); file = open(filename, 'wb');
pickle.dump(self.config, file) pickle.dump(self.config, file)
def handle_msg(self, msg): def handle_msg(self, msg):
...@@ -68,30 +71,34 @@ class ConfigManager: ...@@ -68,30 +71,34 @@ class ConfigManager:
return answer return answer
def run(self): def run(self):
while (True): msg = 1
while (msg):
msg, env = self.cc.group_recvmsg(False) msg, env = self.cc.group_recvmsg(False)
print("received message: ") if msg:
print(msg) print("received message: ")
answer = self.handle_msg(msg); print(msg)
print("sending answer: ") answer = self.handle_msg(msg);
print(answer) print("sending answer: ")
self.cc.group_reply(env, answer) print(answer)
print("answer sent") self.cc.group_reply(env, answer)
pass print("answer sent")
if __name__ == "__main__": if __name__ == "__main__":
print("Hello, BIND10 world!") print("Hello, BIND10 world!")
db_file = "/tmp/parkinglot.db"
try: try:
cm = ConfigManager() cm = ConfigManager()
cm.read_config("/tmp/a") cm.read_config(db_file)
# do loading here if necessary # do loading here if necessary
cm.notify_boss() cm.notify_boss()
cm.run() cm.run()
cm.write_config(db_file)
except ISC.CC.SessionError as se: except ISC.CC.SessionError as se:
print("Error creating config manager, " print("Error creating config manager, "
"is the command channel daemon running?") "is the command channel daemon running?")
except KeyboardInterrupt as kie: except KeyboardInterrupt as kie:
print("Got ctrl-c, save config and exit") print("Got ctrl-c, save config and exit")
cm.write_config("/tmp/a") cm.write_config(db_file)
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