reguire gnupg1 on f>=31; sense the system to use gpg1 when installed
[nodemanager.git] / config.py
index 6288bf7..700b2db 100644 (file)
--- a/config.py
+++ b/config.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 #
 # Parses the PLC configuration file /etc/planetlab/plc_config, which
 # is bootstrapped by Boot Manager, but managed by us.
@@ -6,8 +6,8 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id$
-#
+
+import os
 
 class Config:
     """
@@ -17,17 +17,31 @@ class Config:
 
     def __init__(self, file = "/etc/planetlab/plc_config"):
         try:
-            execfile(file, self.__dict__)
+            exec(compile(open(file).read(), file, 'exec'), self.__dict__)
         except:
-            raise Exception, "Could not parse " + file
+            raise Exception("Could not parse " + file)
 
         if int(self.PLC_API_PORT) == 443:
             uri = "https://"
+            if hasattr(self, 'PLC_API_CA_SSL_CRT'):
+                self.cacert = self.PLC_API_CA_SSL_CRT
+            elif os.path.exists('/usr/boot/cacert.pem'):
+                self.cacert = '/usr/boot/cacert.pem'
+            else:
+                raise Exception("No boot server certificate bundle available")
         else:
             uri = "http://"
+            self.cacert = None
 
         uri += self.PLC_API_HOST + \
                ":" + str(self.PLC_API_PORT) + \
                "/" + self.PLC_API_PATH + "/"
 
         self.plc_api_uri = uri
+
+
+if __name__ == '__main__':
+    from pprint import pprint
+    for (k, v) in Config().__dict__.items():
+        if k not in ['__builtins__']:
+            pprint ( (k, v), )