Ejemplo n.º 1
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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 4
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'])
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
Archivo: setres.py Proyecto: 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)
Ejemplo n.º 9
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))
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
Archivo: cqadm.py Proyecto: 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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
Archivo: qsub.py Proyecto: 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)
Ejemplo n.º 15
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))
Ejemplo n.º 16
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))
Ejemplo n.º 17
0
def modify_reservation(parser):
    """
    this will handle reservation modifications
    """
    query = [{
        'name': parser.options.name,
        'start': '*',
        'cycle': '*',
        'duration': '*'
    }]
    res_list = client_utils.component_call(SCHMGR, False, 'get_reservations',
                                           (query, ))
    if not res_list:
        client_utils.logger.error("cannot find reservation named '%s'" %
                                  parser.options.name)
        sys.exit(1)

    updates = {}  # updates to reservation
    if parser.options.defer != None:
        res = res_list[0]

        if not res['cycle']:
            client_utils.logger.error(
                "Cannot use -D on a non-cyclic reservation")
            sys.exit(1)

        start = res['start']
        duration = res['duration']
        cycle = float(res['cycle'])
        now = time.time()
        periods = math.floor((now - start) / cycle)

        if (periods < 0):
            start += cycle
        elif (now - start) % cycle < duration:
            start += (periods + 1) * cycle
        else:
            start += (periods + 2) * cycle

        newstart = time.strftime("%c", time.localtime(start))
        client_utils.logger.info(
            "Setting new start time for for reservation '%s': %s" %
            (res['name'], newstart))

        updates['start'] = start

        #add a field to updates to indicate we're deferring:
        updates['defer'] = True
    else:
        if parser.options.start != None:
            updates['start'] = parser.options.start
        if parser.options.duration != None:
            updates['duration'] = parser.options.duration

    if parser.options.users != None:
        updates[
            'users'] = None if parser.options.users == "*" else parser.options.users
    if parser.options.project != None:
        updates['project'] = parser.options.project
    if parser.options.cycle != None:
        updates['cycle'] = parser.options.cycle
    if not parser.no_args():
        updates['partitions'] = ":".join(parser.args)
    if parser.options.block_passthrough != None:
        updates['block_passthrough'] = parser.options.block_passthrough

    comp_args = ([{
        'name': parser.options.name
    }], updates, client_utils.getuid())
    client_utils.component_call(SCHMGR, False, 'set_reservations', comp_args)
    reservations = client_utils.component_call(SCHMGR, False,
                                               'get_reservations',
                                               ([{
                                                   'name': parser.options.name,
                                                   'users': '*',
                                                   'start': '*',
                                                   'duration': '*',
                                                   'partitions': '*',
                                                   'cycle': '*',
                                                   'res_id': '*',
                                                   'project': '*',
                                                   'block_passthrough': '*'
                                               }], ))
    client_utils.logger.info(reservations)
    client_utils.logger.info(
        client_utils.component_call(SCHMGR, False, 'check_reservations', ()))
Ejemplo n.º 18
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)
Ejemplo n.º 19
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)
Ejemplo n.º 20
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))
Ejemplo n.º 21
0
Archivo: setres.py Proyecto: ido/cobalt
def modify_reservation(parser):
    """
    this will handle reservation modifications
    """
    query = [{'name':parser.options.name, 'start':'*', 'cycle':'*', 'duration':'*'}]
    res_list = client_utils.component_call(SCHMGR, False, 'get_reservations', (query,))
    if not res_list:
        client_utils.logger.error("cannot find reservation named '%s'" % parser.options.name)
        sys.exit(1)

    updates = {} # updates to reservation
    if parser.options.defer != None:
        res = res_list[0]

        if not res['cycle']:
            client_utils.logger.error("Cannot use -D on a non-cyclic reservation")
            sys.exit(1)

        start    = res['start']
        duration = res['duration']
        cycle    = float(res['cycle'])
        now      = time.time()
        periods  = math.floor((now - start)/cycle)

        if(periods < 0):
            start += cycle
        elif(now - start) % cycle < duration:
            start += (periods + 1) * cycle
        else:
            start += (periods + 2) * cycle

        newstart = time.strftime("%c", time.localtime(start))
        client_utils.logger.info("Setting new start time for for reservation '%s': %s" % (res['name'], newstart))

        updates['start'] = start

        #add a field to updates to indicate we're deferring:
        updates['defer'] = True
    else:
        if parser.options.start != None:
            updates['start'] = parser.options.start
        if parser.options.duration != None:
            updates['duration'] = parser.options.duration

    if parser.options.users != None:
        updates['users'] = None if parser.options.users == "*" else parser.options.users
    if parser.options.project != None:
        updates['project'] = parser.options.project
    if parser.options.cycle != None:
        updates['cycle'] = parser.options.cycle
    if not parser.no_args():
        updates['partitions'] = ":".join(parser.args)
    if parser.options.block_passthrough != None:
        updates['block_passthrough'] = parser.options.block_passthrough

    comp_args = ([{'name':parser.options.name}], updates, client_utils.getuid())
    client_utils.component_call(SCHMGR, False, 'set_reservations', comp_args)
    reservations = client_utils.component_call(SCHMGR, False, 'get_reservations', 
                                               ([{'name':parser.options.name, 'users':'*','start':'*', 'duration':'*', 'partitions':'*', 
                                                  'cycle': '*', 'res_id': '*', 'project':'*', 'block_passthrough':'*'}], ))
    client_utils.logger.info(reservations)
    client_utils.logger.info(client_utils.component_call(SCHMGR, False, 'check_reservations', ()))
Ejemplo n.º 22
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)
Ejemplo n.º 23
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)
Ejemplo n.º 24
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)
Ejemplo n.º 25
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)
Ejemplo n.º 26
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))
Ejemplo n.º 27
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


    #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)
Ejemplo n.º 28
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))