Added a GENI Aggregate Manager module to the mix, it handles the first call, GetVersion
[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 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.py"):
32         self.config_file = None
33         self.config_path = None
34         self.data_path = None
35         self.load(config_file)
36
37     def load(self, config_file):
38         try:
39             execfile(config_file, self.__dict__)
40             self.config_file = config_file
41             # path to configuration data
42             self.config_path = os.path.dirname(config_file)
43             
44             # path to server data
45             if not hasattr(self, 'SFA_DATA_DIR'):
46                 # default to /var/lib/sfa not specified in config
47                 self.SFA_DATA_DIR="/var/lib/sfa"
48                 self.data_path = self.SFA_DATA_DIR
49             else:
50                 self.data_path = self.SFA_DATA_DIR
51                 
52             # path to config data
53             if not hasattr(self, 'SFA_CONFIG_DIR'):
54                 # default to /var/lib/sfa not specified in config
55                 self.SFA_CONFIG_DIR="/etc/sfa"
56
57             if not hasattr(self, 'SFA_REGISTRY_LEVEL1_AUTH'):
58                 self.SFA_REGISTRY_LEVEL1_AUTH=None
59
60             # define interface types
61             # this will determine which manager to use
62             if not hasattr(self, 'SFA_REGISTRY_TYPE'):
63                 self.SFA_REGISTRY_TYPE='pl'
64
65             if not hasattr(self, 'SFA_AGGREGATE_TYPE'):
66                 self.SFA_AGGREGATE_TYPE='pl'
67
68             if not hasattr(self, 'SFA_SM_TYPE'):
69                 self.SFA_SM_TYPE='pl'
70
71             if not hasattr(self, 'SFA_CM_TYPE'):
72                 self.SFA_COMPONENT_TYPE='pl'
73
74             if not hasattr(self, 'SFA_GAM_TYPE'):
75                 self.SFA_GAM_TYPE='pl'
76
77             # create the data directory if it doesnt exist
78             if not os.path.isdir(self.SFA_DATA_DIR):
79                 try:
80                     os.mkdir(self.SFA_DATA_DIR)
81                 except: pass
82              
83         except IOError, e:
84             raise IOError, "Could not find the configuration file: %s" % config_file
85
86     def get_trustedroots_dir(self):
87         return self.config_path + os.sep + 'trusted_roots'
88
89     def get_openflow_aggrMgr_info(self):
90         aggr_mgr_ip = 'localhost'
91         if (hasattr(self,'OPENFLOW_AGGREGATE_MANAGER_IP')):
92             aggr_mgr_ip = self.OPENFLOW_AGGREGATE_MANAGER_IP
93
94         aggr_mgr_port = 2603
95         if (hasattr(self,'OPENFLOW_AGGREGATE_MANAGER_PORT')):
96             aggr_mgr_port = self.OPENFLOW_AGGREGATE_MANAGER_PORT
97
98         return (aggr_mgr_ip,aggr_mgr_port)
99
100     def get_aggregate_type(self):
101         if (hasattr(self,'SFA_AGGREGATE_TYPE')):
102             return self.SFA_AGGREGATE_TYPE
103         else:
104             return "pl"
105
106     def get_plc_dbinfo(self):
107         return {
108             'dbname' : self.SFA_PLC_DB_NAME,
109             'address' : self.SFA_PLC_DB_HOST,
110             'port' : self.SFA_PLC_DB_PORT,
111             'user' : self.SFA_PLC_DB_USER,
112             'password' : self.SFA_PLC_DB_PASSWORD
113             }
114
115     ##
116     # SFA uses a PLCAPI connection to perform operations on the registry,
117     # such as creating and deleting slices. This connection requires an account
118     # on the PLC server with full administrator access.
119     #
120     # The Url parameter controls whether the connection uses PLCAPI directly (i.e.
121     # SFA is located on the same machine as PLC), or uses a XMLRPC connection
122     # to the PLC machine. If you wish to use the API directly, then remove the Url
123     # field from the dictionary. 
124
125     def get_plc_auth(self):
126         return {
127             'AuthMethod': 'capability',
128             'Username': self.SFA_PLC_USER,
129             'AuthString':  self.SFA_PLC_PASSWORD,
130             "Url": self.SFA_PLC_URL
131             }