Beispiel #1
0
    def __init__(self, opts):
        if opts.conf:
            config = opts.conf
        else:
            config = None

        ac = get_all_configs(config)

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

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

        event_gather_cls = self.c.get_class_by_keyword("EventGather")
        event_gather = event_gather_cls(self.p, self.c)

        persistence = em_core_persistence.Persistence(self.p, self.c)

        runlogs_cls = self.c.get_class_by_keyword("Runlogs")
        runlogs = runlogs_cls(self.p, self.c)

        remote_svc_adapter_cls = self.c.get_class_by_keyword("RemoteSvcAdapter")
        remote_svc_adapter = remote_svc_adapter_cls(self.p, self.c)

        event_gather.validate()
        persistence.validate()
        runlogs.validate()
        remote_svc_adapter.validate()

        self.m = Modules(event_gather, persistence, runlogs, remote_svc_adapter)
Beispiel #2
0
def get_iaas_object(opts=None):

    if opts == None:
        opts = EPUMgmtOpts(name="XXXX", conf_file=epumgmt.api.get_default_config())

    ac = get_allconfigs()
    p_cls = get_class_by_keyword("Parameters", allconfigs=ac)
    p = p_cls(ac, opts)
    c_cls = get_class_by_keyword("Common", allconfigs=ac)
    c = c_cls(p)
    iaas_cls = c.get_class_by_keyword("IaaS")
    iaas = iaas_cls(p, c)
    return iaas
Beispiel #3
0
def get_common(opts=None, p=None, ac=None):
    if p is None and opts is None:
        raise Exception("either opts of p must be specified")
    if ac is None:
        ac = get_default_ac()
    if p is None:
        (p, ac) = get_parameters(opts, ac)
    c_cls = get_class_by_keyword("Common", allconfigs=ac)
    c = c_cls(p)
    return (c, p, ac)
Beispiel #4
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
Beispiel #5
0
def get_parameters(confpath):
    # mini implementation of the dependency injection used in the real program:
    allconfs = get_all_configs(confpath)
    p_cls = get_class_by_keyword("Parameters", allconfigs=allconfs)
    return p_cls(allconfs, None)
Beispiel #6
0
def get_parameters(opts, ac=None):
    if ac is None:
        ac = get_default_ac()
    p_cls = get_class_by_keyword("Parameters", allconfigs=ac)
    p = p_cls(ac, opts)
    return (p, ac)