コード例 #1
0
ファイル: cmd_shell.py プロジェクト: waterbear-cloud/paco
def shell_command(paco_ctx,
                  netenv_name,
                  env_name,
                  region,
                  instance_ref,
                  home='.'):
    """Open a shell to an instance"""
    paco_ctx.command = 'shell'
    init_paco_home_option(paco_ctx, home)
    if not paco_ctx.home:
        print(
            'Paco configuration directory needs to be specified with either --home or PACO_HOME environment variable.'
        )
        sys.exit()

    paco_ctx.load_project()
    config_arg = {
        'netenv_name': netenv_name,
        'env_id': env_id,
        'region': region,
    }
    paco_ctx.get_controller('NetEnv', config_arg)
    full_ref = 'paco.ref netenv.%s.%s.%s.%s' % (netenv_name, env_name, region,
                                                instance_ref)
    paco_ctx.get_ref(full_ref)
コード例 #2
0
def describe_command(paco_ctx, home='.', output='html', display='chrome'):
    """Describe a Paco project"""
    paco_ctx.command = 'describe'
    paco_ctx.skip_account_ctx = True
    layout_options = ('html', 'spa', 'json')
    if output not in layout_options:
        raise InvalidOption(
            'Output option (-o, --output) can only be html, json or spa')
    init_paco_home_option(paco_ctx, home)
    paco_ctx.load_project(validate_local_paths=False)
    project = paco_ctx.project

    # Output HTML
    describe_path = pathlib.Path(paco_ctx.describe_path)
    describe_path.mkdir(parents=True, exist_ok=True)
    if output == 'html':
        static_path, html_files, envs_html = display_project_as_html(
            project, output)
        shutil.copytree(static_path, describe_path, dirs_exist_ok=True)
        for fname, html in html_files.items():
            with open(str(describe_path / fname), 'w') as fh:
                fh.write(html)
        for name, html in envs_html.items():
            with open(str(describe_path / name), 'w') as fh:
                fh.write(html)

    # Output JSON
    if output in ('json', 'spa'):
        json_docs = display_project_as_json(project)
        for key, value in json_docs.items():
            with open(str(describe_path / f'{key}.json'), 'w') as fh:
                fh.write(json.dumps(value))
コード例 #3
0
def init_netenv(ctx, home='.'):
    """
    Initializes a netenv resource for a Paco project.
    """
    paco_ctx = ctx.obj
    paco_ctx.command = 'init netenv'
    init_paco_home_option(paco_ctx, home)
    paco_ctx.load_project()
    ctl_project = paco_ctx.get_controller('project')
    # ToDo: FixMe! pass proper NetEnv info to init_command ...
    ctl_project.init_command()
コード例 #4
0
def init_accounts(ctx, home='.'):
    """
    Initializes the accounts for a Paco project.
    """
    paco_ctx = ctx.obj
    paco_ctx.command = 'init accounts'
    init_paco_home_option(paco_ctx, home)
    paco.commands.helpers.PACO_HOME = paco_ctx.home
    paco_ctx.load_project(master_only=True)
    ctl_project = paco_ctx.get_controller('project')
    ctl_project.init_accounts()
コード例 #5
0
def init_credentials(ctx, home='.'):
    """
    Initializes the .credentials file for a Paco project.
    """
    paco_ctx = ctx.obj
    paco_ctx.command = 'init credentials'
    init_paco_home_option(paco_ctx, home)
    if paco_ctx.home == None:
        print("PACO_HOME or --home must be set.")
        sys.exit()
    paco.commands.helpers.PACO_HOME = paco_ctx.home
    paco_ctx.load_project(project_only=True)
    ctl_project = paco_ctx.get_controller('project')
    ctl_project.init_credentials()
コード例 #6
0
ファイル: cmd_describe.py プロジェクト: knowledgewarrior/paco
def describe_command(ctx, home='.'):
    """Describe a Paco project"""
    ctx.command = 'describe'
    init_paco_home_option(ctx, home)
    if not ctx.home:
        print('Paco configuration directory needs to be specified with either --home or PACO_HOME environment variable.')
        sys.exit()
    project = load_cached_project(ctx.home)

    print('Project: {} - {}'.format(project.name, project.title))
    print('Location: {}'.format(ctx.home))
    print()
    print('Accounts')
    for ne in project['accounts'].values():
        print(' - {} - {}'.format(ne.name, ne.title))
    print()
    print('Network Environments')
    for ne in project['netenv'].values():
        print(' - {} - {}'.format(ne.name, ne.title))
    print()