importrandomdescriptors=list()Random_Max=50Constant_Value=50defRandom_Numbers(name):'''Return a random number.'''returnint(random.uniform(0,Random_Max))defConstant_Number(name):'''Return a constant number.'''returnint(Constant_Value)defmetric_init(params):'''Initialize the random number generator and create the metric definition dictionary object for each metric.'''globaldescriptorsglobalRandom_MaxglobalConstant_Valuerandom.seed()print'[pyexample] Received the following parameters'printparamsif'RandomMax'inparams:Random_Max=int(params['RandomMax'])if'ConstantValue'inparams:Constant_Value=int(params['ConstantValue'])d1={'name':'PyRandom_Numbers','call_back':Random_Numbers,'time_max':90,'value_type':'uint','units':'N','slope':'both','format':'%u','description':'Example module metric (random numbers)','groups':'example,random'}d2={'name':'PyConstant_Number','call_back':Constant_Number,'time_max':90,'value_type':'uint','units':'N','slope':'zero','format':'%hu','description':'Example module metric (constant number)'}descriptors=[d1,d2]returndescriptorsdefmetric_cleanup():'''Clean up the metric module.'''pass#This code is for debugging and unit testingif__name__=='__main__':params={'RandomMax':'500','ConstantValue':'322'}metric_init(params)fordindescriptors:v=d['call_back'](d['name'])print'value for %s is %u'%(d['name'],v)