def getAllClientOrSourcesNamesFromMachines( infos ): """ @summary : Goes through all the machines and finds out wich client or sources currently run on each of those machines. To make sure no confusion arrises if to clinets or source have the same name on different machhines or cluster, the returned names will be associated with all the machines/clusters with whom they are associated as to let the caller hadnle the situation as it pleases. @param infos: Infos that were gathered at program call. @return : The dictionary containing the names and their associated machines. """ sourlients ={} for machine in infos.machinesToSearch: if infos.machinesAreClusters == True: machineConfig = MachineConfigParameters() machineConfig.getParametersFromMachineConfigurationFile() machines = machineConfig.getMachinesAssociatedWith( machine ) if machines != []: #print machines machine = str( machines ).replace('[','').replace(']', '').replace(',','').replace( "'",'' ).replace('"','' ).replace(" ",'') if machine != '': rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNamesHavingRunDuringPeriod( infos.start, infos.end, machines, pattern = None, havingrunOnAllMachines = True ) else: rxNames, txNames = [],[] else: #might be a groups machine,in this case do not force to have run on all machines..... if machine != '': rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNamesHavingRunDuringPeriod( infos.start, infos.end, [machine], pattern = None, havingrunOnAllMachines = False ) else: rxNames, txNames = [],[] else:#not a cluster, une mahcine name directly. Force to have run exclusivly on specified machine. if machine != '': rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNamesHavingRunDuringPeriod( infos.start, infos.end, [machine], pattern = None, havingrunOnAllMachines = True ) else: rxNames, txNames = [],[] if infos.fileType == "rx": namesToAdd = rxNames elif infos.fileType == "tx": namesToAdd = txNames for nameToAdd in namesToAdd: if nameToAdd in sourlients.keys(): if machine not in sourlients[nameToAdd]: sourlients[nameToAdd].append( machine ) else: sourlients[nameToAdd] = [ machine ] configParameters = StatsConfigParameters() configParameters.getAllParameters() groups = configParameters.groupParameters.groups for group in groups : if configParameters.groupParameters.groupFileTypes[group] == infos.fileType : sourlients[group] = [str( configParameters.groupParameters.groupsMachines[group] ).replace('[','').replace(']', '').\ replace(',','').replace( "'",'' ).replace('"','' ).replace(" ",'')] return sourlients
def getGraphicProducerFromParserOptions( parser ): """ This method parses the argv received when the program was called It takes the params wich have been passed by the user and sets them in the corresponding fields of the infos variable. If errors are encountered in parameters used, it will immediatly terminate the application. """ graphicType = _("other") mergerType = "" ( options, args )= parser.parse_args() timespan = options.timespan machines = options.machines.replace( ' ','').split(',') clientNames = options.clients.replace( ' ','' ).split(',') types = options.types.replace( ' ', '').split(',') date = options.date.replace('"','').replace("'",'') fileType = options.fileType.replace("'",'') havingRun = options.havingRun individual = options.individual totals = options.totals daily = options.daily weekly = options.weekly monthly = options.monthly yearly = options.yearly fixedCurrent = options.fixedCurrent fixedPrevious = options.fixedPrevious copy = options.copy turnOffLogging = options.turnOffLogging outputLanguage = options.outputLanguage if outputLanguage == "": outputLanguage = LanguageTools.getMainApplicationLanguage() else : if outputLanguage not in LanguageTools.getSupportedLanguages(): print _("Error. The specified language is not currently supported by this application.") print _("Please specify one of the following languages %s or use the default value()" %( str( LanguageTools.getSupportedLanguages() ).replace("[","").replace("]",""), LanguageTools.getMainApplicationLanguage() ) ) print _("Program terminated.") sys.exit() counter = 0 specialParameters = [daily, monthly, weekly, yearly] for specialParameter in specialParameters: if specialParameter: counter = counter + 1 if counter > 1 : print _("Error. Only one of the daily, weekly and yearly options can be use at a time ") print _("Use -h for help.") print _("Program terminated.") sys.exit() elif counter == 1 and timespan != None : print _("Error. When using the daily, the weekly or the yearly options timespan cannot be specified. " ) print _("Use -h for help.") print _("Program terminated.") sys.exit() elif counter == 0: if fixedPrevious or fixedCurrent: print _("Error. When using one of the fixed options, please use either the -d -m -w or -y options. " ) print _("Use -h for help.") print _("Program terminated.") sys.exit() if copy : if daily or not( weekly or monthly or yearly ): print _("Error. Copying can only be used with the -m -w or -y options. ") print _("Use -h for help.") print _("Program terminated.") if counter == 0 and timespan == None : timespan = 12 if fixedPrevious and fixedCurrent: print _("Error. Please use only one of the fixed options,either fixedPrevious or fixedCurrent. ") print _("Use -h for help.") print _("Program terminated.") sys.exit() if individual and totals: print _("Error. Please use only one of the group options,either individual or totals. ") print _("Use -h for help.") print _("Program terminated.") sys.exit() try: # Makes sure date is of valid format. # Makes sure only one space is kept between date and hour. t = time.strptime( date, '%Y-%m-%d %H:%M:%S' ) split = date.split() date = "%s %s" %( split[0], split[1] ) except: print _("Error. The date format must be YYYY-MM-DD HH:MM:SS") print _("Use -h for help.") print _("Program terminated.") sys.exit() #Set graphic type based on parameters. Only one tpye is allowed at once based on previous validation. if daily : graphicType = _("daily") if fixedPrevious == False and fixedCurrent == False : timespan = 24 elif weekly: graphicType = _("weekly") if fixedPrevious == False and fixedCurrent == False : timespan = 24 * 7 elif monthly: graphicType = _("monthly") if fixedPrevious == False and fixedCurrent == False : timespan = 24 * 30 elif yearly: graphicType = _("yearly") if fixedPrevious == False and fixedCurrent == False : timespan = 24 * 365 start, end = StatsDateLib.getStartEndInIsoFormat(date, timespan, graphicType, fixedCurrent, fixedPrevious ) timespan = int( StatsDateLib.getSecondsSinceEpoch( end ) - StatsDateLib.getSecondsSinceEpoch( start ) ) / 3600 #print "timespan %s" %timespan try: if int( timespan ) < 1 : raise except: print _("Error. The timespan value needs to be an integer one above 0.") print _("Use -h for help.") print _("Program terminated.") sys.exit() if fileType != "tx" and fileType != "rx": print _("Error. File type must be either tx or rx.") print "Specified file type was : ", fileType print _("Multiple types are not accepted.") print _("Use -h for additional help.") print _("Program terminated.") sys.exit() if havingRun == True and clientNames[0] != _("ALL"): print _("Error. Cannot use the havingRun option while specifying client/source names.") print _("To use havingRun, do not use -c|--client option.") print _("Use -h for additional help.") print _("Program terminated.") sys.exit() if clientNames[0] == _("ALL"): # Get all of the client/sources that have run between graph's start and end. if totals == True or havingRun == True : #print start, end, machines rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNamesHavingRunDuringPeriod( start, end, machines,None, havingrunOnAllMachines = True ) mergerType = _("totalForMachine") else:#Build graphs only for currently runningclient/sources. rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNames( LOCAL_MACHINE, machines[0] ) mergerType = _("group") if fileType == _("tx"): clientNames = txNames #print clientNames else: clientNames = rxNames else: if totals == True : mergerType = _("regular") #--------------------------------------------------------------------- try : if fileType == _("tx"): validTypes = [ _("latency"), _("bytecount"), _("errors"), _("filesOverMaxLatency"), _("filecount") ] if types[0] == _("All") : types = validTypes else : for t in types : if t not in validTypes: raise Exception("%s is not a valid type" %t) else: validTypes = [ _("bytecount"), _("errors"), _("filecount") ] if types[0] == _("All"): types = validTypes else : for t in types : if t not in validTypes: raise Exception("") #------------------------------------------------------------------- except: #----------------------------------------------------------- print types # print _("Error. With %s fileType, possible data types values are : %s.") %( fileType, validTypes ) #---- print _("For multiple types use this syntax : -t 'type1','type2'") #-------------------------------- print _("Use -h for additional help.") #---------------------------------------- print _("Program terminated.") #------------------------------------------------------------ sys.exit() if individual != True : combinedMachineName = "" for machine in machines: combinedMachineName = combinedMachineName + machine machines = [ combinedMachineName ] if len(clientNames) <1: print _("Error. No client/sources were found that matched the specified parameters") %( fileType, validTypes ) print _("Verify parameters used, especially the machines parameter.") print _("Use -h for additional help.") print _("Program terminated.") sys.exit() if len(clientNames) <1: print _("Error. No client/sources were found that matched the specified parameters") print _("Verify parameters used, especially the machines parameter.") print _("Use -h for additional help.") print _("Program terminated.") sys.exit() elif len(clientNames) == 1 and totals == True: print _("Error. Cannot use totals option with only one client/source name.") print _("Either remove --total option or use more than one client/source..") print _("Use -h for additional help.") print _("Program terminated.") sys.exit() end = StatsDateLib.getIsoWithRoundedHours( end ) graphicsProducer = RRDGraphicProducer( startTime = start, endTime = end, graphicType = graphicType, clientNames = clientNames, types = types, timespan = timespan, machines = machines, fileType = fileType,\ totals = totals, copy = copy, mergerType = mergerType,turnOffLogging = turnOffLogging, inputLanguage = LanguageTools.getMainApplicationLanguage() , outputLanguage = outputLanguage ) return graphicsProducer
def getAllClientOrSourcesNamesFromMachines(infos): """ @summary : Goes through all the machines and finds out wich client or sources currently run on each of those machines. To make sure no confusion arrises if to clinets or source have the same name on different machhines or cluster, the returned names will be associated with all the machines/clusters with whom they are associated as to let the caller hadnle the situation as it pleases. @param infos: Infos that were gathered at program call. @return : The dictionary containing the names and their associated machines. """ sourlients = {} for machine in infos.machinesToSearch: if infos.machinesAreClusters == True: machineConfig = MachineConfigParameters() machineConfig.getParametersFromMachineConfigurationFile() machines = machineConfig.getMachinesAssociatedWith(machine) if machines != []: #print machines machine = str(machines).replace('[', '').replace( ']', '').replace(',', '').replace("'", '').replace('"', '').replace(" ", '') if machine != '': rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNamesHavingRunDuringPeriod( infos.start, infos.end, machines, pattern=None, havingrunOnAllMachines=True) else: rxNames, txNames = [], [] else: #might be a groups machine,in this case do not force to have run on all machines..... if machine != '': rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNamesHavingRunDuringPeriod( infos.start, infos.end, [machine], pattern=None, havingrunOnAllMachines=False) else: rxNames, txNames = [], [] else: #not a cluster, une mahcine name directly. Force to have run exclusivly on specified machine. if machine != '': rxNames, txNames = GeneralStatsLibraryMethods.getRxTxNamesHavingRunDuringPeriod( infos.start, infos.end, [machine], pattern=None, havingrunOnAllMachines=True) else: rxNames, txNames = [], [] if infos.fileType == "rx": namesToAdd = rxNames elif infos.fileType == "tx": namesToAdd = txNames for nameToAdd in namesToAdd: if nameToAdd in sourlients.keys(): if machine not in sourlients[nameToAdd]: sourlients[nameToAdd].append(machine) else: sourlients[nameToAdd] = [machine] configParameters = StatsConfigParameters() configParameters.getAllParameters() groups = configParameters.groupParameters.groups for group in groups: if configParameters.groupParameters.groupFileTypes[ group] == infos.fileType: sourlients[group] = [str( configParameters.groupParameters.groupsMachines[group] ).replace('[','').replace(']', '').\ replace(',','').replace( "'",'' ).replace('"','' ).replace(" ",'')] return sourlients