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