reguire gnupg1 on f>=31; sense the system to use gpg1 when installed
[nodemanager.git] / config.py
1 #!/usr/bin/python3
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
10 import os
11
12 class Config:
13     """
14     Parses Python configuration files; all variables in the file are
15     assigned to class attributes.
16     """
17
18     def __init__(self, file = "/etc/planetlab/plc_config"):
19         try:
20             exec(compile(open(file).read(), file, 'exec'), self.__dict__)
21         except:
22             raise Exception("Could not parse " + file)
23
24         if int(self.PLC_API_PORT) == 443:
25             uri = "https://"
26             if hasattr(self, 'PLC_API_CA_SSL_CRT'):
27                 self.cacert = self.PLC_API_CA_SSL_CRT
28             elif os.path.exists('/usr/boot/cacert.pem'):
29                 self.cacert = '/usr/boot/cacert.pem'
30             else:
31                 raise Exception("No boot server certificate bundle available")
32         else:
33             uri = "http://"
34             self.cacert = None
35
36         uri += self.PLC_API_HOST + \
37                ":" + str(self.PLC_API_PORT) + \
38                "/" + self.PLC_API_PATH + "/"
39
40         self.plc_api_uri = uri
41
42
43 if __name__ == '__main__':
44     from pprint import pprint
45     for (k, v) in Config().__dict__.items():
46         if k not in ['__builtins__']:
47             pprint ( (k, v), )