def getJobs(self): self.numCpusInUse = 0 #p = PBSQuery.PBSQuery() #jobslist = p.getjobs() jobslist = pbs.pbs_statjob(self.con, "", "NULL", "NULL") for jobInst in jobslist: job = Job(jobInst.name) #print "name is"+jobInst.name+"text is",jobInst.text,"next is",jobInst.next,"and this is",jobInst.this for attrib in jobInst.attribs: #print attrib.name+" is the name and the value is "+attrib.value if attrib.name == 'Resource_List': if attrib.resource == "nodes": #Value corresponding to nodes is in format (nodes=)X:ppn=Y[:property1[:propertyN]] #value is an array of one item if ":" in attrib.value: #Node data may be colon separated with procs per node and node properties #print "value for nodes is %s" % attrib.value #nodes,ppnstring = attrib.value.split(":") nodeDataList = attrib.value.split(":") job.numNodes = int(nodeDataList[0]) iterNum = 0 ##Needed to iterate through our properies and skip the first one. for item in nodeDataList: if "=" in item: #An equals suggests a nodes= or ppn= assignment label,value = item.split("=") if label == 'ppn': job.ppn = int(value) ##No else, as it would match the walltime entry! else: #No equals sign means this is a property if iterNum > 0: ##unless its the num_nodes int we stripped off earlier! job.properties.append(item) #If node has a "cloud" property, its cloud, else hardware iterNum += 1 else: #ppn not specified so is taken to be one job.numNodes = int(attrib.value) job.ppn = 1 job.ncpus = job.numNodes elif attrib.resource == "walltime": job.walltime = attrib.value elif attrib.resource == "nodect": job.nodect = attrib.value else: print "attrib resource is %s" % attrib.resource elif attrib.name == 'qtime': job.qtime = int(attrib.value) elif attrib.name == 'job_state': if attrib.value == 'Q': job.status = 'queued' self.queuedJobs.append(job) elif attrib.value == 'R': job.status = 'running' self.numCpusInUse += job.ncpus else: job.status = 'other' #We are not interested in complete or errored jobs. else: pass #print "Attrib name is %s and value is %s" % (attrib.name, attrib.value) ##Now we have acquired all the information we need from each job. Store the job # data in our self.jobs array job.ncpus = job.numNodes * job.ppn self.jobs.append(job) self.numJobs = len(self.jobs) self.numQueuedJobs = len(self.queuedJobs)