Ejemplo n.º 1
0
def validate_action(action):
    action = string.strip(action)
    action = string.lower(action)
    if not action:
        raise InvalidInput("action is missing/empty")

    if action not in ACTIONS().all_actions():
        em_optparse.print_help()
        raise InvalidInput("Unknown action: '%s'" % action)

    return action
Ejemplo n.º 2
0
def core(opts, dbgmsgs=None):
    """Run epumgmt.
    
    From here 'down' there is no concept of a commandline program, only
    'args' which could be coming from any kind of protocol based request.
    
    To make such a thing, construct an opts object with the expected
    member names and values and pass it in to this method.
    
    See the 'em_args' module and the defaults 'Parameters' implementations to
    fully understand arg intake.  See the 'em_cmdline' module to see how args
    are taken in and how the result of the program (no exception or exception)
    is translated into a return code.
    """

    # -------------------------------------------------------------------------
    # SETUP Parameters
    # -------------------------------------------------------------------------

    if not opts:
        raise InvalidInput("No arguments")

    # in the default deployment, this is added by the .sh script wrapper
    if not opts.conf:
        config = get_default_config()
    else:
        config = opts.conf

    ac = get_all_configs(config)

    p_cls = get_class_by_keyword("Parameters", allconfigs=ac)
    p = p_cls(ac, opts)

    # -------------------------------------------------------------------------
    # REQUIRED arguments
    # -------------------------------------------------------------------------

    # --conf is also required; already checked for above

    given_action = p.get_arg_or_none(em_args.ACTION)
    if not given_action:
        em_optparse.print_help()
        msg = "You must specify an action as one of your arguments"
        raise InvalidInput(msg)

    action = validate_action(given_action)

    # -------------------------------------------------------------------------
    # Common
    # -------------------------------------------------------------------------

    c_cls = get_class_by_keyword("Common", allconfigs=ac)
    c = c_cls(p)

    # now there is a logger finally:
    if dbgmsgs:
        c.log.debug(dbgmsgs)

    try:
        _core(action, p, c)
    except:
        # Important for invocation logs to also record any problem
        c.log.exception("")
        raise