Beispiel #1
0
def list_nodes(ID):
    nodename = []
    nodes = pbs.pbs_statnode(ID, "", "NULL", "NULL")
    for node in nodes:
	nodename.append(node.name)
    
    return nodename
Beispiel #2
0
def main():
  server = pbs.pbs_default()
  c      = pbs.pbs_connect(server)

  nodes = pbs.pbs_statnode(c, '', 'NULL', 'NULL')

  for node in nodes:
    print node.name, ' :'
    attrs = node.attribs
    for attr in attrs:
      print '\t%s = %s' %(attr.name, attr.value)

    try:
      mom_port = socket.getservbyname('pbs_resmon', 'tcp')
    except socket.error:
      mom_port = pbs.PBS_MANAGER_SERVICE_PORT

    mom_id = pbs.openrm(node.name, mom_port)

    mom_keys = pbs.get_mom_values(mom_id)
    for key in mom_keys.keys():
      print '\t%s = %s' %(key, mom_keys[key])

    print '\nTesting list with user supplied keywords'

    l = [ 'bas', 'ncpus', 'loadave' ]
    mom_keys = pbs.get_mom_values(mom_id, l)
    for key in mom_keys.keys():
      print '\t%s = %s' %(key, mom_keys[key])
    print ''
    pbs.closerm(mom_id)
Beispiel #3
0
def update_all_nodes(batchserver_name):
    """ Update info about all nodes of the given batchserver.
    """
    server,created = getBatchServer(batchserver_name)
    if not pbs_data_nodes.has_key(batchserver_name):
        pbs_data_nodes[batchserver_name] = {'last_update':None, 'nodes':{}}

    if pbs_data_nodes[batchserver_name]['last_update'] and (datetime.datetime.now()-pbs_data_nodes[batchserver_name]['last_update']).total_seconds()<GlobalConfiguration.objects.get(pk=1).max_lastupdate:
        logging.debug("Nodes info is new enough for server: %s" % batchserver_name)
        print "not updated"
        return pbs_data_nodes

    print "updated"

    conn = pbs.pbs_connect(batchserver_name.encode('iso-8859-1', 'replace'))
    if conn==-1:
        logging.error("Cannot connect to %s - live data will be missing" % server.name)
        return
    statnodes = pbs.pbs_statnode(conn, "" , [], "")
    pbs.pbs_disconnect(conn)

    for sn in statnodes:
        node,created = getNode(sn.name, server)
        attr_dict = dict([ (x.name,x.value) for x in sn.attribs])
        pbs_data_nodes[batchserver_name]['nodes'][node] = update_one_node_from_pbs_data(node, attr_dict)
        pbs_data_nodes[batchserver_name]['last_update'] = datetime.datetime.now()

    return pbs_data_nodes
Beispiel #4
0
def stat_node_by_name(ID,name_node):
    nodes = pbs.pbs_statnode(ID,name_node,"NULL","NULL")
    for node in nodes:
	print node.name
	for attrib in node.attribs:
	    if attrib.resource:
		print attrib.name, attrib.resource ,attrrib.value
	    else:
		print attrib.name, attrib.value
Beispiel #5
0
def write_stat_nodes(ID,file_name):
    stat_file = open(file_name,"w")
    nodes = pbs.pbs_statnode(ID, "", "NULL", "NULL")
    for node in nodes:
	stat_file.write(node.name)
	for attrib in node.attribs:
	    stat_file.write(attrib.value)

    stat_file.close()
    return nodes
Beispiel #6
0
def statjob(id_conn,id_job):
    result = []
    jobs = pbs.pbs_statjob(id_conn, id_job, "NULL", "NULL")
    nodes = pbs.pbs_statnode(id_conn, "", "NULL", "NULL")
    for job in jobs:
        for attrib in job.attribs:
            for node in nodes:
                if string.find(attrib.value,node.name) != -1:
                    result.append(node.name)

    return result
Beispiel #7
0
def print_header():
    # try connecting to the PBS server
#    print " "
    print "Content-Type: text/html"
#    print " "
#    print " "
    try:
	con = pbs.pbs_connect(pbs_server)
	nodes = pbs.pbs_statnode(con, "", "NULL", "NULL")
    except pbserr, error:
	print "<h1>Error connecting to PBS server:</h1><tt>",error,"</tt>"
        sys.exit(1)	
Beispiel #8
0
	def _statnode(self, node_name='', attrib_list=None):
		"""Get the node config from the pbs server"""
		if attrib_list:
			self._list_2_attrib(attrib_list)
		else:
			self.attribs = 'NULL' 
			
		self._connect()
		nodes = pbs.pbs_statnode(self.con, node_name, self.attribs, 'NULL')
		self._disconnect() 
		
		self.nodes = {}
		self._list_2_dict(nodes, node)
Beispiel #9
0
def update_all_nodes(conn,bs):
    """
    Update all nodes in the database using the given pbs connection conn
    and batch server bs.
    """
    statnodes = pbs.pbs_statnode(conn,"",[],"")
    for sn in statnodes:
        if sn.name.find('.')==-1:
            longname = sn.name+'.'+bs.domainname
        else:
            longname = sn.name
        n,created = Node.objects.get_or_create(name=longname, server=bs)
        if created:
            log(LOG_INFO, "new node will be created: %s" % (longname))
            n.server = bs
            try:
                n.subcluster = Subcluster.objects.get(name=n.name_without_number())
                log(LOG_INFO, "new node will be put in subluster: %s" % (n.subcluster.name))
            except Subcluster.DoesNotExist:
                log(LOG_INFO, "new node will be out of any subcluster: %s" % (longname))
        dattrs = attribs_to_dict(sn.attribs)
        n.state = dattrs['state']
        log(LOG_INFO, "name: %s, state: %s" % (n.name, n.state))
        try:
            n.properties = dattrs['properties']
            log(LOG_INFO, "name: %s, properties: %s" % (n.name, n.properties))
        except KeyError:             
            n.properties = ''
        if dattrs.has_key('jobs'):
            try:
                slotnum_fulljobid = [ x.strip().split('/') for x in dattrs['jobs'].split(',') ]
            except KeyError:
                log(LOG_ERROR, "dattrs: %s" % str(dattrs))
            for slotnum, fulljobid in slotnum_fulljobid:
                # soon pbspro will be gone
                if bs.name=='ce2.egee.cesnet.cz':
                    tmp = slotnum
                    slotnum = fulljobid
                    fulljobid = tmp
                jobid,servername = fulljobid.split('.',1)
                js,created = JobSlot.objects.get_or_create(slot=slotnum, node=n)
                if created:
                    log(LOG_INFO, "new jobslot will be created: %s in %s" % (slotnum, longname))

                j = update_one_job(conn, jobid, bs)
                js.job = j
                js.save()
            
        n.save()
Beispiel #10
0
def main():

  pbs_server = pbs.pbs_default()
  if not pbs_server:
    print "No default pbs server"
    sys.exit(1)

  con = pbs.pbs_connect(pbs_server)
  nodes = pbs.pbs_statnode(con, "", "NULL", "NULL")


  for node in nodes:
    print node.name
    for attrib in node.attribs:
      print '\t', attrib.name, '=', attrib.value
	def _statnode(self, select='', attrib_list=None, property=None):
		"""Get the node config from the pbs server"""
		if attrib_list:
			self._list_2_attrib(attrib_list)
		else:
			self.attribs = 'NULL' 
			
		if property:
			select = ':%s' %(property)

		self._connect()
		nodes = pbs.pbs_statnode(self.con, select, self.attribs, 'NULL')
		self._disconnect() 
		
		self._list_2_dict(nodes, node)
Beispiel #12
0
def update_one_node(node):
    """ Update live info about the given node 
    """
    conn = pbs.pbs_connect(node.server.name.encode('iso-8859-1', 'replace'))
    if conn==-1:
        logging.error("Cannot connect to %s - live data will be missing" % server.name)
        return
    statnodes = pbs.pbs_statnode(conn, node.name.encode('iso-8859-1', 'replace') , [], "")
    pbs.pbs_disconnect(conn)

    if len(statnodes)==0:
        logging.error("pbs_statnode failed for node: %s" % node.name)
        return
    if len(statnodes)>1:
        logging.warning("pbs_statnode returned more than one records for node: %s" % node.name)

    attr_dict = dict([ (x.name,x.value) for x in statnodes[0].attribs])
    update_one_node_from_pbs_data(node, attr_dict)
    node.save()
Beispiel #13
0
def main():
    state_list = []
    node_list = []
    node_nr = 0

    if len(sys.argv) > 1:
        pbs_server = sys.argv[1]
    else:
        pbs_server = pbs.pbs_default()
        if not pbs_server:
            print "No default pbs server, usage: pbsmon [server] "
            sys.exit(1)

    con = pbs.pbs_connect(pbs_server)
    if con < 0:
        errno, text = pbs.error()
        print errno, text
        sys.exit(1)

    # We are only interested in the state and jobs of a node
    #
    attrl = pbs.new_attrl(2)
    attrl[0].name = "state"
    attrl[1].name = "jobs"

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

    # Some is het None dan weer NULL, beats me
    #
    for node in nodes:

        # display_node_status(batch_info)
        node_attr = node.attribs

        # A node can have serveral states, huh. We are only
        # interested in first entry.
        #
        temp = string.splitfields(node_attr[0].value, ",")
        state = temp[0]

        # look if on a free node a job is scheduled, then mark it
        # as other state
        #
        if state == pbs.ND_free:
            if len([x for x in node_attr if x.name == "jobs"]):
                state_list.append(translate_state[pbs_ND_free_and_job])
            else:
                state_list.append(translate_state[state])
        else:
            state_list.append(translate_state[state])

        re_host = re.compile(
            r"""

      (?P<name>\d+)

      """,
            re.VERBOSE,
        )

        result = re_host.search(node.name)
        if result:
            node_list.append(result.group("name"))
        else:
            node_nr = node_nr + 1
            node_list.append(str(node_nr))

    display_cluster_status(node_list, state_list)
def pbsmon():
    global NODES_PER_RACK, N_RACKS, PBS_STATES

    if len(sys.argv) > 1:
        pbs_server = sys.argv[1]
    else:
        pbs_server = pbs.pbs_default()

    if not pbs_server:
        print "No default pbs server, usage: %s [server]" % os.path.basename(sys.argv[0])
        sys.exit(1)

    con = pbs.pbs_connect(pbs_server)
    if con < 0:
        errno, text = pbs.error()
        print errno, text
        sys.exit(1)

    # get the state of the nodes
    attrl = pbs.new_attrl(2)
    attrl[0].name = "state"
    attrl[1].name = "jobs"
    nodes = pbs.pbs_statnode(con, "", attrl, "NULL")

    node_dict = {}

    count_states = {}
    for key in PBS_STATES.keys():
        count_states[key] = 0

    for node in nodes:
        node_attr = node.attribs
        temp = string.split(node_attr[0].value, ",")
        state = temp[0]
        state_char = PBS_STATES[state]
        count_states[state] = count_states[state] + 1

        if state == pbs.ND_free:
            if len(node_attr) > 1:
                # 				print 'TD: %s' % node.name, node_attr[1]
                state_char = PBS_STATES[pbs_ND_single]
                count_states[pbs.ND_free] = count_states[pbs.ND_free] - 1
                count_states[pbs_ND_single] = count_states[pbs_ND_single] + 1

        # 		print 'TD: %s %s' % (node.name, state_char)
        node_dict[node.name] = state_char

    legend = PBS_STATES.keys()
    legend.sort()

    # print nodes with gb-r%dn%d naming scheme
    print "  ",
    for rack in xrange(1, N_RACKS + 1):
        print "%2d" % rack,
    print

    for node_nr in xrange(1, NODES_PER_RACK + 1):
        print "%2d" % node_nr,

        for rack in xrange(1, N_RACKS + 1):
            node_name = "gb-r%dn%d" % (rack, node_nr)

            if node_dict.has_key(node_name):
                print " %s" % node_dict[node_name],

                del node_dict[node_name]
            else:
                print "  ",

        if node_nr - 1 < len(legend):
            state = legend[node_nr - 1]
            print "  %s  %-13s : %d" % (PBS_STATES[state], state, count_states[state])
        else:
            print

    print

    # any other nodes?
    arr = node_dict.keys()
    if arr:
        arr.sort()

        for node in arr:
            print "%s %s" % (node, node_dict[node])

        print
Beispiel #15
0
def stat_nodeconf(ID):
    nodes = pbs.pbs_statnode(ID, "", "NULL", "NULL")
    for node in nodes:
	print node.name	
	for attrib in node.attribs:
	    print attrib.value