示例#1
0
def main():
    """
    get-bootable-blocks main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ],
        [ cb_gtzero       , (True,) ], # return int
        [ cb_bgq_geo      , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)
    parser.parse_it() # parse the command line
    opts   = parser.options
    args   = parser.args

    if parser.no_args():
        client_utils.print_usage(parser)
        sys.exit(1)

    block_loc   = args[0]
    idle_blocks = client_utils.component_call(SYSMGR, False, 'get_idle_blocks', (block_loc, opts.query_size, opts.geo_list))
    client_utils.logger.info("\n".join(idle_blocks))
示例#2
0
def main():
    """
    qdel main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    user = client_utils.getuid()

    # Set required default values: None

    parser.parse_it() # parse the command line

    jobids = client_utils.validate_jobid_args(parser)
    jobs   = [{'tag':'job', 'user':user, 'jobid':jobid} for jobid in jobids]

    deleted_jobs = client_utils.component_call(QUEMGR, True, 'del_jobs', (jobs, False, user))
    time.sleep(1)
    if deleted_jobs:
        data = [('JobID','User')] + [(job.get('jobid'), job.get('user')) for job in deleted_jobs]
        client_utils.logger.info("      Deleted Jobs")
        client_utils.print_tabular(data)
示例#3
0
def main():
    """
    setres main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [cb_debug, ()]
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    whoami = client_utils.getuid()
    parser.parse_it()  # parse the command line

    validate_args(parser)

    opt = parser.options
    args = parser.args

    if opt.down:
        delta = client_utils.component_call(SYSMGR, False, 'nodes_down',
                                            (args, whoami))
        client_utils.logger.info("nodes marked down:")
        for d in delta:
            client_utils.logger.info("   %s" % d)
        client_utils.logger.info("")
        client_utils.logger.info("unknown nodes:")
        for a in args:
            if a not in delta:
                client_utils.logger.info("   %s" % a)

    elif opt.up:
        delta = client_utils.component_call(SYSMGR, False, 'nodes_up',
                                            (args, whoami))
        client_utils.logger.info("nodes marked up:")
        for d in delta:
            client_utils.logger.info("   %s" % d)
        client_utils.logger.info('')
        client_utils.logger.info("nodes that weren't in the down list:")
        for a in args:
            if a not in delta:
                client_utils.logger.info("   %s" % a)

    elif opt.list_nstates:
        header, output = client_utils.cluster_display_node_info()
        client_utils.printTabular(header + output)

    elif opt.queue:
        data = client_utils.component_call(SYSMGR, False,
                                           'set_queue_assignments',
                                           (opt.queue, args, whoami))
        client_utils.logger.info(data)
示例#4
0
def main():
    """
    setres main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    whoami = client_utils.getuid()
    parser.parse_it() # parse the command line

    validate_args(parser)

    opt  = parser.options
    args = parser.args

    if opt.down:
        delta = client_utils.component_call(SYSMGR, False, 'nodes_down', (args, whoami))
        client_utils.logger.info("nodes marked down:")
        for d in delta:
            client_utils.logger.info("   %s" % d)
        client_utils.logger.info("")
        client_utils.logger.info("unknown nodes:")
        for a in args:
            if a not in delta:
                client_utils.logger.info("   %s" % a)

    elif opt.up:
        delta = client_utils.component_call(SYSMGR, False, 'nodes_up', (args, whoami))
        client_utils.logger.info("nodes marked up:")
        for d in delta:
            client_utils.logger.info("   %s" % d)
        client_utils.logger.info('')
        client_utils.logger.info("nodes that weren't in the down list:")
        for a in args:
            if a not in delta:
                client_utils.logger.info("   %s" %a)

    elif opt.list_nstates:
        header, output = client_utils.cluster_display_node_info()
        client_utils.printTabular(header + output)

    elif opt.queue:
        data = client_utils.component_call(SYSMGR, False, 'set_queue_assignments', (opt.queue, args, whoami))
        client_utils.logger.info(data)
示例#5
0
def main():
    """
    qselect main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    opts = {}  # old map
    opt2spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>           <cb args>
        [cb_debug, ()],
        [cb_nodes, (False, )],  # return string
        [cb_time, (False, False, False)]
    ]  # no delta time, return minutes, return string

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    # Set required default for the query:
    query = {
        'tag': 'job',
        'jobid': '*',
        'nodes': '*',
        'walltime': '*',
        'mode': '*',
        'project': '*',
        'state': '*',
        'queue': '*'
    }

    parser.parse_it()  # parse the command line

    if not parser.no_args():
        client_utils.logger.error("qselect takes no arguments")
        sys.exit(1)

    client_utils.get_options(query, opts, opt2spec, parser)
    response = client_utils.component_call(QUEMGR, False, 'get_jobs',
                                           ([query], ))
    if not response:
        client_utils.logger.error("Failed to match any jobs")
    else:
        client_utils.logger.debug(response)
        client_utils.logger.info("   The following jobs matched your query:")
        for job in response:
            client_utils.logger.info("      %d" % job.get('jobid'))
示例#6
0
def main():
    """
    qmove main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    # Set required default values: None

    parser.parse_it() # parse the command line

    if not parser.no_args():
        client_utils.logger.error("No arguments needed")
    
    impl = client_utils.component_call(SYSMGR, False, 'get_implementation', ())

    # make sure we're on a cluster-system or orcm-system
    if ("cluster_system" != impl) and ("orcm_system" != impl):
        client_utils.logger.error("nodelist is only supported on cluster and orcm systems.  Try partlist instead.")
        sys.exit(0)

    status     = client_utils.component_call(SYSMGR, False, 'get_node_status', ())
    queue_data = client_utils.component_call(SYSMGR, False, 'get_queue_assignments', ())

    header = [['Host', 'Queue', 'State']]
    #build output list
    output = []
    for t in status:
        host_name = t[0]
        status = t[1]
        queues = []
        for q in queue_data:
            if host_name in queue_data[q]:
                queues.append(q) 
        output.append([host_name, ":".join(queues), status])
        
    client_utils.printTabular(header + output)
示例#7
0
文件: nodelist.py 项目: ido/cobalt
def main():
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    # Set required default values: None

    parser.parse_it() # parse the command line
    opt = parser.options
    args = parser.args

    #if not parser.no_args():
    #    client_utils.logger.error("No arguments needed")

    impl = client_utils.component_call(SYSMGR, False, 'get_implementation', ())

    # make sure we're on a cluster-system
    if impl not in ['cluster_system', 'alps_system']:
        client_utils.logger.error("nodelist is only supported on cluster systems.  Try partlist instead.")
        sys.exit(0)

    if impl == 'alps_system':
        if opt.list_details:
            # get list from arguments.  Currently assuing a comma separated,
            # hyphen-condensed nodelist
            client_utils.print_node_details(args)
        else:
            client_utils.print_node_list()
        return



    header, output = client_utils.cluster_display_node_info()
    if parser.options.noheader is not None:
        client_utils.printTabular(header + output, with_header_info=False)
    else:
        client_utils.printTabular(header + output)
示例#8
0
def main():
    """
    qmove main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [cb_debug, ()]
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    user = client_utils.getuid()

    # Set required default values: None

    parser.parse_it()  # parse the command line

    queue, jobs = validate_args(parser, user)
    filters = client_utils.get_filters()
    jobdata = client_utils.component_call(QUEMGR, False, 'get_jobs', (jobs, ))

    response = []
    # move jobs to queue
    for job in jobdata:
        orig_job = job.copy()
        job.update({'queue': queue})
        client_utils.process_filters(filters, job)
        [j] = client_utils.component_call(QUEMGR, False, 'set_jobs',
                                          ([orig_job], job, user))
        response.append("moved job %d to queue '%s'" %
                        (j.get('jobid'), j.get('queue')))

    if not response:
        client_utils.logger.error("Failed to match any jobs or queues")
    else:
        for line in response:
            client_utils.logger.info(line)
示例#9
0
def main():
    """
    userres main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [( cb_debug, ())]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    parser.parse_it() # parse the command line
    args = parser.args

    if parser.no_args():
        client_utils.print_usage(parser)
        sys.exit(1)

    # Check if reservation exists
    spec = [{'name': rname, 'users':"*", 'start':'*', 'cycle':'*', 'duration':'*'} for rname in args]
    result = client_utils.component_call(SCHMGR, False, 'get_reservations', (spec,))

    if len(result) and len(result) != len(args):
        client_utils.logger.error("Reservation subset matched")
    elif not result:
        client_utils.logger.error("No Reservations matched")
        sys.exit(1)

    user_name = client_utils.getuid()
    
    for spec in result:
        if not spec['users'] or user_name not in spec['users'].split(":"):
            client_utils.logger.error("You are not a user of reservation '%s' and so cannot alter it.", spec['name'])
            continue

        if spec['cycle']:
            updates = update_start_time(spec, user_name)
        else:
            client_utils.component_call(SCHMGR, False, 'del_reservations', ([{'name':spec['name']}], user_name))
            client_utils.logger.info("Releasing reservation '%s'", spec['name'])
示例#10
0
def main():
    """
    qstat main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    delim = ':'

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        (cb_debug, ()),
        (cb_split, (delim, ))
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)
    parser.parse_it()  # parse the command line

    # Get the header instance
    hinfo = client_utils.header_info(parser)

    # Get the queues for job ids
    queues = client_utils.component_call(QUEMGR, True, 'get_queues',
                                         ([{
                                             'name': '*',
                                             'state': '*'
                                         }], ))

    #  if Q option specified then get the info for the specified queues
    if parser.options.Q != None:

        output = get_output_for_queues(parser, hinfo)

    else:

        # build query from long_header (all fields) and fetch response
        output = get_output_for_jobs(parser, hinfo, queues)

    process_the_output(output, parser, hinfo)
示例#11
0
def main():
    """
    slpstat main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [cb_debug, ()]
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    # Set required default values: None

    parser.parse_it()  # parse the command line

    if not parser.no_args():
        client_utils.logger.error('No arguments needed')

    services = client_utils.component_call(SLPMGR, False, 'get_services',
                                           ([{
                                               'tag': 'service',
                                               'name': '*',
                                               'stamp': '*',
                                               'location': '*'
                                           }], ))

    if services:
        header = [('Name', 'Location', 'Update Time')]
        output = [(service['name'], service['location'],
                   time.strftime("%c", time.localtime(service['stamp'])))
                  for service in services]
        client_utils.print_tabular(header + [tuple(item) for item in output])
    else:
        client_utils.logger.info("no services registered")
示例#12
0
def main():
    """
    setres main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec = {}  # map of destination option strings and parsed values
    opts = {}  # old map
    opt2spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>           <cb args>
        [cb_time, (False, True, True)],  # no delta time, Seconds, return int
        [cb_date, (True, )],  # Allow to set the date to 'now'
        [cb_passthrough, ()],
        [cb_debug, ()],
        [cb_res_users, ()]
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    user = client_utils.getuid()

    parser.parse_it()  # parse the command line
    opt_count = client_utils.get_options(spec, opts, opt2spec, parser)

    # if continue to process options then
    if validate_args(parser, spec, opt_count):

        # modify an existing reservation
        if parser.options.modify_res != None:
            modify_reservation(parser)

        # add new reservation
        else:
            add_reservation(parser, spec, user)
示例#13
0
def main():
    """
    qmove main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    user = client_utils.getuid()

    # Set required default values: None

    parser.parse_it() # parse the command line

    queue,jobs = validate_args(parser,user)
    filters    = client_utils.get_filters()
    jobdata    = client_utils.component_call(QUEMGR, False, 'get_jobs', (jobs,))

    response = []
    # move jobs to queue
    for job in jobdata:
        orig_job = job.copy()
        job.update({'queue':queue})
        client_utils.process_filters(filters,job)
        [j] = client_utils.component_call(QUEMGR, False, 'set_jobs', ([orig_job],job,user))
        response.append("moved job %d to queue '%s'" % (j.get('jobid'), j.get('queue')))

    if not response:
        client_utils.logger.error("Failed to match any jobs or queues")
    else:
        for line in response:
            client_utils.logger.info(line)
示例#14
0
文件: setres.py 项目: ido/cobalt
def main():
    """
    setres main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec     = {} # map of destination option strings and parsed values
    opts     = {} # old map
    opt2spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>           <cb args>
        [ cb_time                , (False, True, True) ], # no delta time, Seconds, return int
        [ cb_date                , (True,) ], # Allow to set the date to 'now'
        [ cb_passthrough         , () ],
        [ cb_debug               , () ],
        [ cb_res_users           , () ]] 

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    user = client_utils.getuid()

    parser.parse_it() # parse the command line
    opt_count = client_utils.get_options(spec, opts, opt2spec, parser)

    # if continue to process options then
    if validate_args(parser,spec,opt_count):

        # modify an existing reservation
        if parser.options.modify_res != None:
            modify_reservation(parser)
        
        # add new reservation
        else:
            add_reservation(parser,spec,user)
示例#15
0
def main():
    """
    releaseres main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [(cb_debug, ())]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    parser.parse_it()  # parse the command line
    args = parser.args

    if parser.no_args():
        client_utils.print_usage(parser)
        sys.exit(1)

    # Check if reservation exists
    spec = [{'name': arg, 'partitions': '*'} for arg in args]
    result = client_utils.component_call(SCHMGR, False, 'get_reservations',
                                         (spec, ))

    if len(result) and len(result) != len(args):
        client_utils.logger.error("Reservation subset matched")
    elif not result:
        client_utils.logger.error("No Reservations matched")
        sys.exit(1)

    result = client_utils.component_call(SCHMGR, False, 'release_reservations',
                                         (spec, client_utils.getuid()))
    for resinfo in result:
        partitions = resinfo['partitions'].split(':')
        client_utils.logger.info(
            "Released reservation '%s' for partitions: %s", resinfo['name'],
            str(partitions))
示例#16
0
文件: qstat.py 项目: ido/cobalt
def main():
    """
    qstat main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    delim = ':'

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        ( cb_debug        , () ),
        ( cb_split        , (delim,) ) ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)
    parser.parse_it() # parse the command line

    # Get the header instance 
    hinfo = client_utils.header_info(parser)

    # Get the queues for job ids
    queues = client_utils.component_call(QUEMGR, True, 'get_queues', ([{'name':'*','state':'*'}],))

    #  if Q option specified then get the info for the specified queues 
    if parser.options.Q != None:

        output = get_output_for_queues(parser,hinfo)

    else:

        # build query from long_header (all fields) and fetch response        
        output = get_output_for_jobs(parser,hinfo,queues)

    process_the_output(output,parser,hinfo)
示例#17
0
def main():
    """
    cqadm main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec = {}  # map of destination option strings and parsed values
    opts = {}  # old map
    opt2spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        (cb_debug, ()),
        (cb_gtzero, (True, )),  # return int
        (cb_time, (False, False,
                   False)),  # no delta time, minutes, return string
        (cb_path, (opts, False)),  # do not use CWD
        (cb_setqueues, ()),
        (cb_hold, ())
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    user = client_utils.getuid()

    # Set required default values: None

    parser.parse_it()  # parse the command line
    opt_count = client_utils.get_options(spec, opts, opt2spec, parser)

    jobs = validate_args(parser, spec, opt_count)

    process_cqadm_options(jobs, parser, spec, user)
示例#18
0
文件: nodelist.py 项目: ido/cobalt
def main():
    """
    qmove main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [cb_debug, ()]
    ]

    # Get the version information
    opt_def = __doc__.replace("__revision__", __revision__)
    opt_def = opt_def.replace("__version__", __version__)

    parser = ArgParse(opt_def, callbacks)

    # Set required default values: None

    parser.parse_it()  # parse the command line

    if not parser.no_args():
        client_utils.logger.error("No arguments needed")

    impl = client_utils.component_call(SYSMGR, False, "get_implementation", ())

    # make sure we're on a cluster-system
    if "cluster_system" != impl:
        client_utils.logger.error("nodelist is only supported on cluster systems.  Try partlist instead.")
        sys.exit(0)

    header, output = client_utils.cluster_display_node_info()
    if parser.options.noheader is not None:
        client_utils.printTabular(header + output, with_header_info=False)
    else:
        client_utils.printTabular(header + output)
示例#19
0
def main():
    """
    qmove main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    # Set required default values: None

    parser.parse_it() # parse the command line

    if not parser.no_args():
        client_utils.logger.error("No arguments needed")

    impl = client_utils.component_call(SYSMGR, False, 'get_implementation', ())

    # make sure we're on a cluster-system
    if "cluster_system" != impl:
        client_utils.logger.error("nodelist is only supported on cluster systems.  Try partlist instead.")
        sys.exit(0)


    header, output = client_utils.cluster_display_node_info()
    if parser.options.noheader is not None:
        client_utils.printTabular(header + output, with_header_info=False)
    else:
        client_utils.printTabular(header + output)
示例#20
0
文件: cqadm.py 项目: ido/cobalt
def main():
    """
    cqadm main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec = {}  # map of destination option strings and parsed values
    opts = {}  # old map
    opt2spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        (cb_debug, ()),
        (cb_gtzero, (True,)),  # return int
        (cb_time, (False, False, False)),  # no delta time, minutes, return string
        (cb_path, (opts, False)),  # do not use CWD
        (cb_setqueues, ()),
        (cb_hold, ()),
    ]

    # Get the version information
    opt_def = __doc__.replace("__revision__", __revision__)
    opt_def = opt_def.replace("__version__", __version__)

    parser = ArgParse(opt_def, callbacks)

    user = client_utils.getuid()

    # Set required default values: None

    parser.parse_it()  # parse the command line
    opt_count = client_utils.get_options(spec, opts, opt2spec, parser)

    jobs = validate_args(parser, spec, opt_count)

    process_cqadm_options(jobs, parser, spec, user)
示例#21
0
文件: releaseres.py 项目: ido/cobalt
def main():
    """
    releaseres main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [(cb_debug, ())]

    # Get the version information
    opt_def = __doc__.replace("__revision__", __revision__)
    opt_def = opt_def.replace("__version__", __version__)

    parser = ArgParse(opt_def, callbacks)

    parser.parse_it()  # parse the command line
    args = parser.args

    if parser.no_args():
        client_utils.print_usage(parser)
        sys.exit(1)

    # Check if reservation exists
    spec = [{"name": arg, "partitions": "*"} for arg in args]
    result = client_utils.component_call(SCHMGR, False, "get_reservations", (spec,))

    if len(result) and len(result) != len(args):
        client_utils.logger.error("Reservation subset matched")
    elif not result:
        client_utils.logger.error("No Reservations matched")
        sys.exit(1)

    result = client_utils.component_call(SCHMGR, False, "release_reservations", (spec, client_utils.getuid()))
    for resinfo in result:
        partitions = resinfo["partitions"].split(":")
        client_utils.logger.info("Released reservation '%s' for partitions: %s", resinfo["name"], str(partitions))
示例#22
0
def main():
    """
    slpstat main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    # Set required default values: None

    parser.parse_it() # parse the command line

    if not parser.no_args():
        client_utils.logger.error('No arguments needed')

    services = client_utils.component_call(SLPMGR, False, 'get_services', 
                                           ([{'tag':'service', 'name':'*', 'stamp':'*', 'location':'*'}],))

    if services:
        header = [('Name', 'Location', 'Update Time')]
        output = [ (service['name'],
                    service['location'],
                    time.strftime("%c", time.localtime(service['stamp'])))
                   for service in services ]
        client_utils.print_tabular(header + [tuple(item) for item in output])
    else:
        client_utils.logger.info("no services registered")
示例#23
0
def main():
    """
    qdel main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [cb_debug, ()]
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    user = client_utils.getuid()

    # Set required default values: None

    parser.parse_it()  # parse the command line

    jobids = client_utils.validate_jobid_args(parser)
    jobs = [{'tag': 'job', 'user': user, 'jobid': jobid} for jobid in jobids]

    deleted_jobs = client_utils.component_call(QUEMGR, True, 'del_jobs',
                                               (jobs, False, user))
    time.sleep(1)
    if deleted_jobs:
        data = [('JobID', 'User')] + [(job.get('jobid'), job.get('user'))
                                      for job in deleted_jobs]
        client_utils.logger.info("      Deleted Jobs")
        client_utils.print_tabular(data)
示例#24
0
def main():
    """
    qsub main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec = {}  # map of destination option strings and parsed values
    opts = {}  # old map
    opt2spec = {}
    def_spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        (cb_debug, ()),
        (cb_env, (opts, )),
        (cb_nodes, (False, )),  # return string
        (cb_gtzero, (False, )),  # return string
        (cb_time, (False, False,
                   False)),  # no delta time, minutes, return string
        (cb_umask, ()),
        (cb_path, (opts, True)),  # use CWD
        (cb_dep, ()),
        (cb_attrs, ()),
        (cb_mode, ()),
        (cb_user_list, (opts, )),
        (cb_geometry, (opts, ))
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    user = client_utils.getuid()

    def_spec['tag'] = 'job'
    def_spec['user'] = user
    def_spec['outputdir'] = client_utils.CWD_TAG
    def_spec['jobid'] = '*'
    def_spec['path'] = client_utils.getpath()
    def_spec['mode'] = False
    def_spec['cwd'] = client_utils.getcwd()
    def_spec['kernel'] = CN_DEFAULT_KERNEL
    def_spec['ion_kernel'] = ION_DEFAULT_KERNEL
    def_spec['queue'] = 'default'
    def_spec['umask'] = 022
    def_spec['run_project'] = False
    def_spec['user_list'] = [user]
    def_spec['procs'] = False
    def_spec['script_preboot'] = True

    parser = ArgParse(opt_def, callbacks)
    opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)
    reparse = validate_args(parser, spec)

    if reparse:
        # re-parse with new sys.argv
        # note: the first parse is necessary to make sure that
        #       the env syntax is correct for every --env option provided
        #       If not parsed prior to the union then the union could result
        #       in a valid syntax, but it would not be what the user would want.
        opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)

    client_utils.setumask(spec['umask'])
    validate_options(parser, opt_count)
    update_outputprefix(parser, spec)
    update_paths(spec)
    check_inputfile(parser, spec)
    opts = client_utils.component_call(SYSMGR, False, 'validate_job', (opts, ))
    filters = client_utils.get_filters()
    client_utils.process_filters(filters, spec)
    update_spec(opts, spec, opt2spec)
    get_interactive_command(parser, spec, opts, opt2spec, def_spec)
    jobs = client_utils.component_call(QUEMGR, False, 'add_jobs', ([spec], ))

    def on_interrupt(sig, func=None):
        '''Handler to cleanup the queued 'dummy' job if the user interrupts
        qsub -I forcibly

        '''
        try:
            spec = [{'tag': 'job', 'jobid': jobs[0]['jobid'], 'user': user}]
        except NameError:
            sys.exit(1)
        except:
            raise
        client_utils.logger.info("Deleting job %d", (jobs[0]['jobid']))
        del_jobs = client_utils.component_call(QUEMGR, False, 'del_jobs',
                                               (spec, False, user))
        client_utils.logger.info("%s", del_jobs)
        sys.exit(1)

    #reset sigint and sigterm interrupt handlers to deal with interactive failures
    signal.signal(signal.SIGINT, on_interrupt)
    signal.signal(signal.SIGTERM, on_interrupt)

    if parser.options.envs:
        client_utils.logger.debug("Environment Vars: %s", parser.options.envs)
    logjob(jobs[0], spec)

    # If this is an interactive job, wait for it to start, then ssh in
    if parser.options.interactive:
        headnode = ""
        query = [{
            'tag': 'job',
            'jobid': jobs[0]['jobid'],
            'location': '*',
            'state': "*"
        }]
        while True:
            response = client_utils.component_call(QUEMGR, False, 'get_jobs',
                                                   (query, ))
            state = response[0]['state']
            location = response[0]['location']
            if state == 'running' and location:
                headnode = location[0]
                client_utils.logger.info("Opening ssh session to %s", headnode)
                break
            elif state != 'running' and state != 'queued' and state != 'starting':
                client_utils.logger.error(
                    "ERROR: Something went wrong with job submission, did not expect job to reach %s state.",
                    response[0]['state'])
                break
            else:
                #using Cobalt Utils sleep here
                sleep(2)
        if not headnode:
            client_utils.logger.error(
                "Unable to determine head node for job %d", (jobs[0]['jobid']))
        else:
            try:
                os.putenv("COBALT_NODEFILE",
                          "/var/tmp/cobalt.%s" % (response[0]['jobid']))
                os.putenv("COBALT_JOBID", "%s" % (response[0]['jobid']))
                os.system(
                    "/usr/bin/ssh -o \"SendEnv COBALT_NODEFILE COBALT_JOBID\" %s"
                    % (headnode))
            except:
                client_utils.logger.error(
                    'Exception occurred during execution ssh session.  Job Terminated.'
                )
        spec = [{'tag': 'job', 'jobid': jobs[0]['jobid'], 'user': user}]
        jobs = client_utils.component_call(QUEMGR, False, 'del_jobs',
                                           (spec, False, user))
示例#25
0
def main():
    """
    showres main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [cb_debug, ()]
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    parser.parse_it()  # parse the command line

    if not parser.no_args():
        client_utils.logger.error("No arguments needed")

    if parser.options.verbose != None and parser.options.really_verbose != None:
        client_utils.logger.error('Only use -l or -x not both')
        sys.exit(1)

    cluster = False
    if 'cluster' in client_utils.component_call(SYSMGR, False,
                                                'get_implementation', ()):
        cluster = True

    reservations = client_utils.component_call(SCHMGR, False,
                                               'get_reservations',
                                               ([{
                                                   'name': '*',
                                                   'users': '*',
                                                   'start': '*',
                                                   'duration': '*',
                                                   'partitions': '*',
                                                   'cycle': '*',
                                                   'queue': '*',
                                                   'res_id': '*',
                                                   'cycle_id': '*',
                                                   'project': '*',
                                                   'block_passthrough': '*'
                                               }], ))

    output = []

    verbose = False
    really_verbose = False
    header = [('Reservation', 'Queue', 'User', 'Start', 'Duration',
               'Passthrough', 'Partitions', 'Remaining', 'T-Minus')]

    if parser.options.verbose:
        verbose = True
        header = [
            ('Reservation', 'Queue', 'User', 'Start', 'Duration', 'End Time',
             'Cycle Time', 'Passthrough', 'Partitions', 'Remaining', 'T-Minus')
        ]
    elif parser.options.really_verbose:
        really_verbose = True
        header = [('Reservation', 'Queue', 'User', 'Start', 'Duration',
                   'End Time', 'Cycle Time', 'Passthrough', 'Partitions',
                   'Project', 'ResID', 'CycleID', 'Remaining', 'T-Minus')]

    for res in reservations:

        passthrough = "Allowed"
        if res['block_passthrough']:
            passthrough = "Blocked"

        start = float(res['start'])
        duration = float(res['duration'])
        now = time.time()

        deltatime = now - start
        remaining = "inactive" if deltatime < 0.0 else client_utils.get_elapsed_time(
            deltatime, duration, True)
        remaining = "00:00:00" if '-' in remaining else remaining
        tminus = "active" if deltatime >= 0.0 else client_utils.get_elapsed_time(
            deltatime, duration, True)

        # do some crazy stuff to make reservations which cycle display the
        # "next" start time
        if res['cycle']:
            cycle = float(res['cycle'])
            periods = math.floor((now - start) / cycle)
            # reservations can't become active until they pass the start time
            # -- so negative periods aren't allowed
            if periods < 0:
                pass
            # if we are still inside the reservation, show when it started
            elif (now - start) % cycle < duration:
                start += periods * cycle
            # if we are in the dead time after the reservation ended, show
            # when the next one starts
            else:
                start += (periods + 1) * cycle
        if res['cycle_id'] == None:
            res['cycle_id'] = '-'

        if res['cycle']:
            cycle = float(res['cycle'])
            if cycle < (60 * 60 * 24):
                cycle = "%02d:%02d" % (cycle / 3600, (cycle / 60) % 60)
            else:
                cycle = "%0.1f days" % (cycle / (60 * 60 * 24))
        else:
            cycle = None
        dmin = (duration / 60) % 60
        dhour = duration / 3600

        time_fmt = "%c"
        starttime = time.strftime(time_fmt, time.localtime(start))
        endtime = time.strftime(time_fmt, time.localtime(start + duration))

        if parser.options.oldts == None:
            #time_fmt += " %z (%Z)"
            starttime = client_utils.sec_to_str(start)
            endtime = client_utils.sec_to_str(start + duration)

        if really_verbose:
            output.append(
                (res['name'], res['queue'], res['users'], starttime,
                 "%02d:%02d" % (dhour, dmin), endtime, cycle, passthrough,
                 mergelist(res['partitions'], cluster), res['project'],
                 res['res_id'], res['cycle_id'], remaining, tminus))
        elif verbose:
            output.append(
                (res['name'], res['queue'], res['users'], starttime,
                 "%02d:%02d" % (dhour, dmin), endtime, cycle, passthrough,
                 mergelist(res['partitions'], cluster), remaining, tminus))
        else:
            output.append((res['name'], res['queue'], res['users'], starttime,
                           "%02d:%02d" % (dhour, dmin), passthrough,
                           mergelist(res['partitions'],
                                     cluster), remaining, tminus))

    output.sort((lambda x, y: cmp(
        time.mktime(
            time.strptime(x[3].split('+')[0].split('-')[0].strip(), time_fmt)),
        time.mktime(
            time.strptime(y[3].split('+')[0].split('-')[0].strip(), time_fmt)))
                 ))
    client_utils.print_tabular(header + output)
示例#26
0
文件: qsub.py 项目: ido/cobalt
def main():
    """
    qsub main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)



    spec     = {} # map of destination option strings and parsed values
    opts     = {} # old map
    opt2spec = {}
    def_spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        ( cb_debug        , () ),
        ( cb_interactive  , () ),
        ( cb_env          , (opts,) ),
        ( cb_nodes        , (False,) ), # return string
        ( cb_gtzero       , (False,) ), # return string
        ( cb_time         , (False, False, False) ), # no delta time, minutes, return string
        ( cb_umask        , () ),
        ( cb_path         , (opts, True) ), # use CWD
        ( cb_dep          , () ),
        ( cb_attrs        , () ),
        ( cb_mode         , () ),
        ( cb_user_list    , (opts,) ),
        ( cb_geometry     , (opts,) )]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    user = client_utils.getuid()

    def_spec['tag']            = 'job'
    def_spec['user']           = user
    def_spec['outputdir']      = client_utils.CWD_TAG
    def_spec['jobid']          = '*'
    def_spec['path']           = client_utils.getpath()
    def_spec['mode']           = False
    def_spec['cwd']            = client_utils.getcwd()
    def_spec['kernel']         = CN_DEFAULT_KERNEL
    def_spec['ion_kernel']     = ION_DEFAULT_KERNEL
    def_spec['queue']          = 'default'
    def_spec['umask']          = 022
    def_spec['run_project']    = False
    def_spec['user_list']      = [user]
    def_spec['procs']          = False
    def_spec['script_preboot'] = True

    parser    = ArgParse(opt_def, callbacks)
    opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)
    reparse  = validate_args(parser, spec)

    if reparse:
        # re-parse with new sys.argv
        # note: the first parse is necessary to make sure that
        #       the env syntax is correct for every --env option provided
        #       If not parsed prior to the union then the union could result
        #       in a valid syntax, but it would not be what the user would want.
        opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)

    client_utils.setumask(spec['umask'])
    validate_options(parser, opt_count)
    update_outputprefix(parser, spec)
    update_paths(spec)
    check_inputfile(parser, spec)

    not_exit_on_interrupt()
    opts['qsub_host'] = socket.gethostname()
    opts = client_utils.component_call(SYSMGR, False, 'validate_job',(opts,))
    impl = client_utils.component_call(SYSMGR, False, 'get_implementation',())
    exit_on_interrupt()

    if impl in ['alps_system']:
        # If we're interactive, remote and go.
        if opts['mode'] == 'interactive':
            if opts.get('ssh_host', None) is not None:
                if opts['qsub_host'] != opts['ssh_host']:
                    #remote execute qsub on the ssh_host
                    client_utils.logger.info('Connecting to %s for interactive qsub...', opts['ssh_host'])
                    sys.exit(qsub_remote_host(opts['ssh_host'])) # return status from qsub-ssh

    filters = client_utils.get_filters()
    client_utils.process_filters(filters, spec)
    # Attrs needs special handling filter won't set otherwise
    if spec.get('attrs', None) is not None:
        opts['attrs'].update(ast.literal_eval(str(spec['attrs'])))
    update_spec(parser, opts, spec, opt2spec)
    run_job(parser, user, spec, opts)
示例#27
0
def main():
    """
    schedctl main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    use_cwd = False
    options = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        [cb_debug, ()],
        [cb_score, ()],
        [cb_path, (options, use_cwd)]
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    # Set required default values: None

    parser.parse_it()  # parse the command line
    args = parser.args
    opt = parser.options

    whoami = client_utils.getuid()

    validate_args(parser, args)

    if opt.stop != None:
        client_utils.component_call(SCHMGR, False, 'disable', (whoami, ))
        client_utils.logger.info("Job Scheduling: DISABLED")
        sys.exit(0)
    elif opt.start != None:
        client_utils.component_call(SCHMGR, False, 'enable', (whoami, ))
        client_utils.logger.info("Job Scheduling: ENABLED")
        sys.exit(0)
    elif opt.stat != None:
        if client_utils.component_call(SCHMGR, False, 'sched_status', ()):
            client_utils.logger.info("Job Scheduling: ENABLED")
        else:
            client_utils.logger.info("Job Scheduling: DISABLED")
        sys.exit(0)
    elif opt.reread != None:
        client_utils.logger.info("Attempting to reread utility functions.")
        client_utils.component_call(QUEMGR, False,
                                    'define_user_utility_functions',
                                    (whoami, ))
        sys.exit(0)
    elif opt.savestate != None:
        response = client_utils.component_call(SCHMGR, False, 'save',
                                               (opt.savestate, ))
        client_utils.logger.info(response)
        sys.exit(0)

    if opt.adjust != None:
        client_utils.set_scores(opt.adjust, args, whoami)

    if opt.dep_frac != None:
        specs = [{'jobid': jobid} for jobid in args]
        response = client_utils.component_call(QUEMGR, False, 'set_jobs',
                                               (specs, {
                                                   "dep_frac": opt.dep_frac
                                               }, whoami))

        if not response:
            client_utils.logger.info("no jobs matched")
        else:
            dumb = [str(r["jobid"]) for r in response]
            client_utils.logger.info(
                "updating inheritance fraction for jobs: %s" % ", ".join(dumb))
示例#28
0
def main():
    """
    qsub main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)


    spec     = {} # map of destination option strings and parsed values
    opts     = {} # old map
    opt2spec = {}
    def_spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        ( cb_debug        , () ),
        ( cb_env          , (opts,) ),
        ( cb_nodes        , (False,) ), # return string
        ( cb_gtzero       , (False,) ), # return string
        ( cb_time         , (False, False, False) ), # no delta time, minutes, return string
        ( cb_umask        , () ),
        ( cb_path         , (opts, True) ), # use CWD
        ( cb_dep          , () ),
        ( cb_attrs        , () ),
        ( cb_mode         , () ),
        ( cb_user_list    , (opts,) ),
        ( cb_geometry     , (opts,) )]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    user = client_utils.getuid()

    def_spec['tag']            = 'job'
    def_spec['user']           = user
    def_spec['outputdir']      = client_utils.CWD_TAG
    def_spec['jobid']          = '*'
    def_spec['path']           = client_utils.getpath()
    def_spec['mode']           = False
    def_spec['cwd']            = client_utils.getcwd()
    def_spec['kernel']         = CN_DEFAULT_KERNEL
    def_spec['ion_kernel']     = ION_DEFAULT_KERNEL
    def_spec['queue']          = 'default'
    def_spec['umask']          = 022
    def_spec['run_project']    = False
    def_spec['user_list']      = [user]
    def_spec['procs']          = False
    def_spec['script_preboot'] = True

    parser    = ArgParse(opt_def, callbacks)
    opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)
    reparse  = validate_args(parser, spec)

    if reparse:
        # re-parse with new sys.argv
        # note: the first parse is necessary to make sure that
        #       the env syntax is correct for every --env option provided
        #       If not parsed prior to the union then the union could result
        #       in a valid syntax, but it would not be what the user would want.
        opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)

    client_utils.setumask(spec['umask'])
    validate_options(parser, opt_count)
    update_outputprefix(parser, spec)
    update_paths(spec)
    check_inputfile(parser, spec)
    opts = client_utils.component_call(SYSMGR, False, 'validate_job',(opts,))
    filters = client_utils.get_filters()
    client_utils.process_filters(filters, spec)
    update_spec(opts, spec, opt2spec)
    get_interactive_command(parser, spec, opts, opt2spec, def_spec)
    jobs = client_utils.component_call(QUEMGR, False, 'add_jobs',([spec],))

    def on_interrupt(sig, func=None):
        '''Handler to cleanup the queued 'dummy' job if the user interrupts
        qsub -I forcibly

        '''
        try:
            spec = [{'tag':'job', 'jobid':jobs[0]['jobid'], 'user':user}]
        except NameError:
            sys.exit(1)
        except:
            raise
        client_utils.logger.info("Deleting job %d", (jobs[0]['jobid']))
        del_jobs = client_utils.component_call(QUEMGR, False, 'del_jobs', (spec, False, user))
        client_utils.logger.info("%s", del_jobs)
        sys.exit(1)

    #reset sigint and sigterm interrupt handlers to deal with interactive failures
    signal.signal(signal.SIGINT, on_interrupt)
    signal.signal(signal.SIGTERM, on_interrupt)

    if parser.options.envs:
        client_utils.logger.debug("Environment Vars: %s", parser.options.envs)
    logjob(jobs[0], spec)

    # If this is an interactive job, wait for it to start, then ssh in
    if parser.options.interactive:
        headnode = ""
        query = [{'tag':'job', 'jobid':jobs[0]['jobid'], 'location':'*', 'state':"*"}]
        while True:
            response = client_utils.component_call(QUEMGR, False, 'get_jobs', (query, ))
            state = response[0]['state']
            location = response[0]['location']
            if state == 'running' and location:
                headnode = location[0]
                client_utils.logger.info("Opening ssh session to %s", headnode)
                break
            elif state != 'running' and state != 'queued' and state != 'starting':
                client_utils.logger.error("ERROR: Something went wrong with job submission, did not expect job to reach %s state.",
                        response[0]['state'])
                break
            else:
                #using Cobalt Utils sleep here
                sleep(2)
        if not headnode:
            client_utils.logger.error("Unable to determine head node for job %d", (jobs[0]['jobid']))
        else:
            try:
                os.putenv("COBALT_NODEFILE", "/var/tmp/cobalt.%s" % (response[0]['jobid']))
                os.putenv("COBALT_JOBID", "%s" % (response[0]['jobid']))
                os.system("/usr/bin/ssh -o \"SendEnv COBALT_NODEFILE COBALT_JOBID\" %s" % (headnode))
            except:
                client_utils.logger.error('Exception occurred during execution ssh session.  Job Terminated.')
        spec = [{'tag':'job', 'jobid':jobs[0]['jobid'], 'user':user}]
        jobs = client_utils.component_call(QUEMGR, False, 'del_jobs', (spec, False, user))
示例#29
0
def main():
    """
    partlist main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    parser.parse_it() # parse the command line

    if not parser.no_args():
        client_utils.logger.error("No arguments required")
        sys.exit(1)
    
    sys_info = client_utils.system_info()
    
    sys_type = sys_info[0]

    if sys_type == 'bgq':
        spec = [{'tag':'partition', 'name':'*', 'queue':'*', 'state':'*',
                 'size':'*', 'functional':'*', 'scheduled':'*', 'children':'*',
                 'backfill_time':"*", 'draining':"*",'node_geometry':"*"}]
    else:
        spec = [{'tag':'partition', 'name':'*', 'queue':'*', 'state':'*',
                 'size':'*', 'functional':'*', 'scheduled':'*', 'children':'*',
                 'backfill_time':"*", 'draining':"*"}]

    parts        = client_utils.component_call(SYSMGR, True, 'get_partitions', (spec,))
    reservations = client_utils.component_call(SCHMGR, False, 'get_reservations', 
                                               ([{'queue':'*','partitions':'*','active':True}],))

    expanded_parts = {}
    for res in reservations:
        for res_part in res['partitions'].split(':'):
            for p in parts:
                if p['name'] == res_part:
                    if expanded_parts.has_key(res['queue']):
                        expanded_parts[res['queue']].update(p['children'])
                    else:
                        expanded_parts[res['queue']] = set( p['children'] )
                    expanded_parts[res['queue']].add(p['name'])    
    
    for res in reservations:
        for p in parts:
            if p['name'] in expanded_parts.get(res['queue'], []):
                p['queue'] += ":%s" % res['queue']

    def my_cmp(left, right):
        val = -cmp(int(left['size']), int(right['size']))
        if val == 0:
            return cmp(left['name'], right['name'])
        else:
            return val

    parts.sort(my_cmp)
    now = time.time()
    for part in parts:
        if part['draining'] and part['state'] == "idle":
            # remove a little extra, to make sure that users can just type the number
            # that is output by partlist to get their job to backfill
            remaining = max(0, part['backfill_time'] - now - 90)
            hours, seconds = divmod(remaining, 3600.0)
            minutes = seconds/60.0
            part['backfill'] = "%d:%0.2d" % (int(hours), int(minutes))
        else:
            part['backfill'] = "-"

    if sys_type == 'bgq':
        header = [['Name', 'Queue', 'State', 'Backfill', 'node_geometry']]
        #build output list, adding
        output = [[part.get(x) for x in [y.lower() for y in header[0]]] for part in parts 
                  if part['functional'] and part['scheduled']]
        #Hack to make the display cleaner.
        header[0][4] = 'Geometry'
        for o in output:
            if o[4] != None:
                o[4] = 'x'.join([str(i) for i in o[4]])
    else:
        header = [['Name', 'Queue', 'State', 'Backfill']]
        #build output list, adding
        output = [[part.get(x) for x in [y.lower() for y in header[0]]] for part in parts 
                  if part['functional'] and part['scheduled']]
    client_utils.printTabular(header + output)
示例#30
0
文件: nodeadm.py 项目: ido/cobalt
def main():
    """
    setres main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    whoami = client_utils.getuid()
    parser.parse_it() # parse the command line

    validate_args(parser)

    opt  = parser.options
    args = parser.args


    #get type of system, Cray systems handled differently

    impl = client_utils.component_call(SYSMGR, False, 'get_implementation', ())

    if impl in ['alps_system']:
        updates = {}
        if opt.list_nstates:
            client_utils.print_node_list()
            return
        if opt.list_details:
            # list details and bail
            # get list from arguments.  Currently assuing a comma separated,
            # hyphen-condensed nodelist
            client_utils.print_node_details(args)
            return
        update_type = 'ERROR'
        if opt.down:
            update_type = 'node down'
            updates['down'] = True
        elif opt.up:
            update_type = 'node up'
            updates['up'] = True
        elif opt.queue:
            update_type = 'queue'
            updates['queues'] = opt.queue
        mod_nodes = client_utils.component_call(SYSMGR, False, 'update_nodes',
                (updates, client_utils.expand_node_args(args), whoami))
        client_utils.logger.info('Update %s applied to nodes %s', update_type,
                compact_num_list(mod_nodes))

    else:
        if opt.down:
            delta = client_utils.component_call(SYSMGR, False, 'nodes_down', (args, whoami))
            client_utils.logger.info("nodes marked down:")
            for d in delta:
                client_utils.logger.info("   %s" % d)
            client_utils.logger.info("")
            client_utils.logger.info("unknown nodes:")
            for a in args:
                if a not in delta:
                    client_utils.logger.info("   %s" % a)

        elif opt.up:
            delta = client_utils.component_call(SYSMGR, False, 'nodes_up', (args, whoami))
            client_utils.logger.info("nodes marked up:")
            for d in delta:
                client_utils.logger.info("   %s" % d)
            client_utils.logger.info('')
            client_utils.logger.info("nodes that weren't in the down list:")
            for a in args:
                if a not in delta:
                    client_utils.logger.info("   %s" %a)

        elif opt.list_nstates:
            header, output = client_utils.cluster_display_node_info()
            client_utils.printTabular(header + output)

        elif opt.queue:
            data = client_utils.component_call(SYSMGR, False, 'set_queue_assignments', (opt.queue, args, whoami))
            client_utils.logger.info(data)
示例#31
0
def main():
    """
    get-bootable-blocks main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [cb_debug, ()],
        [cb_gtzero, (True, )]
    ]  # return int

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    user = client_utils.getuid()

    parser.parse_it()  # parse the command line
    opts = parser.options

    if not parser.no_args():
        client_utils.logger.info('No arguments needed')

    if opts.free and opts.reboot:
        client_utils.logger.error(
            "ERROR: --free may not be specified with --reboot.")
        sys.exit(BAD_OPTION_FAIL)

    block = opts.block
    if block == None:
        try:
            block = os.environ['COBALT_PARTNAME']
        except KeyError:
            pass
        try:
            block = os.environ['COBALT_BLOCKNAME']
        except KeyError:
            pass
        if block == None:
            client_utils.logger.error(
                "ERROR: block not specified as option or in environment.")
            sys.exit(BAD_OPTION_FAIL)

    jobid = opts.jobid
    if jobid == None:
        try:
            jobid = int(os.environ['COBALT_JOBID'])
        except KeyError:
            client_utils.logger.error(
                "ERROR: Cobalt jobid not specified as option or in environment."
            )
            sys.exit(BAD_OPTION_FAIL)

    if opts.reboot or opts.free:
        #Start the free on the block
        #poke cobalt to kill all jobs on the resource as well.
        success = client_utils.component_call(SYSMGR, False,
                                              'initiate_proxy_free',
                                              (block, user, jobid))
        client_utils.logger.info("Block free on %s initiated." % (block, ))
        if not success:
            client_utils.logger.error(
                "Free request for block %s failed authorization." % (block, ))
            sys.exit(AUTH_FAIL)
        while (True):
            #wait for free.  If the user still has jobs running, this won't complete.
            #the proxy free should take care of this, though.
            if client_utils.component_call(SYSMGR, False,
                                           'get_block_bgsched_status',
                                           (block, )) == 'Free':
                client_utils.logger.info("Block %s successfully freed." %
                                         (block, ))
                break

    if not opts.free:
        #This returns important error codes. Pass this back up through main.
        return client_utils.boot_block(block, user, jobid)
示例#32
0
def main():
    """
    qalter main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec     = {} # map of destination option strings and parsed values
    opts     = {} # old map
    opt2spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>           <cb args>
        [ cb_debug               , () ],
        [ cb_gtzero              , (True,) ], # return int
        [ cb_nodes               , (True,) ], # return int
        [ cb_time                , (True, False, False) ], # delta time allowed, return minutes, return string
        [ cb_upd_dep             , () ],
        [ cb_attrs               , () ],
        [ cb_user_list           , (opts,) ],
        [ cb_geometry            , (opts,) ],
        [ cb_mode                , () ]]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    user = client_utils.getuid()

    # Set required default values: None

    parser.parse_it() # parse the command line
    opt_count = client_utils.get_options(spec, opts, opt2spec, parser)

    # if run_project set then set run users to current user
    if parser.options.run_project != None:
        spec['user_list'] = [user]

    jobids  = validate_args(parser, opt_count)
    filters = client_utils.get_filters()

    jobdata = get_jobdata(jobids, parser, user)

    if parser.options.defer != None:
        client_utils.set_scores(0, jobids, user)
        if opt_count == 1:
            return

    response = []
    # for every job go update the spec info
    for job in jobdata:
        # append the parsed spec to the updates list
        new_spec          = spec.copy()
        new_spec['jobid'] = job['jobid']
        if parser.options.walltime is not None:
            update_time(job, new_spec, parser)
        if parser.options.nodes is not None or parser.options.mode is not None:
            if parser.options.nodes is None:
                new_spec['nodes'] = job['nodes']
            if parser.options.mode is None:
                new_spec['mode'] = job['mode']
            update_procs(new_spec, parser)
        if parser.options.geometry is not None:
            client_utils.validate_geometry(opts['geometry'], job['nodes'])

        del job['is_active']
        orig_job = job.copy()
        job.update(new_spec)

        client_utils.process_filters(filters, job)
        response = client_utils.component_call(QUEMGR, False, 'set_jobs', ([orig_job], job, user))
        do_some_logging(job, orig_job, parser)

    if not response:
        client_utils.logger.error("Failed to match any jobs or queues")
    else:
        client_utils.logger.debug(response)
示例#33
0
def main():
    """
    qsub main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec = {}  # map of destination option strings and parsed values
    opts = {}  # old map
    opt2spec = {}
    def_spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        (cb_debug, ()),
        (cb_interactive, ()),
        (cb_env, (opts, )),
        (cb_nodes, (False, )),  # return string
        (cb_gtzero, (False, )),  # return string
        (cb_time, (False, False,
                   False)),  # no delta time, minutes, return string
        (cb_umask, ()),
        (cb_path, (opts, True)),  # use CWD
        (cb_dep, ()),
        (cb_attrs, ()),
        (cb_mode, ()),
        (cb_user_list, (opts, )),
        (cb_geometry, (opts, ))
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    user = client_utils.getuid()

    def_spec['tag'] = 'job'
    def_spec['user'] = user
    def_spec['outputdir'] = client_utils.CWD_TAG
    def_spec['jobid'] = '*'
    def_spec['path'] = client_utils.getpath()
    def_spec['mode'] = False
    def_spec['cwd'] = client_utils.getcwd()
    def_spec['kernel'] = CN_DEFAULT_KERNEL
    def_spec['ion_kernel'] = ION_DEFAULT_KERNEL
    def_spec['queue'] = 'default'
    def_spec['umask'] = 022
    def_spec['run_project'] = False
    def_spec['user_list'] = [user]
    def_spec['procs'] = False
    def_spec['script_preboot'] = True

    parser = ArgParse(opt_def, callbacks)
    opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)
    reparse = validate_args(parser, spec)

    if reparse:
        # re-parse with new sys.argv
        # note: the first parse is necessary to make sure that
        #       the env syntax is correct for every --env option provided
        #       If not parsed prior to the union then the union could result
        #       in a valid syntax, but it would not be what the user would want.
        opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)

    client_utils.setumask(spec['umask'])
    validate_options(parser, opt_count)
    update_outputprefix(parser, spec)
    update_paths(spec)
    check_inputfile(parser, spec)

    not_exit_on_interrupt()
    opts = client_utils.component_call(SYSMGR, False, 'validate_job', (opts, ))
    exit_on_interrupt()

    filters = client_utils.get_filters()
    client_utils.process_filters(filters, spec)
    update_spec(parser, opts, spec, opt2spec)

    run_job(parser, user, spec, opts)
示例#34
0
def main():
    """
    schedctl main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    use_cwd = False
    options = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        [ cb_debug        , () ],
        [ cb_score        , () ],
        [ cb_path         , (options, use_cwd) ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    # Set required default values: None

    parser.parse_it() # parse the command line
    args  = parser.args
    opt   = parser.options

    whoami = client_utils.getuid()

    validate_args(parser, args)

    if opt.stop != None:
        client_utils.component_call(SCHMGR, False, 'disable', (whoami,))
        client_utils.logger.info("Job Scheduling: DISABLED")
        sys.exit(0)
    elif opt.start != None:
        client_utils.component_call(SCHMGR, False, 'enable', (whoami,))
        client_utils.logger.info("Job Scheduling: ENABLED")
        sys.exit(0)
    elif opt.stat != None:
        if client_utils.component_call(SCHMGR, False, 'sched_status', ()):
            client_utils.logger.info("Job Scheduling: ENABLED")
        else:
            client_utils.logger.info("Job Scheduling: DISABLED")
        sys.exit(0)
    elif opt.reread != None:
        client_utils.logger.info("Attempting to reread utility functions.")
        client_utils.component_call(QUEMGR, False, 'define_user_utility_functions', (whoami,))
        sys.exit(0)
    elif opt.savestate != None:
        response = client_utils.component_call(SCHMGR, False, 'save', (opt.savestate,))
        client_utils.logger.info(response)
        sys.exit(0)

    if opt.adjust != None:
        client_utils.set_scores(opt.adjust, args, whoami)

    if opt.dep_frac != None:
        specs = [{'jobid':jobid} for jobid in args]
        response = client_utils.component_call(QUEMGR, False, 'set_jobs', (specs, {"dep_frac": opt.dep_frac}, whoami))

        if not response:
            client_utils.logger.info("no jobs matched")
        else:
            dumb = [str(r["jobid"]) for r in response]
            client_utils.logger.info("updating inheritance fraction for jobs: %s" % ", ".join(dumb))
示例#35
0
def main():
    """
    qsub main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    spec     = {} # map of destination option strings and parsed values
    opts     = {} # old map
    opt2spec = {}
    def_spec = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        ( cb_debug        , () ),
        ( cb_interactive  , () ),
        ( cb_env          , (opts,) ),
        ( cb_nodes        , (False,) ), # return string
        ( cb_gtzero       , (False,) ), # return string
        ( cb_time         , (False, False, False) ), # no delta time, minutes, return string
        ( cb_umask        , () ),
        ( cb_path         , (opts, True) ), # use CWD
        ( cb_dep          , () ),
        ( cb_attrs        , () ),
        ( cb_mode         , () ),
        ( cb_user_list    , (opts,) ),
        ( cb_geometry     , (opts,) )]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    user = client_utils.getuid()

    def_spec['tag']            = 'job'
    def_spec['user']           = user
    def_spec['outputdir']      = client_utils.CWD_TAG
    def_spec['jobid']          = '*'
    def_spec['path']           = client_utils.getpath()
    def_spec['mode']           = False
    def_spec['cwd']            = client_utils.getcwd()
    def_spec['kernel']         = CN_DEFAULT_KERNEL
    def_spec['ion_kernel']     = ION_DEFAULT_KERNEL
    def_spec['queue']          = 'default'
    def_spec['umask']          = 022
    def_spec['run_project']    = False
    def_spec['user_list']      = [user]
    def_spec['procs']          = False
    def_spec['script_preboot'] = True

    parser    = ArgParse(opt_def, callbacks)
    opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)
    reparse  = validate_args(parser, spec)

    if reparse:
        # re-parse with new sys.argv
        # note: the first parse is necessary to make sure that
        #       the env syntax is correct for every --env option provided
        #       If not parsed prior to the union then the union could result
        #       in a valid syntax, but it would not be what the user would want.
        opt_count = parse_options(parser, spec, opts, opt2spec, def_spec)

    client_utils.setumask(spec['umask'])
    validate_options(parser, opt_count)
    update_outputprefix(parser, spec)
    update_paths(spec)
    check_inputfile(parser, spec)

    not_exit_on_interrupt()
    opts = client_utils.component_call(SYSMGR, False, 'validate_job',(opts,))
    exit_on_interrupt()

    filters = client_utils.get_filters()
    client_utils.process_filters(filters, spec)
    update_spec(parser, opts, spec, opt2spec)

    run_job(parser, user, spec, opts)
示例#36
0
def main():
    """
    partadm main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # get the system info
    sysinfo  = client_utils.system_info()
    sys_type =  sysinfo[0]

    print_block = print_block_bgp
    if sys_type == 'bgq':
        print_block = print_block_bgq

    use_cwd = False
    options = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        [ cb_debug        , () ],
        [ cb_path         , (options, use_cwd) ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__', __revision__)
    opt_def =  opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    # Set required default values: None

    parser.parse_it() # parse the command line
    args  = parser.args
    opts  = parser.options

    whoami = client_utils.getuid()

    validate_args(parser)
    parts = []

    if parser.options.recursive:
        parts = recursive(args)
    else:
        parts = args

    parts = handle_mux_options(opts, parts, whoami, sys_type)

    # make sure parts is an a list even if it is an empty list
    if parts is None:
        parts = []

    if opts.pg_list:
        print_pg_info(None)
        sys.exit(0)

    if opts.blockinfo:
        handle_blockinfo_option(parts, sys_type, print_block)

    if opts.clean_block:
        handle_clean_block_option(parts, whoami, sys_type)

    if opts.list_blocks:
        handle_list_blocks_option(parts, sys_type)

    elif opts.boot_start or opts.boot_stop or opts.list_io:
        pass

    else:
        client_utils.logger.info(parts)

    if opts.list_io:
        handle_list_io_option(sys_type)
示例#37
0
def main():
    """
    partadm main function.
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # get the system info
    sysinfo = client_utils.system_info()
    sys_type = sysinfo[0]

    print_block = print_block_bgp
    if sys_type == 'bgq':
        print_block = print_block_bgq

    use_cwd = False
    options = {}

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args (tuple) >
        [cb_debug, ()],
        [cb_path, (options, use_cwd)]
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    # Set required default values: None

    parser.parse_it()  # parse the command line
    args = parser.args
    opts = parser.options

    whoami = client_utils.getuid()

    validate_args(parser)
    parts = []

    if parser.options.recursive:
        parts = recursive(args)
    else:
        parts = args

    parts = handle_mux_options(opts, parts, whoami, sys_type)

    # make sure parts is an a list even if it is an empty list
    if parts is None:
        parts = []

    if opts.pg_list:
        print_pg_info(None)
        sys.exit(0)

    if opts.blockinfo:
        handle_blockinfo_option(parts, sys_type, print_block)

    if opts.clean_block:
        handle_clean_block_option(parts, whoami, sys_type)

    if opts.list_blocks:
        handle_list_blocks_option(parts, sys_type)

    elif opts.boot_start or opts.boot_stop or opts.list_io:
        pass

    else:
        client_utils.logger.info(parts)

    if opts.list_io:
        handle_list_io_option(sys_type)
示例#38
0
def main():
    """
    showres main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ] ]

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    parser.parse_it() # parse the command line

    if not parser.no_args():
        client_utils.logger.error("No arguments needed")
    
    if parser.options.verbose != None and parser.options.really_verbose != None:
        client_utils.logger.error('Only use -l or -x not both')
        sys.exit(1)

    cluster = False
    if 'cluster' in client_utils.component_call(SYSMGR, False, 'get_implementation', ()):
        cluster = True

    reservations = client_utils.component_call(SCHMGR, False, 'get_reservations', 
                                               ([{'name':'*', 'users':'*','start':'*', 'duration':'*', 'partitions':'*', 
                                                  'cycle': '*', 'queue': '*', 'res_id': '*', 'cycle_id': '*','project':'*', 
                                                  'block_passthrough':'*'}], ))

    output = []

    verbose        = False
    really_verbose = False
    header = [('Reservation', 'Queue', 'User', 'Start', 'Duration','Passthrough', 'Partitions', 'Remaining','T-Minus')]

    if parser.options.verbose:
        verbose = True
        header = [('Reservation', 'Queue', 'User', 'Start', 'Duration',
                   'End Time', 'Cycle Time', 'Passthrough', 'Partitions', 'Remaining', 'T-Minus')]
    elif parser.options.really_verbose:
        really_verbose = True
        header = [('Reservation', 'Queue', 'User', 'Start', 'Duration','End Time', 'Cycle Time','Passthrough','Partitions', 
                   'Project', 'ResID', 'CycleID', 'Remaining', 'T-Minus' )]

    for res in reservations:

        passthrough = "Allowed"
        if res['block_passthrough']:
            passthrough = "Blocked"

        start     = float(res['start'])
        duration  = float(res['duration'])
        now       = time.time()

        deltatime = now - start
        remaining = "inactive" if deltatime < 0.0 else client_utils.get_elapsed_time(deltatime, duration, True)
        remaining = "00:00:00" if '-' in remaining else remaining
        tminus    = "active" if deltatime >= 0.0 else client_utils.get_elapsed_time(deltatime, duration, True)

        # do some crazy stuff to make reservations which cycle display the 
        # "next" start time
        if res['cycle']:
            cycle = float(res['cycle'])
            periods = math.floor((now - start)/cycle)
            # reservations can't become active until they pass the start time 
            # -- so negative periods aren't allowed
            if periods < 0:
                pass
            # if we are still inside the reservation, show when it started
            elif (now - start) % cycle < duration:
                start += periods * cycle
            # if we are in the dead time after the reservation ended, show 
            # when the next one starts
            else:
                start += (periods+1) * cycle
        if res['cycle_id'] == None:
            res['cycle_id'] = '-'

        if res['cycle']:
            cycle = float(res['cycle'])
            if cycle < (60 * 60 * 24):
                cycle = "%02d:%02d" % (cycle/3600, (cycle/60)%60)
            else:
                cycle = "%0.1f days" % (cycle / (60 * 60 * 24))
        else:
            cycle = None
        dmin = (duration/60)%60
        dhour = duration/3600

        time_fmt = "%c"
        starttime = time.strftime(time_fmt, time.localtime(start))
        endtime   = time.strftime(time_fmt, time.localtime(start + duration)) 

        if parser.options.oldts == None:
            #time_fmt += " %z (%Z)"
            starttime = client_utils.sec_to_str(start)
            endtime = client_utils.sec_to_str(start + duration)

        if really_verbose:
            output.append((res['name'], res['queue'], res['users'], 
                           starttime,"%02d:%02d" % (dhour, dmin),
                           endtime, cycle, passthrough,
                           mergelist(res['partitions'], cluster), 
                           res['project'], res['res_id'], res['cycle_id'], remaining, tminus))
        elif verbose:
            output.append((res['name'], res['queue'], res['users'], 
                           starttime,"%02d:%02d" % (dhour, dmin),
                           endtime, cycle, passthrough,
                           mergelist(res['partitions'], cluster), 
                           remaining, tminus))
        else:
            output.append((res['name'], res['queue'], res['users'], 
                           starttime,"%02d:%02d" % (dhour, dmin), passthrough,
                           mergelist(res['partitions'], cluster), 
                           remaining, tminus))

    output.sort( (lambda x,y: cmp( time.mktime(time.strptime(x[3].split('+')[0].split('-')[0].strip(), time_fmt)), 
                                   time.mktime(time.strptime(y[3].split('+')[0].split('-')[0].strip(), time_fmt))) ) )
    client_utils.print_tabular(header + output)
示例#39
0
def main():
    """
    partlist main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [cb_debug, ()]
    ]

    # Get the version information
    opt_def = __doc__.replace('__revision__', __revision__)
    opt_def = opt_def.replace('__version__', __version__)

    parser = ArgParse(opt_def, callbacks)

    parser.parse_it()  # parse the command line

    if not parser.no_args():
        client_utils.logger.error("No arguments required")
        sys.exit(1)

    sys_info = client_utils.system_info()

    sys_type = sys_info[0]

    if sys_type == 'bgq':
        spec = [{
            'tag': 'partition',
            'name': '*',
            'queue': '*',
            'state': '*',
            'size': '*',
            'functional': '*',
            'scheduled': '*',
            'children': '*',
            'backfill_time': "*",
            'draining': "*",
            'node_geometry': "*"
        }]
    else:
        spec = [{
            'tag': 'partition',
            'name': '*',
            'queue': '*',
            'state': '*',
            'size': '*',
            'functional': '*',
            'scheduled': '*',
            'children': '*',
            'backfill_time': "*",
            'draining': "*"
        }]

    parts = client_utils.component_call(SYSMGR, True, 'get_partitions',
                                        (spec, ))
    reservations = client_utils.component_call(SCHMGR, False,
                                               'get_reservations',
                                               ([{
                                                   'queue': '*',
                                                   'partitions': '*',
                                                   'active': True
                                               }], ))

    expanded_parts = {}
    for res in reservations:
        for res_part in res['partitions'].split(':'):
            for p in parts:
                if p['name'] == res_part:
                    if expanded_parts.has_key(res['queue']):
                        expanded_parts[res['queue']].update(p['children'])
                    else:
                        expanded_parts[res['queue']] = set(p['children'])
                    expanded_parts[res['queue']].add(p['name'])

    for res in reservations:
        for p in parts:
            if p['name'] in expanded_parts.get(res['queue'], []):
                p['queue'] += ":%s" % res['queue']

    def my_cmp(left, right):
        val = -cmp(int(left['size']), int(right['size']))
        if val == 0:
            return cmp(left['name'], right['name'])
        else:
            return val

    parts.sort(my_cmp)
    now = time.time()
    for part in parts:
        if part['draining'] and part['state'] == "idle":
            # remove a little extra, to make sure that users can just type the number
            # that is output by partlist to get their job to backfill
            remaining = max(0, part['backfill_time'] - now - 90)
            hours, seconds = divmod(remaining, 3600.0)
            minutes = seconds / 60.0
            part['backfill'] = "%d:%0.2d" % (int(hours), int(minutes))
        else:
            part['backfill'] = "-"

    if sys_type == 'bgq':
        header = [['Name', 'Queue', 'State', 'Backfill', 'node_geometry']]
        #build output list, adding
        output = [[part.get(x) for x in [y.lower() for y in header[0]]]
                  for part in parts
                  if part['functional'] and part['scheduled']]
        #Hack to make the display cleaner.
        header[0][4] = 'Geometry'
        for o in output:
            if o[4] != None:
                o[4] = 'x'.join([str(i) for i in o[4]])
    else:
        header = [['Name', 'Queue', 'State', 'Backfill']]
        #build output list, adding
        output = [[part.get(x) for x in [y.lower() for y in header[0]]]
                  for part in parts
                  if part['functional'] and part['scheduled']]
    client_utils.printTabular(header + output)
示例#40
0
文件: boot-block.py 项目: ido/cobalt
def main():
    """
    get-bootable-blocks main
    """
    # setup logging for client. The clients should call this before doing anything else.
    client_utils.setup_logging(logging.INFO)

    # list of callback with its arguments
    callbacks = [
        # <cb function>     <cb args>
        [ cb_debug        , () ],
        [ cb_gtzero       , (True,) ] ] # return int

    # Get the version information
    opt_def =  __doc__.replace('__revision__',__revision__)
    opt_def =  opt_def.replace('__version__',__version__)

    parser = ArgParse(opt_def,callbacks)

    user = client_utils.getuid()

    parser.parse_it() # parse the command line
    opts   = parser.options

    if not parser.no_args():
        client_utils.logger.info('No arguments needed')

    if opts.free and opts.reboot:
        client_utils.logger.error("ERROR: --free may not be specified with --reboot.")
        sys.exit(BAD_OPTION_FAIL)

    block = opts.block
    if block == None:
        try:
            block = os.environ['COBALT_PARTNAME']
        except KeyError:
            pass
        try:
            block = os.environ['COBALT_BLOCKNAME']
        except KeyError:
            pass
        if block == None:
            client_utils.logger.error("ERROR: block not specified as option or in environment.")
            sys.exit(BAD_OPTION_FAIL)

    jobid = opts.jobid
    if jobid == None:
        try:
            jobid = int(os.environ['COBALT_JOBID'])
        except KeyError:
            client_utils.logger.error("ERROR: Cobalt jobid not specified as option or in environment.")
            sys.exit(BAD_OPTION_FAIL)

    if opts.reboot or opts.free:
        #Start the free on the block
        #poke cobalt to kill all jobs on the resource as well.
        success = client_utils.component_call(SYSMGR, False, 'initiate_proxy_free', (block, user, jobid))
        client_utils.logger.info("Block free on %s initiated." % (block,))
        if not success:
            client_utils.logger.error("Free request for block %s failed authorization." % (block, ))
            sys.exit(AUTH_FAIL)
        while (True):
            #wait for free.  If the user still has jobs running, this won't complete.
            #the proxy free should take care of this, though.
            if client_utils.component_call(SYSMGR, False, 'get_block_bgsched_status', (block,)) == 'Free':
                client_utils.logger.info("Block %s successfully freed." % (block,))
                break

    if not opts.free:
        #This returns important error codes. Pass this back up through main.
        return client_utils.boot_block(block, user, jobid)