cosmetic
[nodemanager.git] / config.py
1 #!/usr/bin/python
2 #
3 # $Id$
4 # $URL$
5 #
6 # Parses the PLC configuration file /etc/planetlab/plc_config, which
7 # is bootstrapped by Boot Manager, but managed by us.
8 #
9 # Mark Huang <mlhuang@cs.princeton.edu>
10 # Copyright (C) 2006 The Trustees of Princeton University
11 #
12 # $Id$
13 #
14
15 import os
16
17 class Config:
18     """
19     Parses Python configuration files; all variables in the file are
20     assigned to class attributes.
21     """
22
23     def __init__(self, file = "/etc/planetlab/plc_config"):
24         try:
25             execfile(file, self.__dict__)
26         except:
27             raise Exception, "Could not parse " + file
28
29         if int(self.PLC_API_PORT) == 443:
30             uri = "https://"
31             if hasattr(self, 'PLC_API_CA_SSL_CRT'):
32                 self.cacert = self.PLC_API_CA_SSL_CRT
33             elif os.path.exists('/usr/boot/cacert.pem'):
34                 self.cacert = '/usr/boot/cacert.pem'
35             else:
36                 raise Exception, "No boot server certificate bundle available"
37         else:
38             uri = "http://"
39             self.cacert = None
40
41         uri += self.PLC_API_HOST + \
42                ":" + str(self.PLC_API_PORT) + \
43                "/" + self.PLC_API_PATH + "/"
44
45         self.plc_api_uri = uri
46
47
48 if __name__ == '__main__':
49     from pprint import pprint
50     for (k,v) in Config().__dict__.iteritems():
51         if k not in ['__builtins__']:
52             pprint ( (k,v), )