sfa settings : sfa_plc category split into sfa_plc and sfa_db
[sfa.git] / sfa / util / config.py
1 ##
2 # SFA Configuration Info
3 #
4 # This module holds configuration parameters for SFA. There are two
5 # main pieces of information that are used: the database connection and
6 # the PLCAPI connection
7 ##
8
9 ##
10 # SFA 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 SFA does not access any of the PLC databases directly via
15 # a mysql connection; All PLC databases are accessed via PLCAPI.
16
17 import os.path
18 import traceback
19
20 class Config:
21     """
22     Parse the bash/Python/PHP version of the configuration file. Very
23     fast but no type conversions.
24     """
25
26     def __init__(self, config_file = "/etc/sfa/sfa_config.py"):
27         self.config_file = None
28         self.config_path = None
29         self.data_path = None
30         self.load(config_file)
31
32     def load(self, config_file):
33         try:
34             execfile(config_file, self.__dict__)
35             self.config_file = config_file
36             # path to configuration data
37             self.config_path = os.path.dirname(config_file)
38             
39             # path to server data
40             if not hasattr(self, 'SFA_DATA_DIR'):
41                 # default to /var/lib/sfa not specified in config
42                 self.SFA_DATA_DIR="/var/lib/sfa"
43                 self.data_path = self.SFA_DATA_DIR
44             else:
45                 self.data_path = self.SFA_DATA_DIR
46                 
47             # path to config data
48             if not hasattr(self, 'SFA_CONFIG_DIR'):
49                 # default to /var/lib/sfa not specified in config
50                 self.SFA_CONFIG_DIR="/etc/sfa"
51
52             if not hasattr(self, 'SFA_REGISTRY_LEVEL1_AUTH'):
53                 self.SFA_REGISTRY_LEVEL1_AUTH=None
54
55             # define interface types
56             # this will determine which manager to use
57             if not hasattr(self, 'SFA_REGISTRY_TYPE'):
58                 self.SFA_REGISTRY_TYPE='pl'
59
60             if not hasattr(self, 'SFA_AGGREGATE_TYPE'):
61                 self.SFA_AGGREGATE_TYPE='pl'
62
63             if not hasattr(self, 'SFA_SM_TYPE'):
64                 self.SFA_SM_TYPE='pl'
65
66             if not hasattr(self, 'SFA_CM_TYPE'):
67                 self.SFA_COMPONENT_TYPE='pl'
68
69             if not hasattr(self, 'SFA_MAX_SLICE_RENEW'):
70                 self.SFA_MAX_SLICE_RENEW=60
71
72             # create the data directory if it doesnt exist
73             if not os.path.isdir(self.SFA_DATA_DIR):
74                 try:
75                     os.mkdir(self.SFA_DATA_DIR)
76                 except: pass
77              
78         except IOError, e:
79             raise IOError, "Could not find or load the configuration file: %s" % config_file
80
81     def get_trustedroots_dir(self):
82         return self.config_path + os.sep + 'trusted_roots'
83
84     def get_openflow_aggrMgr_info(self):
85         aggr_mgr_ip = 'localhost'
86         if (hasattr(self,'OPENFLOW_AGGREGATE_MANAGER_IP')):
87             aggr_mgr_ip = self.OPENFLOW_AGGREGATE_MANAGER_IP
88
89         aggr_mgr_port = 2603
90         if (hasattr(self,'OPENFLOW_AGGREGATE_MANAGER_PORT')):
91             aggr_mgr_port = self.OPENFLOW_AGGREGATE_MANAGER_PORT
92
93         return (aggr_mgr_ip,aggr_mgr_port)
94
95     def get_aggregate_type(self):
96         if (hasattr(self,'SFA_AGGREGATE_TYPE')):
97             return self.SFA_AGGREGATE_TYPE
98         else:
99             return "pl"
100
101     def get_interface_hrn(self):
102         if (hasattr(self,'SFA_INTERFACE_HRN')):
103             return self.SFA_INTERFACE_HRN
104         else:
105             return "plc"
106
107     def get_plc_dbinfo(self):
108         return {
109             'dbname' : self.SFA_DB_NAME,
110             'address' : self.SFA_DB_HOST,
111             'port' : self.SFA_DB_PORT,
112             'user' : self.SFA_DB_USER,
113             'password' : self.SFA_DB_PASSWORD
114             }
115
116     # TODO: find a better place to put this method
117     def get_max_aggrMgr_info(self):
118         am_apiclient_path = '/usr/local/MAXGENI_AM_APIClient'
119         if (hasattr(self,'MAXGENI_AM_APICLIENT_PATH')):
120             am_client_path = self.MAXGENI_AM_APICLIENT_PATH
121
122         am_url = 'https://geni.dragon.maxgigapop.net:8443/axis2/services/AggregateGENI'
123         if (hasattr(self,'MAXGENI_AM_URL')):
124             am_url = self.MAXGENI_AM_URL
125
126         return (am_apiclient_path,am_url)
127
128     ##
129     # SFA uses a PLCAPI connection to perform operations on the registry,
130     # such as creating and deleting slices. This connection requires an account
131     # on the PLC server with full administrator access.
132     #
133     # The Url parameter controls whether the connection uses PLCAPI directly (i.e.
134     # SFA is located on the same machine as PLC), or uses a XMLRPC connection
135     # to the PLC machine. If you wish to use the API directly, then remove the Url
136     # field from the dictionary. 
137
138     def get_plc_auth(self):
139         return {
140             'AuthMethod': 'capability',
141             'Username': self.SFA_PLC_USER,
142             'AuthString':  self.SFA_PLC_PASSWORD,
143             "Url": self.SFA_PLC_URL
144             }