Example #1
0
def read_eventrec(path):
    """
    read lsb.streams
    """

    if lsf.lsb_init("test") > 0:
        exit(1)

    s = lsf.lsbStream()
    s.streamFile = path
    s.maxStreamSize = 1024 * 1024 * 1024
    s.maxStreamFileNum = 10

    cc = lsf.lsb_openstream(s)
    if cc < 0:
        print("Cannot open the file %s. Ensure you are the file owner." %
              (path))
        exit(1)

    lineNum = lsf.new_intp()
    lsf.intp_assign(lineNum, 0)
    flag = 1

    while flag > 0:
        log = lsf.lsb_readstream(lineNum)
        if log:
            display(log)
        else:
            flag = 0

    lsf.lsb_closestream(path)
def run_job(command):
    """
    Run a job...
    """
    submitreq = lsf.submit()
    submitreq.command = command
    submitreq.options = 0
    submitreq.options2 = 0

    limits = []
    for i in range(0, lsf.LSF_RLIM_NLIMITS):
        limits.append(lsf.DEFAULT_RLIMIT)

    submitreq.rLimits = limits
 
    submitreq.beginTime = 0
    submitreq.termTime = 0
    submitreq.numProcessors = 1
    submitreq.maxNumProcessors = 1

    submitreply = lsf.submitReply()

    if lsf.lsb_init("test") > 0:
        exit(1)

    job_id = lsf.lsb_submit(submitreq, submitreply)
    return job_id
Example #3
0
def run_job(command):
    """
    Run a job...
    """
    submitreq = lsf.submit()
    submitreq.command = command
    submitreq.options = 0
    submitreq.options2 = 0

    limits = []
    for i in range(0, lsf.LSF_RLIM_NLIMITS):
        limits.append(lsf.DEFAULT_RLIMIT)

    submitreq.rLimits = limits
 
    submitreq.beginTime = 0
    submitreq.termTime = 0
    submitreq.numProcessors = 1
    submitreq.maxNumProcessors = 1

    submitreply = lsf.submitReply()

    if lsf.lsb_init("test") > 0:
        exit(1)

    job_id = lsf.lsb_submit(submitreq, submitreply)
    return job_id
def read_eventrec(path):
    """
    read lsb.streams
    """

    if lsf.lsb_init("test") > 0:
        exit(1)

    s = lsf.lsbStream()
    s.streamFile = path;
    s.maxStreamSize = 1024*1024*1024
    s.maxStreamFileNum = 10;

    cc = lsf.lsb_openstream(s)
    if cc < 0 :
        print("Cannot open the file %s. Ensure you are the file owner." % (path))
        exit(1);

    lineNum = lsf.new_intp()
    lsf.intp_assign(lineNum, 0)
    flag = 1

    while flag > 0:
        log = lsf.lsb_readstream(lineNum)
        if log:
            display(log)
        else:
            flag = 0
Example #5
0
def query_queue(queue_name):
    """
    "query queue info"
    """

    if lsf.lsb_init("test") > 0:
        return -1;

    intp_num_queues = lsf.new_intp();
    lsf.intp_assign(intp_num_queues, 1);
    strArr = lsf.new_stringArray(1);
    #print lsf.intp_value(intp_num_queues);
    lsf.stringArray_setitem(strArr, 0, queue_name);
    #print lsf.stringArray_getitem(strArr, 0);
    queueInfo = lsf.lsb_queueinfo(strArr,intp_num_queues,None,None,0);
    if queueInfo != None:
        print 'queueInfo is not null';
    else:
        print 'queueInfo is null'
        return -1;

    print 'queue name = %s' % queueInfo.queue;
    print 'queue description = %s' % queueInfo.description; 

    return 0;
Example #6
0
def printLimit():
    if lsf.lsb_init("test") > 0:
        return -1

    req = lsf.limitInfoReq()
    req.name = " "
    pp_ents = lsf.calloc_limitInfoEntPtrPtr()
    intp_size = lsf.copy_intp(0)
    lsinfo = lsf.lsInfo()

    rc = lsf.lsb_limitInfo(req, pp_ents, intp_size, lsinfo)
    if rc == -1:
        print('call lsf failed')
        return -1

    ents = lsf.limitInfoEntPtrPtr_value(pp_ents)
    size = lsf.intp_value(intp_size)

    print("{} limits in the cluster.".format(size))

    for i in range(size):
        ent = lsf.limitInfoEntArray_getitem(ents, i)
        print('No.{} limit name : {}'.format(i, ent.name))

    return 0
Example #7
0
def modify_job(job_id):
    """
    Modify a job...
    """
    submitreq = lsf.submit()
    submitreq.command = str(job_id);
    submitreq.options = 0
    submitreq.resReq = "rusage[mem=3500]"
    submitreq.options |= lsf.SUB_MODIFY
    submitreq.options |= lsf.SUB_RES_REQ
    submitreq.options2 = 0
    submitreq.options3 = 0
    submitreq.options4 = 0

    limits = []
    for _ in range(0, lsf.LSF_RLIM_NLIMITS):
        limits.append(lsf.DEFAULT_RLIMIT)
    submitreq.rLimits = limits

    submitreply = lsf.submitReply()

    if lsf.lsb_init("test") > 0:
        exit(1)

    
    job_id = lsf.lsb_modify(submitreq, submitreply, -1)
    return job_id
Example #8
0
def create_reply():
    reply = lsf.submitReply()

    init_code = lsf.lsb_init('')
    if init_code > 0:
        raise RuntimeError("Failed lsb_init, errno = %d" % lsf.lsb_errno())

    return reply
Example #9
0
def init():
    global _ALREADY_INIT
    if _ALREADY_INIT:
        return

    init_code = api.lsb_init(None)
    if init_code != 0:
        raise LSFBindingException("Failed lsb_init")
    _ALREADY_INIT = True
Example #10
0
def init():
    global _ALREADY_INIT
    if _ALREADY_INIT:
        return

    init_code = api.lsb_init(None)
    if init_code != 0:
        raise LSFBindingException('Failed lsb_init')
    _ALREADY_INIT = True
Example #11
0
def connect(queue="batch"):
    """
    Call this to connect to lsf. The name of the queue does not have to be the
    one you actually want to query, it just needs to be a valid queue.

    :param queue: (str) queue that exists in lsf.
    :return:
    """
    if lsf.lsb_init(queue) > 0:
        raise Exception("Couldn't connect.")
def printQueueInfo():
    if lsf.lsb_init("test") > 0:
        return -1

    strArr = lsf.new_stringArray(2)
    lsf.stringArray_setitem(strArr, 0, "normal")
    lsf.stringArray_setitem(strArr, 1, "short")

    for info in lsf.get_queue_info_by_name(strArr, 2):
        print info.queue
        print info.description
        print ''

    return 0
def printQueueInfo():
    if lsf.lsb_init("test") > 0:
        return -1;

    strArr = lsf.new_stringArray(1); #array length is 2
    lsf.stringArray_setitem(strArr, 0, "normal");
#    lsf.stringArray_setitem(strArr, 1, "short");

    for info in lsf.get_queue_info_by_name(strArr, 1):
        print(info.queue)
        print(info.description)
        print('')

    return 0;
Example #14
0
def printQueueInfo():
    if lsf.lsb_init("test") > 0:
        return -1;

    strArr = lsf.new_stringArray(2); //array length is 2
    lsf.stringArray_setitem(strArr, 0, "normal");
    lsf.stringArray_setitem(strArr, 1, "short");

    for info in lsf.get_queue_info_by_name(strArr, 2):
        print info.queue;
        print info.description;
        print ''

    return 0;
Example #15
0
def printQueueInfo():
    if lsf.lsb_init("test") > 0:
        return -1

    strArr = lsf.new_stringArray(1)
    #array length is 2
    lsf.stringArray_setitem(strArr, 0, "normal")
    #    lsf.stringArray_setitem(strArr, 1, "short");

    for info in lsf.get_queue_info_by_name(strArr, 1):
        print(info.queue)
        print(info.description)
        print('')

    return 0
Example #16
0
def queue_info(queue_name=None):
    """
    :param queue_name:
    :return:
    python api style
    """
    if lsf.lsb_init("test") != 0:
        exit(1)

    queue = lsf.new_stringArray(1)
    lsf.stringArray_setitem(queue, 0, queue_name)

    for info in lsf.get_queue_info_by_name(queue, 0):
        print info.queue
        print info.description
        print ''
Example #17
0
def printHostInfo():
    if lsf.lsb_init("test") > 0:
        return -1

    intp_nhosts = lsf.new_intp()
    lsf.intp_assign(intp_nhosts, 0)
    all_lsload_data = lsf.ls_load_py(None, intp_nhosts, 0, None)
    nhosts = lsf.intp_value(intp_nhosts)

    print("{} hosts in the cluster.".format(nhosts))

    for i in range(nhosts):
        host = all_lsload_data[i]
        print('No.{} host name : {}'.format(i, host.hostName))

    return 0
Example #18
0
def printAppInfo():
    if lsf.lsb_init("test") > 0:
        return -1

    intp_nent = lsf.new_intp()
    ents = lsf.lsb_appInfo(intp_nent)
    nent = lsf.intp_value(intp_nent)

    print("{} apps in the cluster.".format(nent))

    for i in range(nent):
        ent = lsf.appInfoEntArray_getitem(ents, i)
        print('No.{} app name : {}, description: {}'.format(
            i, ent.name, ent.description))

    return 0
Example #19
0
def query_queue(queue_name):
    """
    c api style
    """

    if lsf.lsb_init("test") != 0:
        exit(1)

    intp_num_queues = lsf.new_intp()
    lsf.intp_assign(intp_num_queues, 1)
    queue_p = lsf.new_stringArray(1)
    lsf.stringArray_setitem(queue_p, 0, queue_name)
    info = lsf.lsb_queueinfo(queue_p, intp_num_queues, None, None, 0)
    if info is not None:
        return info.queue, info.description
    else:
        print 'queueInfo is null'
        exit(1)
Example #20
0
def read_eventrec(path):
    """
    read lsb.events
    """
    lineNum = lsf.new_intp()
    lsf.intp_assign(lineNum, 0)
    fp = lsf.fopen(path, "r")
    flag = 1

    if lsf.lsb_init("test") > 0:
        exit(1)

    while flag > 0:
        log = lsf.lsb_geteventrec(fp, lineNum)
        if log:
            display(log)
        else:
            flag = 0
def read_eventrec(path):
    """
    read lsb.events
    """
    lineNum = lsf.new_intp()
    lsf.intp_assign(lineNum, 0)
    fp = lsf.fopen(path, "r")
    flag = 1

    if lsf.lsb_init("test") > 0:
        exit(1)

    while flag > 0:
        log = lsf.lsb_geteventrec(fp, lineNum)
        if log:
            display(log)
        else:
            flag = 0
Example #22
0
def printHostInfo():
    if lsf.lsb_init("test") > 0:
        return -1;

    intp_nhosts = lsf.new_intp()
    lsf.intp_assign(intp_nhosts, 0) 
    hostsdata = lsf.ls_load(None, intp_nhosts, 0, None)
    nhosts = lsf.intp_value(intp_nhosts)
    all_lsload_data = lsf.hostLoadArray_frompointer(hostsdata)

    print("{} hosts in the cluster.".format(nhosts))

    for i in range(nhosts) :
        host = all_lsload_data[i]
        hostname = ctypes.cast( host.hostName, ctypes.c_char_p)
        print('No.{} host name : {}'.format(i, hostname.value))

    return 0
Example #23
0
def queryHostGroupInfo():
    """
    "query host group info"
    """
    if lsf.lsb_init("queryHostGroupInfo") > 0:
        return -1

    strArr = lsf.new_stringArray(2)
    lsf.stringArray_setitem(strArr, 0, "hg1")
    lsf.stringArray_setitem(strArr, 1, "hg2")
    for hgroupInfo in lsf.get_hostgroup_info_by_name(strArr, 2):
        if hgroupInfo != None:
            print 'hgroup name = %s' % hgroupInfo.group
            print 'hgroup list = %s' % hgroupInfo.memberList
        else:
            print 'hgroupInfo is null'
            return -1

    return 0
def read_streamline(path):
    """
    Use lsb_readstreamline() to parse the file
    """

    if lsf.lsb_init("test") > 0:
        exit(1)

    file = open(path)
 
    while 1:
        lines = file.readlines(100000)
        if not lines:
            break
        for line in lines:
            log = lsf.lsb_readstreamline(line)
            if log:
                display(log)
            else:
                break
Example #25
0
def read_streamline(path):
    """
    Use lsb_readstreamline() to parse the file
    """

    if lsf.lsb_init("test") > 0:
        exit(1)

    file = open(path)

    while 1:
        lines = file.readlines(100000)
        if not lines:
            break
        for line in lines:
            log = lsf.lsb_readstreamline(line)
            if log:
                display(log)
            else:
                break
def queryHostGroupInfo():
    """
    "query host group info"
    """
    if lsf.lsb_init("queryHostGroupInfo") > 0:
        return -1;

    strArr = lsf.new_stringArray(2);
    lsf.stringArray_setitem(strArr, 0, "hg1");
    lsf.stringArray_setitem(strArr, 1, "hg2");
    for hgroupInfo in lsf.get_hostgroup_info_by_name(strArr,2):
        if hgroupInfo != None:
            print('hgroup name = %s' % hgroupInfo.group);
            print('hgroup list = %s' % hgroupInfo.memberList);
        else:
            print('hgroupInfo is null')
            return -1;

    lsf.delete_stringArray(strArr);

    return 0;
Example #27
0
def kill_jobs():
    """
    Kill multiple jobs...
    """
    signalbulkjobs = lsf.signalBulkJobs()
    signalbulkjobs.signal = 9
    signalbulkjobs.njobs = 3 
    signalbulkjobs.jobs = lsf.new_LS_LONG_INTArray(3)
    lsf.LS_LONG_INTArray_setitem(signalbulkjobs.jobs, 0, 1797)
    lsf.LS_LONG_INTArray_setitem(signalbulkjobs.jobs, 1, 1798)
    lsf.LS_LONG_INTArray_setitem(signalbulkjobs.jobs, 2, 1799)
    #signalbulkjobs.flags = 0
    #signalbulkjobs.numkvs = 0
    #signalbulkjobs.kvs = None

    if lsf.lsb_init("test") > 0:
        exit(1)

    
    result = lsf.lsb_killbulkjobs(signalbulkjobs)
    return result
def read_eventrec(path):
    """
    read lsb.events
    """
    lineNum = lsf.new_intp()
    lsf.intp_assign(lineNum, 0)
    fp = lsf.fopen(path, "r")
    if fp is None:
        print("The file %s does not exist." % path)
        sys.exit(1)

    flag = 1

    if lsf.lsb_init("test") > 0:
        exit(1)

    while flag > 0:
        log = lsf.lsb_geteventrec(fp, lineNum)
        if log:
            display(log)
        else:
            flag = 0
Example #29
0
def printLimit():
    if lsf.lsb_init("test") > 0:
        return -1

    req = lsf.limitInfoReq()
    req.name = " "
    pp_ents = lsf.calloc_limitInfoEntPtrPtr()
    intp_size = lsf.copy_intp(0)
    lsinfo = lsf.lsInfo()

    rc = lsf.lsb_limitInfo(req, pp_ents, intp_size, lsinfo)
    if rc == -1:
        print('call lsf failed')
        return -1

    ents = lsf.limitInfoEntPtrPtr_value(pp_ents)
    size = lsf.intp_value(intp_size)

    print("{} limits in the cluster.".format(size))

    for i in range(size):
        ent = lsf.limitInfoEntArray_getitem(ents, i)
        # print limit name
        print('Limit No.{} : {}'.format(i, ent.name))

        # print confInfo in the limit
        printLimitItem('confInfo', ent.confInfo)

        # print usageC in the limit
        print('usageC : {}'.format(ent.usageC))
        # print usageInfo in the limit
        all_usageInfo = lsf.limitItemArray_frompointer(ent.usageInfo)
        for j in range(ent.usageC):
            printLimitItem('usageInfo', all_usageInfo[j])

        # print ineligible in the limit
        print('ineligible : {}\n\n'.format(ent.ineligible))

    return 0
Example #30
0
def read_eventrec(path):
    """
    read lsb.events
    """
    lineNum = lsf.new_intp()
    lsf.intp_assign(lineNum, 0)
    fp = lsf.fopen(path, "r")
    if fp is None:
        print("The file %s does not exist." % path)
        sys.exit(1)

    flag = 1

    if lsf.lsb_init("test") > 0:
        exit(1)

    while flag > 0:
        log = lsf.lsb_geteventrec(fp, lineNum)
        if log:
            display(log)
        else:
            flag = 0
Example #31
0
def read_eventrec(path):
    """
    read lsb.streams
    """
    s = lsf.lsbStream()
    s.streamFile = path;
    s.maxStreamSize = 1024*1024*1024
    s.maxStreamFileNum = 10;

    lsf.lsb_openstream(s)

    lineNum = lsf.new_intp()
    lsf.intp_assign(lineNum, 0)
    flag = 1

    if lsf.lsb_init("test") > 0:
        exit(1)

    while flag > 0:
        log = lsf.lsb_readstream(lineNum)
        if log:
            display(log)
        else:
            flag = 0
Example #32
0
def init():
    lsf.lsb_init('Filco')
from pythonlsf import lsf

if lsf.lsb_init("test") > 0:
    exit(1)

print('\n Hosts in cluster: %s' % lsf.get_host_names())

print('\n Clustername: {0:30s} \n'.format(lsf.ls_getclustername()))

print('{0:15s} {1:20s} {2:20s} {3:5s} {4:4s}'.format('Hostname', 'Type',
                                                     'Model', 'Cores', 'Load'))

for info in lsf.get_host_info():
    #Deal with the case when hostname contain "-".
    if '-' in info.hostName:
        load = lsf.get_host_load("hname=" + "'" + info.hostName + "'", lsf.R15M)
    else:
        load = lsf.get_host_load("hname=" + info.hostName, lsf.R15M)
    
    if load >= 65535:
        load = -1

    print('{0:15s} {1:20s} {2:20s} {3:5d} {4:4.2f}'.format(info.hostName,
                                                           info.hostType,
                                                           info.hostModel,
                                                           info.cores,
                                                           load))

    resources = ""
    index = 0;
    if info.nRes > 0:
Example #34
0
#! /usr/bin/env python

from pythonlsf import lsf

if lsf.lsb_init("test") > 0:
    exit(1)

print '\n Hosts in cluster: ', lsf.get_host_names()

print '\n Clustername: ', lsf.ls_getclustername(), '\n'

print '{0:15s} {1:20s} {2:20s} {3:5s} {4:4s}'.format('Hostname', 'Type',
                                                     'Model', 'Cores', 'Load')

for info in lsf.get_host_info():
    #Deal with the case when hostname contain "-".
    if '-' in info.hostName:
        load = lsf.get_host_load("hname=" + "'" + info.hostName + "'",
                                 lsf.R15M)
    else:
        load = lsf.get_host_load("hname=" + info.hostName, lsf.R15M)

    if load >= 65535:
        load = -1

    print '{0:15s} {1:20s} {2:20s} {3:5d} {4:4.2f}'.format(
        info.hostName, info.hostType, info.hostModel, info.cores, load)

    resources = ""
    index = 0
    if info.nRes > 0:
Example #35
0
def init():
    lsf.lsb_init('lsfstats')
Example #36
0
def init():
    lsf.lsb_init('Filco')
Example #37
0
        job_status = JobStat.RUN.name
    elif status & lsf.JOB_STAT_SSUSP:
        job_status = JobStat.SSUSP.name
    elif status & lsf.JOB_STAT_USUSP:
        job_status = JobStat.USUSP.name
    elif status & lsf.JOB_STAT_EXIT:
        job_status = JobStat.EXIT.name
    elif status & lsf.JOB_STAT_DONE:
        job_status = JobStat.DONE.name
    elif status & lsf.JOB_STAT_PDONE:
        job_status = JobStat.PDONE.name
    elif status & lsf.JOB_STAT_PERR:
        job_status = JobStat.PERR.name
    elif status & lsf.JOB_STAT_WAIT:
        job_status = JobStat.WAIT.name
    elif status & lsf.JOB_STAT_RUNKWN:
        job_status = JobStat.RUNKWN.name
    elif status & lsf.JOB_STAT_UNKWN:
        job_status = JobStat.UNKWN.name
    else:
        job_status = JobStat.UNKWN.name
    return job_status


if __name__ == '__main__':
    if lsf.lsb_init("test") != 0:
        raise Exception(lsf.lsb_sysmsg())
    jobs = get_jobs()  # fetch all
    for job in jobs:
        print job