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 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