Beispiel #1
0
def setup_lp_cli():
    """
    Perform setup of LinchpinContext, lpc.load_config, and LinchPinAPI
    """

    global lpctx
    global lpc

    global target
    global pinfile

    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))

    setup_load_config()

    pinfile = 'PinFile'
    mock_path = '{0}/{1}/{2}'.format(lib_path, 'mockdata', provider)

    lpctx = LinchpinCliContext()
    lpctx.load_config(lpconfig=config_path)
    lpctx.load_global_evars()
    lpctx.setup_logging()
    lpctx.workspace = os.path.realpath(mock_path)
    lpctx.pinfile = pinfile
    lpctx.pf_data = None
    lpctx.no_monitor = True
    lpctx.set_evar("no_monitor", True)
    lpctx.set_cfg("progress_bar", "no_progress", str(True))

    lpc = LinchpinCli(lpctx)
    lpc.disable_pbar = True
Beispiel #2
0
def runcli(ctx, config, pinfile, workspace, verbose, version, creds_path):
    """linchpin: hybrid cloud orchestration"""

    ctx.load_config(lpconfig=config)
    # workspace arg in load_config used to extend linchpin.conf
    ctx.load_global_evars()
    ctx.setup_logging()

    ctx.verbose = verbose

    if pinfile:
        ctx.log_info('pinfile name changed to {0}'.format(pinfile))
        ctx.pinfile = pinfile

    if version:
        ctx.log_state('linchpin version {0}'.format(ctx.version))
        sys.exit(0)

    if creds_path is not None:
        ctx.set_evar('creds_path',
                     os.path.realpath(os.path.expanduser(creds_path)))

    if workspace is not None:
        ctx.workspace = os.path.realpath(os.path.expanduser(workspace))
        ctx.log_debug("ctx.workspace: {0}".format(ctx.workspace))

    # global LinchpinCli placeholder
    global lpcli
    lpcli = LinchpinCli(ctx)
Beispiel #3
0
def setup_lp_fetch_env():
    global lpc
    global lpcli

    global target
    global pinfile
    global mockpath

    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))

    setup_load_config()

    pinfile = 'PinFile'
    mock_path = '{0}/{1}/{2}'.format(lib_path, 'mockdata', provider)

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()
    lpc.setup_logging()
    lpc.workspace = '/tmp/workspace/'
    mockpath = os.path.realpath(mock_path)

    if not os.path.exists(lpc.workspace):
        os.mkdir(lpc.workspace)

    lpcli = LinchpinCli(lpc)
Beispiel #4
0
def setup_lp_cli():
    """
    Perform setup of LinchpinContext, lpc.load_config, and LinchPinAPI
    """

    global lpctx
    global lpc

    global target
    global pinfile

    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))

    setup_load_config()

    pinfile = 'PinFile'
    mock_path = '{0}/{1}/{2}'.format(lib_path, 'mockdata', provider)

    lpctx = LinchpinCliContext()
    lpctx.load_config(lpconfig=config_path)
    lpctx.load_global_evars()
    lpctx.setup_logging()
    lpctx.workspace = os.path.realpath(mock_path)

    lpc = LinchpinCli(lpctx)
Beispiel #5
0
def test_cli_create():

    lpctx = LinchpinCliContext()
    lpctx.load_config()
    lpctx.load_global_evars()
    lpc = LinchpinCli(lpctx)

    assert_equal(isinstance(lpc, LinchpinCli), True)
Beispiel #6
0
def runcli(ctx, config, pinfile, template_data, outfile, workspace, verbose,
           version, creds_path, ask_vault_pass, no_monitor):
    """linchpin: hybrid cloud orchestration"""

    ctx.load_config(lpconfig=config)
    # workspace arg in load_config used to extend linchpin.conf
    ctx.load_global_evars()
    ctx.setup_logging()

    ctx.verbosity = verbose

    # if the pinfile is a template, data will be passed here
    ctx.pf_data = template_data
    ctx.outfile = None
    if outfile:
        ctx.outfile = outfile
        ctx.set_cfg('tmp', 'outfile', outfile)

    ctx.pinfile = None
    if pinfile:
        ctx.pinfile = pinfile

    if version:
        ctx.log_state('linchpin version {0}'.format(ctx.version))
        sys.exit(0)

    if no_monitor:
        ctx.no_monitor = True
        ctx.set_evar('no_monitor', True)
    else:
        ctx.no_monitor = ctx.get_evar('no_monitor')

    if creds_path is not None:
        ctx.set_evar('creds_path',
                     os.path.realpath(os.path.expanduser(creds_path)))

    if workspace is not None:
        ctx.workspace = os.path.realpath(os.path.expanduser(workspace))
        ctx.log_debug("ctx.workspace: {0}".format(ctx.workspace))

    ctx.ask_vault_pass = ask_vault_pass

    # global LinchpinCli placeholder
    global lpcli
    lpcli = LinchpinCli(ctx)
Beispiel #7
0
def setup_lp_fetch_env():
    global lpc
    global lpcli

    global target
    global pinfile
    global mockpath

    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))

    setup_load_config()

    lpc = LinchpinCliContext()
    lpc.load_config(lpconfig=config_path)
    lpc.load_global_evars()
    lpc.setup_logging()

    lpc.workspace = tempfile.mkdtemp(prefix='fetch_')
    print(('workspace: {0}'.format(lpc.workspace)))

    lpcli = LinchpinCli(lpc)
Beispiel #8
0
def _get_hosts(ctx, args, incomplete):
    lpctx = LinchpinCliContext()
    lpctx.load_config(lpconfig=None)
    lpctx.load_global_evars()
    lpcli = LinchpinCli(lpctx)
    return [k for k in lpcli.ctx.inventory.hosts.keys() if incomplete in k]