rename configuration variables like from GENI_ to SFA_
[sfa.git] / sfa / util / config.py
1 ##
2 # Geniwrapper Configuration Info
3 #
4 # This module holds configuration parameters for geniwrapper. There are two
5 # main pieces of information that are used: the database connection and
6 # the PLCAPI connection
7 ##
8
9 ##
10 # Geniwrapper uses a MYSQL database to store records. This database may be
11 # co-located with the PLC database, or it may be a separate database. The
12 # following parameters define the connection to the database.
13 #
14 # Note that Geniwrapper does not access any of the PLC databases directly via
15 # a mysql connection; All PLC databases are accessed via PLCAPI.
16
17 ### $Id$
18 ### $URL$
19
20 import os.path
21 import traceback
22
23 from sfa.util.debug import log
24
25 class Config:
26     """
27     Parse the bash/Python/PHP version of the configuration file. Very
28     fast but no type conversions.
29     """
30
31     def __init__(self, config_file = "/etc/sfa/sfa_config"):
32         self.config_file = None
33         self.config_path = None
34         self.load(config_file)
35
36     def load(self, config_file):
37         try:
38             execfile(config_file, self.__dict__)
39             self.config_file = config_file
40             self.config_path = os.path.dirname(config_file)
41         except IOError, e:
42             raise IOError, "Could not find the configuration file: %s" % config_file
43
44
45 def get_default_dbinfo():
46     config = Config()
47     dbinfo={
48         'dbname' : config.SFA_PLC_DB_NAME,
49         'address' : config.SFA_PLC_DB_HOST,
50         'port' : config.SFA_PLC_DB_PORT,
51         'user' : config.SFA_PLC_DB_USER,
52         'password' : config.SFA_PLC_DB_PASSWORD
53         }
54     return dbinfo
55
56 ##
57 # Geniwrapper uses a PLCAPI connection to perform operations on the registry,
58 # such as creating and deleting slices. This connection requires an account
59 # on the PLC server with full administrator access.
60 #
61 # The Url parameter controls whether the connection uses PLCAPI directly (i.e.
62 # Geniwrapper is located on the same machine as PLC), or uses a XMLRPC connection
63 # to the PLC machine. If you wish to use the API directly, then remove the Url
64 # field from the dictionary. 
65
66 def get_pl_auth():
67     config = Config()
68     pl_auth = {
69         'Username': config.SFA_PLC_USER,
70         'AuthMethod': 'capability',
71         'AuthString':  config.SFA_PLC_PASSWORD,
72         "Url": config.SFA_PLC_URL
73         }
74     return pl_auth