예제 #1
0
def print_adapter_help(ctx, adapter_name):
    """
    Prints detailed information about the specified freckelize adapter.
    """

    config = ctx.obj["config"]

    repos = tasks.get_local_repos(config.trusted_repos, "adapters",
                                  DEFAULT_LOCAL_REPO_PATH_BASE, DEFAULT_REPOS,
                                  DEFAULT_ABBREVIATIONS)

    adapters = get_all_adapters_in_repos(repos)

    adapter_files = find_adapter_files(ADAPTER_MARKER_EXTENSION,
                                       adapters,
                                       config=config)

    adapter_file = adapter_files.get(adapter_name, False)
    if not adapter_file:
        click.echo(
            "\nNo adapter with the name '{}' found.\n".format(adapter_name))
        sys.exit(0)

    output_adapter_help(adapter_name, adapter_file, details=True, help=True)

    click.echo("")
예제 #2
0
def list_adapters_cli(ctx, filter, details):
    """
    Lists all freckelize adapters that are available in the requested execution context.
    """

    config = ctx.obj["config"]

    repos = tasks.get_local_repos(config.trusted_repos, "adapters",
                                  DEFAULT_LOCAL_REPO_PATH_BASE, DEFAULT_REPOS,
                                  DEFAULT_ABBREVIATIONS)

    click.echo("")
    click.secho("Available adapters", bold=True)
    click.secho("==================", bold=True)

    adapters = get_all_adapters_in_repos(repos)

    adapter_files = find_adapter_files(ADAPTER_MARKER_EXTENSION,
                                       adapters,
                                       config=config)

    for adapter_name, adapter_file in sorted(adapter_files.items()):

        # reading metadata twice, not ideal
        metadata = get_adapter_metadata(adapter_file)
        short_help = metadata.get("doc", {}).get("short_help", "n/a")

        if filter:
            if filter not in adapter_name and filter not in short_help:
                continue

        output_adapter_help(adapter_name, adapter_file, details=details)

    click.echo("")
예제 #3
0
def get_all_adapters_in_repos(repos):
    result = []
    repos = nsbl_tasks.get_local_repos(repos, "adapters", DEFAULT_LOCAL_REPO_PATH_BASE, DEFAULT_REPOS, DEFAULT_ABBREVIATIONS)
    for repo in repos:
        adapters = get_adapters_from_repo(repo)
        result.extend(adapters)

    return result
예제 #4
0
def list_aliases_cli(ctx, filter, details):
    """
    Lists aliases that are defined in the 'task-aliases.yml' files in the requested execution context.
    """

    config = ctx.obj["config"]
    role_repos = tasks.get_local_repos(config.trusted_repos, "roles",
                                       DEFAULT_LOCAL_REPO_PATH_BASE,
                                       DEFAULT_REPOS, DEFAULT_ABBREVIATIONS)

    task_descs = calculate_task_descs(None,
                                      role_repos,
                                      add_upper_case_versions=False)

    desc = {}
    aliases = {}

    for d in task_descs:

        meta = d.get(TASKS_META_KEY, {})

        name = meta.get(TASK_META_NAME_KEY, "")
        task_name = meta.get(TASK_NAME_KEY, name)
        task_type = meta.get(TASK_TYPE_KEY, None)

        if not task_type:
            if "." in task_name:
                task_type = ROLE_NAME_KEY
            else:
                task_type = TASK_TASK_TYPE

        if filter and not filter in name:
            continue

        desc[name] = {"task_type": task_type, "task_name": task_name}
        if details:
            # vars = d.get(VARS_KEY)
            # click.echo("\nalias '{}' (type: {}):".format(name, task_type))
            yaml_string = yaml.safe_dump(d,
                                         default_flow_style=False,
                                         allow_unicode=True,
                                         encoding="utf-8")
            desc[name]["details"] = yaml_string
            #click.echo("   " + yaml_string

    click.echo("")
    click.secho("task overrides", bold=True)
    click.secho("==============", bold=True)
    click.echo("")
    for name, d in sorted(desc.items()):
        click.secho("{}".format(name), bold=True, nl=False)
        click.secho(": {} {}".format(d["task_type"], d["task_name"]),
                    bold=False)
        if details:
            click.echo("")
            click.echo("   " + d["details"].replace("\n", "\n    "))
    click.echo("")
예제 #5
0
def create_and_run_nsbl_runner(task_config, task_metadata={}, output_format="default", ask_become_pass="******",
                               pre_run_callback=None, no_run=False, additional_roles=[], config=None, run_box_basics=False, additional_repo_paths=[], hosts_list=["localhost"]):

    if run_box_basics:
        result = execute_run_box_basics(output_format)

        if result["return_code"] > 0:
            return result

    if not config:
        config = DEFAULT_FRECKLES_CONFIG

    if additional_repo_paths:
        if config.use_freckle_as_repo:
            config.add_repos(additional_repo_paths)

    config_trusted_repos = config.trusted_repos
    local_role_repos = nsbl_tasks.get_local_repos(config_trusted_repos, "roles", DEFAULT_LOCAL_REPO_PATH_BASE, DEFAULT_REPOS, DEFAULT_ABBREVIATIONS)

    role_repos = defaults.calculate_role_repos(local_role_repos, use_default_roles=False)

    task_descs = config.task_descs

    nsbl_obj = nsbl.Nsbl.create(task_config, role_repos, task_descs, wrap_into_hosts=hosts_list, pre_chain=[],
                                additional_roles=additional_roles)

    runner = nsbl.NsblRunner(nsbl_obj)
    run_target = os.path.expanduser(DEFAULT_RUN_LOCATION)
    ansible_verbose = ""
    stdout_callback = "nsbl_internal"
    ignore_task_strings = []
    display_sub_tasks = True
    display_skipped_tasks = False

    if output_format == "verbose":
        stdout_callback = "default"
        ansible_verbose = "-vvvv"
    elif output_format == "ansible":
        stdout_callback = "default"
    elif output_format == "skippy":
        stdout_callback = "skippy"
    elif output_format == "default_full":
        stdout_callback = "nsbl_internal"
        display_skipped_tasks = True
    elif output_format == "default":
        ignore_task_strings = DEFAULT_IGNORE_STRINGS
        stdout_callback = "nsbl_internal"
    else:
        raise Exception("Invalid output format: {}".format(output_format))

    force = True
    return runner.run(run_target, force=force, ansible_verbose=ansible_verbose, ask_become_pass=ask_become_pass,
                      extra_plugins=EXTRA_FRECKLES_PLUGINS, callback=stdout_callback, add_timestamp_to_env=True,
                      add_symlink_to_env=DEFAULT_RUN_SYMLINK_LOCATION, no_run=no_run,
                      display_sub_tasks=display_sub_tasks, display_skipped_tasks=display_skipped_tasks,
                      display_ignore_tasks=ignore_task_strings, pre_run_callback=pre_run_callback)
예제 #6
0
def find_supported_blueprints(config=None):

    if not config:
        config = DEFAULT_FRECKLES_CONFIG

    trusted_repos = config.trusted_repos
    repos = nsbl_tasks.get_local_repos(trusted_repos, "blueprints", DEFAULT_LOCAL_REPO_PATH_BASE, DEFAULT_REPOS, DEFAULT_ABBREVIATIONS)

    result = {}
    for r in repos:
        p = get_blueprints_from_repo(r)
        result.update(p)
    return result
예제 #7
0
def get_available_blueprints(config=None):
    """Find all available blueprints."""

    if not config:
        config = DEFAULT_FRECKLES_CONFIG

    repos = nsbl_tasks.get_local_repos(config.trusted_repos, "blueprints", DEFAULT_LOCAL_REPO_PATH_BASE, DEFAULT_REPOS, DEFAULT_ABBREVIATIONS)

    result = {}
    for repo in repos:

        blueprints = get_blueprints_from_repo(repo)
        for name, path in blueprints.items():
            result[name] = path

    return result
예제 #8
0
def find_supported_profiles(config=None, additional_context_repos=[]):

    if not config:
        config = DEFAULT_FRECKLES_CONFIG

    trusted_repos = copy.copy(config.trusted_repos)
    if additional_context_repos:
        trusted_repos.extend(additional_context_repos)

    repos = nsbl_tasks.get_local_repos(trusted_repos, "adapters", DEFAULT_LOCAL_REPO_PATH_BASE, DEFAULT_REPOS, DEFAULT_ABBREVIATIONS)

    result = {}
    for r in repos:
        p = get_adapters_from_repo(r)
        result.update(p)

    return result
예제 #9
0
def list_blueprints_cli(ctx, filter, details):
    """
    Lists all blueprints that are available in the requested execution context.
    """

    config = ctx.obj["config"]

    repos = tasks.get_local_repos(config.trusted_repos, "blueprints",
                                  DEFAULT_LOCAL_REPO_PATH_BASE, DEFAULT_REPOS,
                                  DEFAULT_ABBREVIATIONS)

    click.echo("")
    click.secho("Available blueprints", bold=True)
    click.secho("====================", bold=True)

    blueprints = {}
    for repo in repos:
        blueprints_temp = get_blueprints_from_repo(repo)
        for name, path in blueprints_temp.items():
            if filter and filter not in name:
                continue

            blueprints[name] = path

    for name, path in sorted(blueprints.items()):

        metadata = get_blueprint_metadata(
            os.path.join(path, "{}.blueprint.freckle".format(name)))

        short_help = metadata.get("doc", {}).get("short_help", "n/a")
        long_help = metadata.get("doc", {}).get("help", "n/a")

        click.secho("\n{}\n{}\n".format(name, "-" * len(name)), bold=True)
        click.secho("  desc", nl=False, bold=True)
        click.echo(": {}".format(short_help))
        click.secho("  path", nl=False, bold=True)
        click.echo(": {}".format(path))

        if details:
            click.echo("")
            click.secho("  documentation", bold=True)
            click.echo("")
            indented = reindent(long_help, 4)
            click.echo(indented)

    click.echo("")
예제 #10
0
def list_roles_cli(ctx, filter, readme, defaults, meta):
    """
    Lists all roles that are available in the current context (which means, in the default and extra repositories configured by the user in a particular run).

    This command lists all roles in all repositories that are configure, it does not automatically tell you which one will be used if you have two roles with the same name. That depends on the order you specify repositories in a run (last repo wins).
    """

    config = ctx.obj["config"]

    repos = tasks.get_local_repos(config.trusted_repos, "roles",
                                  DEFAULT_LOCAL_REPO_PATH_BASE, DEFAULT_REPOS,
                                  DEFAULT_ABBREVIATIONS)

    click.echo("")
    click.secho("Available roles", bold=True)
    click.secho("===============", bold=True)
    click.echo("")

    for repo in repos:
        for role, role_details in sorted(
                tasks.get_role_details_in_repo(repo).items()):

            if filter and filter not in role:
                continue

            click.secho("\n{}\n{}\n".format(role, "-" * len(role)), bold=True)

            _path = role_details["path"]
            _author = role_details["meta"].get("galaxy_info",
                                               {}).get("author", "n/a")
            _desc = role_details["meta"].get("galaxy_info",
                                             {}).get("description", "n/a")
            _role_repo = role_details["repo"]

            click.secho("  desc", nl=False, bold=True)
            click.echo(": {}".format(_desc))
            click.secho("  path", nl=False, bold=True)
            click.echo(": {}".format(_path))
            click.secho("  repo", nl=False, bold=True)
            click.echo(": {}".format(_role_repo))

            click.secho("  author", nl=False, bold=True)
            click.echo(": {}".format(_author))

            if readme:
                click.echo("")
                click.secho("  readme", bold=True)
                click.echo("")
                indented = reindent(role_details["readme"], 4)
                click.echo(indented)

            if defaults:
                click.echo("")
                click.secho("  defaults", bold=True)
                click.echo("")

                for key, value in role_details["defaults"].items():
                    click.echo("    path: ", nl=False)
                    click.secho(" {}".format(key), nl=True, bold=True)
                    yaml_string = yaml.dump(value, default_flow_style=False)
                    indented = reindent(yaml_string, 11)
                    click.echo("")
                    click.echo(indented)

            if meta:
                click.echo("")
                click.secho("  meta", bold=True)
                click.echo("")
                yaml_string = yaml.dump(role_details["meta"],
                                        default_flow_style=False)
                indented = reindent(yaml_string, 4)
                click.echo(indented)

    click.echo("")