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