From: Faiyaz Ahmed Date: Tue, 30 Dec 2008 21:12:57 +0000 (+0000) Subject: use /etc/planetlab/ for plc specific config info. X-Git-Tag: sfa-0.9-0@14641~783 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=29beb25fa22b0445e3d1869dbf57540f27c07a55;p=sfa.git use /etc/planetlab/ for plc specific config info. --- diff --git a/util/config.py b/util/config.py index 562aee17..b9c860a8 100644 --- a/util/config.py +++ b/util/config.py @@ -14,13 +14,45 @@ # Note that Geniwrapper does not access any of the PLC databases directly via # a mysql connection; All PLC databases are accessed via PLCAPI. +import os +import sys + +# If we have been checked out into a directory at the same +# level as myplc, where plc_config.py lives. If we are in a +# MyPLC environment, plc_config.py has already been installed +# in site-packages. +myplc = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + \ + os.sep + "myplc" + +class Config: + """ + Parse the bash/Python/PHP version of the configuration file. Very + fast but no type conversions. + """ + + def __init__(self, file = "/etc/planetlab/plc_config"): + # Load plc_config + try: + execfile(file, self.__dict__) + except: + # Try myplc directory + try: + execfile(myplc + os.sep + "plc_config", self.__dict__) + except: + raise PLCAPIError("Could not find plc_config in " + \ + file + ", " + \ + myplc + os.sep + "plc_config") + + +plcConfig = Config() + def get_default_dbinfo(): - dbinfo={} - dbinfo['dbname'] = 'planetlab4' - dbinfo['address'] = 'localhost' - dbinfo['port'] = 5432 - dbinfo['user'] = 'pgsqluser' - dbinfo['password'] = '4c77b272-c892-4bdf-a833-dddeeee1a2ed' + dbinfo={ 'dbname' = plcConfig.PLC_DB_NAME, + 'address' = plcConfig.PLC_DB_HOST, + 'port' = plcConfig.PLC_DB_PORT, + 'user' = plcConfig.PLC_DB_USER, + 'password' = plcConfig.PLC_DB_PASSWORD + } return dbinfo @@ -35,10 +67,10 @@ def get_default_dbinfo(): # field from the dictionary. def get_pl_auth(): - pl_auth = {'Username': 'root@198.0.0.132', - 'AuthMethod': 'password', - 'AuthString': 'root', - "Url": "https://localhost:443/PLCAPI/" - } + pl_auth = {'Username': plcConfig.PLC_API_MAINTENANCE_USER, + 'AuthMethod': 'password', + 'AuthString': plcConfig.PLC_MAINTENANCE_PASSWORD, + "Url": 'https://%s:%s%s' %(plcConfig.PLC_API_HOST, plcConfig.PLC_API_PORT, plcConfig.PLC_API_PATH) + } return pl_auth diff --git a/util/excep.pyc b/util/excep.pyc index edb7e87d..2795d569 100644 Binary files a/util/excep.pyc and b/util/excep.pyc differ diff --git a/util/util.pyc b/util/util.pyc index 72417b35..0f688c82 100644 Binary files a/util/util.pyc and b/util/util.pyc differ