Exemple #1
0
def core(opts, dbgmsgs=None):
    """Run workspace-control.
    
    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 'wc_args' module and the defaults 'Parameters' implementations to
    fully understand arg intake.  See the 'wc_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:
        raise InvalidInput("The path to the 'main.conf' file is required, see --help.")
        
    ac = get_all_configs(opts.conf)
    
    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(wc_args.ACTION)
    if not given_action:
        raise InvalidInput("The %s argument is required, see help" % wc_args.ACTION.long_syntax)
        
    action = validate_action(given_action)
    
    vm_name = None
    if given_action != "query":
        given_vm_name = p.get_arg_or_none(wc_args.NAME)
        if not given_vm_name:
            raise InvalidInput("The %s argument is required, see help" % wc_args.NAME.long_syntax)
    
	vm_name = validate_name(given_vm_name)
    
    # -------------------------------------------------------------------------
    # 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(vm_name, action, p, c)
    except Exception,e:
        c.log.exception(e)
        raise
def mockconfigs(basename="main.conf"):
    return get_all_configs(get_mock_mainconf(basename=basename))
Exemple #3
0
        logfiledir = os.path.join(vardir, logfiledir)

    return logfiledir


if len(sys.argv) != 2:
    sys.stderr.write(
        "This program requires 1 argument, the absolute path to the main.conf file"
    )
    sys.exit(1)

confpath = sys.argv[1]

# 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)
p = p_cls(allconfs, None)

logfiledir = get_logfiledir(p)
if not logfiledir:
    sys.exit(1)

# find the newest file in the directory:

sys.stderr.write("Log file dir:    %s\n" % logfiledir)

sortme = []
for root, dirs, files in os.walk(logfiledir):
    for name in files:
        path = os.path.join(logfiledir, name)
def realconfigs():
    # only a best effort guess, tests assume it is under $basedir/etc
    return get_all_configs(get_mainconf_guess())
Exemple #5
0
def core(opts, dbgmsgs=None):
    """Run workspace-control.
    
    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 'wc_args' module and the defaults 'Parameters' implementations to
    fully understand arg intake.  See the 'wc_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:
        raise InvalidInput(
            "The path to the 'main.conf' file is required, see --help.")

    ac = get_all_configs(opts.conf)

    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(wc_args.ACTION)
    if not given_action:
        raise InvalidInput("The %s argument is required, see help" %
                           wc_args.ACTION.long_syntax)

    action = validate_action(given_action)

    given_vm_name = p.get_arg_or_none(wc_args.NAME)
    if not given_vm_name:
        raise InvalidInput("The %s argument is required, see help" %
                           wc_args.NAME.long_syntax)

    vm_name = validate_name(given_vm_name)

    # -------------------------------------------------------------------------
    # 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(vm_name, action, p, c)
    except Exception, e:
        c.log.exception(e)
        raise
Exemple #6
0
        if not os.path.isabs(vardir):
            basedir = guess_basedir()
            vardir = os.path.join(basedir, vardir)
            
        logfiledir = os.path.join(vardir, logfiledir)
        
    return logfiledir
    
if len(sys.argv) != 2:
    sys.stderr.write("This program requires 1 argument, the absolute path to the main.conf file")
    sys.exit(1)

confpath=sys.argv[1]

# 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)
p = p_cls(allconfs, None)

logfiledir = get_logfiledir(p)
if not logfiledir:
    sys.exit(1)

# find the newest file in the directory:

sys.stderr.write("Log file dir:    %s\n" % logfiledir)

sortme = []
for root, dirs, files in os.walk(logfiledir):
    for name in files:
        path = os.path.join(logfiledir, name)
Exemple #7
0
def realconfigs():
    # only a best effort guess, tests assume it is under $basedir/etc
    return get_all_configs(get_mainconf_guess())
Exemple #8
0
def mockconfigs(basename="main.conf"):
    return get_all_configs(get_mock_mainconf(basename=basename))