Example #1
0
    def dumpDetails(self):
        pbs_server = pbs.pbs_default()
        if not pbs_server:
            print "No default pbs server"
            sys.exit(1)

        nodes = pbs.pbs_statnode(self.con, "", "NULL", "NULL")

        for node in nodes:
            print node.name
            for attrib in node.attribs:
                print '\t', attrib.name, '=', attrib.value
Example #2
0
    def getNodes(self):
        '''
        Build an array of Node objects comprising the worker nodes of the cluster.
        '''
        #pbs_statnode queries the pbs server over an existing connection and
        #returns a list of nodes and some of their properties
        nodelist = pbs.pbs_statnode(self.con, "", "NULL", "NULL")

        #Iterate through the nodelist, creating
        for node in nodelist:
            thisnode = Node()
            thisnode.setHostname(node.name)
            thisnode.nodeType = 'hardware'      #Node type is "hardware" unless it proves itself a cloud node!
            ##Bit of a hack, but set num jobs to zero initially - jobs data will not be given
            # where there are no jobs running on a node, so overwrite this if that happens
            thisnode.setNumJobs(0)          ##Set number of running jobs to zero
            thisnode.setFreeCpus(thisnode.num_cpus) #Set free cpus to the total number of cpus on the node

            for attrib in node.attribs:
                if attrib.name == 'state':
                    thisnode.setState(attrib.value)
                elif attrib.name == 'np':
                    #np attribute contains the number of cpu cores
                    #as defined in Torques nodes file
                    thisnode.setNumCpus(attrib.value)
                elif attrib.name == 'properties':
                    #"properties" is a resource-manager 'label' indicating
                    #any specific features provided by this node, such as
                    #applications or physical components
                    propertyList = attrib.value.split(',')
                    for propertyName in propertyList:
                        thisnode.addProperty(propertyName)
                        if propertyName == 'cloud':         #Node has the "cloud" property
                            thisnode.nodeType = 'cloud'     #Convert nodetype to cloud
                        #print "added property",propertyName
                elif attrib.name == 'status':
                    #Torque 'status' contains a value which is in turn a string of attributes
                    #and corresponding values(e.g name1=value1,name2=value2 etc)
                    variables = attrib.value.split(',')
                    pairs = [variable.split('=',1) for variable in variables]
                    for data in pairs:

                        if data[0] == 'physmem':
                            thisnode.setMem(data[1])
                        elif data[0] == 'jobs':
                            if data[1]:     ##if our list is not empty, this node jobs running on it.
                                for jobid in data[1]:
                                    jobinstance = Job(jobid)
                                    thisnode.addJob(jobinstance)
                                thisnode.setNumJobs(thisnode.jobs.__len__())    ##Add the number of running jobs as a property of the node
                                if thisnode.num_jobs == thisnode.num_cpus:  ##If num_jobs = num_cpus, this node is completely full
                                    thisnode.setFreeCpus(0)
                                    self.fullnodes.append(thisnode)         ##Add to list of full nodes

                        #else: print "data is ",data[0]
                #else:
                    #print "attrib is",attrib.name,"and value is",attrib.value
            #thisnode.printDetails()
            self.nodes.append(thisnode)
            if thisnode.num_jobs == 0 and thisnode.state != 'down':
                thisnode.setState('idle')
            if thisnode.state == 'down':
                self.downnodes.append(thisnode)
            elif thisnode.state == 'idle':
                self.idlenodes.append(thisnode)
            if thisnode.nodeType == 'cloud':
                self.cloudnodes.append(thisnode)
                if thisnode.state == 'idle':
                    self.idlecloudnodes.append(thisnode)
            elif thisnode.nodeType == 'hardware':
                if thisnode.state == 'idle':
                    self.idlehardwarenodes.append(thisnode)
        self.total_nodes = len(self.nodes)
        self.idle_nodes = len(self.idlenodes)
        self.down_nodes = len(self.downnodes)
        self.numIdleCloudNodes = len(self.idlecloudnodes)
        self.numIdleHardwareNodes = len(self.idlehardwarenodes)