[svn] commit: r170 - /branches/f2f200910/src/lib/bind-cfgd/python/bind-cfgd.py

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Oct 29 21:12:08 UTC 2009


Author: jelte
Date: Thu Oct 29 21:12:07 2009
New Revision: 170

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

Modified:
    branches/f2f200910/src/lib/bind-cfgd/python/bind-cfgd.py

Modified: branches/f2f200910/src/lib/bind-cfgd/python/bind-cfgd.py
==============================================================================
--- branches/f2f200910/src/lib/bind-cfgd/python/bind-cfgd.py (original)
+++ branches/f2f200910/src/lib/bind-cfgd/python/bind-cfgd.py Thu Oct 29 21:12:07 2009
@@ -1,5 +1,6 @@
 import ISC
-
+import pickle
+    
 class ConfigData:
     def __init__(self):
         self.zones = {}
@@ -32,14 +33,16 @@
     def read_config(self, filename):
         print("Reading config")
         try:
-            file = open(filename, 'r');
+            file = open(filename, 'rb');
             self.config = pickle.load(file)
         except IOError as ioe:
             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):
         print("Writing config")
-        file = open(filename, 'w');
+        file = open(filename, 'wb');
         pickle.dump(self.config, file)
 
     def handle_msg(self, msg):
@@ -68,30 +71,34 @@
         return answer
         
     def run(self):
-        while (True):
+        msg = 1
+        while (msg):
             msg, env = self.cc.group_recvmsg(False)
-            print("received message: ")
-            print(msg)
-            answer = self.handle_msg(msg);
-            print("sending answer: ")
-            print(answer)
-            self.cc.group_reply(env, answer)
-            print("answer sent")
-            pass
-
+            if msg:
+                print("received message: ")
+                print(msg)
+                answer = self.handle_msg(msg);
+                print("sending answer: ")
+                print(answer)
+                self.cc.group_reply(env, answer)
+                print("answer sent")
+            
+                
 if __name__ == "__main__":
     print("Hello, BIND10 world!")
+    db_file = "/tmp/parkinglot.db"
     try:
         cm = ConfigManager()
-        cm.read_config("/tmp/a")
+        cm.read_config(db_file)
         # do loading here if necessary
         cm.notify_boss()
         cm.run()
+        cm.write_config(db_file)
     except ISC.CC.SessionError as se:
         print("Error creating config manager, "
               "is the command channel daemon running?")
     except KeyboardInterrupt as kie:
         print("Got ctrl-c, save config and exit")
-        cm.write_config("/tmp/a")
-
+        cm.write_config(db_file)
+    
         




More information about the bind10-changes mailing list