def plcReadConfigVar(catID, varID, configFile=DEF_PLC_CONFIG_FILE): """ Returns the value of the specified variable. """ plcc = PLCConfiguration(configFile) ret = plcc.get(catID, varID) if ret == None: return None for d in ret: if d['id'] == varID: ret = d['value'] break pass return ret
def plcReadConfigVar(catID,varID,configFile=DEF_PLC_CONFIG_FILE): """ Returns the value of the specified variable. """ plcc = PLCConfiguration(configFile) ret = plcc.get(catID,varID) if ret == None: return None for d in ret: if d['id'] == varID: ret = d['value'] break pass return ret
def __init__(self, file = "/etc/planetlab/plc_config.xml"): try: from plc_config import PLCConfiguration except: sys.path.append(myplc) from plc_config import PLCConfiguration # Load plc_config.xml try: cfg = PLCConfiguration(file) except: # Try myplc directory try: cfg = PLCConfiguration(myplc + os.sep + "plc_config.xml") except: raise PLCAPIError("Could not find plc_config.xml in " + \ file + ", " + \ myplc + os.sep + "plc_config.xml") for (category, variablelist) in cfg.variables().values(): for variable in variablelist.values(): # Try to cast each variable to an appropriate Python # type. if variable['type'] == "int": value = int(variable['value']) elif variable['type'] == "double": value = float(variable['value']) elif variable['type'] == "boolean": if variable['value'] == "true": value = True else: value = False else: value = variable['value'] # Variables are split into categories such as # "plc_api", "plc_db", etc. Within each category are # variables such as "host", "port", etc. For backward # compatibility, refer to variables by their shell # names. shell_name = category['id'].upper() + "_" + variable['id'].upper() setattr(self, shell_name, value)
def plcUpdateConfig(variables,configFile=DEF_PLC_CONFIG_FILE): """ Update the default planetlab config file. Arguments: variables = list of dicts or lists configFile = alternate planetlab config file Example: to set plc_www/host (i.e., PLC_WWW_HOST in myplc docs), do variables[0] = { 'category' : 'plc_www', 'variable' : 'host', 'value' : <value> } or variables[0] = [ 'plc_www','host',<value> ] """ plcc = PLCConfiguration(configFile) for obj in variables: catDict = dict() varDict = dict() if type(obj) == list: catDict['id'] = obj[0] varDict['id'] = obj[1] varDict['value'] = obj[2] pass elif type(obj) == dict: catDict['id'] = obj['category'] varDict['id'] = obj['variable'] varDict['value'] = obj['value'] pass else: raise "Unsupported variable object!" plcc.set(catDict,varDict) pass plcc.save() pass
def plcUpdateConfig(variables, configFile=DEF_PLC_CONFIG_FILE): """ Update the default planetlab config file. Arguments: variables = list of dicts or lists configFile = alternate planetlab config file Example: to set plc_www/host (i.e., PLC_WWW_HOST in myplc docs), do variables[0] = { 'category' : 'plc_www', 'variable' : 'host', 'value' : <value> } or variables[0] = [ 'plc_www','host',<value> ] """ plcc = PLCConfiguration(configFile) for obj in variables: catDict = dict() varDict = dict() if type(obj) == list: catDict['id'] = obj[0] varDict['id'] = obj[1] varDict['value'] = obj[2] pass elif type(obj) == dict: catDict['id'] = obj['category'] varDict['id'] = obj['variable'] varDict['value'] = obj['value'] pass else: raise "Unsupported variable object!" plcc.set(catDict, varDict) pass plcc.save() pass