コード例 #1
0
ファイル: __main__.py プロジェクト: quarckster/ocdeployer
def list_sets(template_dir, output=None):
    as_dict = {"service_sets": all_sets(template_dir)}

    if not output:
        log.info("Available service sets:\n * %s", "\n * ".join(as_dict["service_sets"]))

    elif output == "json":
        print(json.dumps(as_dict, indent=2))

    elif output == "yaml":
        print(yaml.dump(as_dict, default_flow_style=False))
コード例 #2
0
ファイル: __main__.py プロジェクト: bsquizz/ocdeployer
def list_sets(template_dir, output=None):
    as_dict = {"service_sets": all_sets(template_dir)}

    if not output:
        log.info("Available service sets:\n * %s", "\n * ".join(as_dict["service_sets"]))

    elif output == "json":
        print(json.dumps(as_dict, indent=2))

    elif output == "yaml":
        print(yaml.dump(as_dict, default_flow_style=False))
コード例 #3
0
def _parse_args(template_dir, all_services, sets, pick, dst_project,
                env_files):
    """Parses args common to 'process' and 'deploy'."""
    if not template_dir:
        path = appdirs_path / "templates"
        template_dir = path if path.exists() else pathlib.Path(
            pathlib.os.getcwd()) / "templates"

    template_dir = os.path.abspath(template_dir)

    if not all_services and not sets and not pick:
        log.error("Error: no service sets or components selected for deploy."
                  " Use --sets, --all, or --pick")
        sys.exit(1)

    specific_component = None
    server = get_server_info()

    if pick:
        try:
            service_set, specific_component = pick.split("/")
        except ValueError:
            log.error(
                "Invalid format for '--pick', use: 'service_set/component'")
            sys.exit(1)
        sets_selected = [service_set]
        confirm_msg = (
            "Deploying single component '{}' to project '{}' on server {} -- continue?"
            .format(pick, dst_project, server))
    else:
        if all_services:
            sets_selected = all_sets(template_dir)
        else:
            sets_selected = sets.split(",")
        confirm_msg = (
            "Deploying service sets '{}' to project '{}' on server {} -- continue?"
            .format(", ".join(sets_selected), dst_project, server))

    if env_files:
        variables_data = get_variables_data(env_files)
    else:
        variables_data = {}

    return template_dir, specific_component, sets_selected, variables_data, confirm_msg
コード例 #4
0
ファイル: __main__.py プロジェクト: bsquizz/ocdeployer
def _parse_args(template_dir, all_services, sets, pick, dst_project, env_files):
    """Parses args common to 'process' and 'deploy'."""
    if not template_dir:
        path = appdirs_path / "templates"
        template_dir = path if path.exists() else pathlib.Path(pathlib.os.getcwd()) / "templates"

    template_dir = os.path.abspath(template_dir)

    if not all_services and not sets and not pick:
        log.error(
            "Error: no service sets or components selected for deploy."
            " Use --sets, --all, or --pick"
        )
        sys.exit(1)

    specific_component = None

    if pick:
        try:
            service_set, specific_component = pick.split("/")
        except ValueError:
            log.error("Invalid format for '--pick', use: 'service_set/component'")
            sys.exit(1)
        sets_selected = [service_set]
        confirm_msg = "Deploying single component '{}' to project '{}'.  Continue?".format(
            pick, dst_project
        )
    else:
        if all_services:
            sets_selected = all_sets(template_dir)
        else:
            sets_selected = sets.split(",")
        confirm_msg = "Deploying service sets '{}' to project '{}'.  Continue?".format(
            ", ".join(sets_selected), dst_project
        )

    if env_files:
        variables_data = get_variables_data(env_files)
    else:
        variables_data = {}

    return template_dir, specific_component, sets_selected, variables_data, confirm_msg
コード例 #5
0
ファイル: __main__.py プロジェクト: bsquizz/ocdeployer
def _parse_args(template_dir, env_values, env_files, all_services, sets, pick,
                dst_project):
    """Parses args common to 'process' and 'deploy'."""
    template_dir = get_dir(template_dir, "templates", "template")

    # Analyze the values provided by --env to determine which config handler we are using
    if env_values and env_files:
        log.error("You cannot use both --env and --env-file")
        sys.exit(1)
    elif env_values:
        all_env_values_are_files = all(
            [os.path.exists(value) for value in env_values])
        some_env_values_are_files = any(
            [os.path.exists(value) for value in env_values])
        if all_env_values_are_files:
            log.info(
                "A specific filename was provided for env, using legacy env file processing"
            )
            env_config_handler = LegacyEnvConfigHandler(env_files=env_values)
        elif some_env_values_are_files:
            log.error(
                "Error: Values for '--env' must be either all filenames, or all env names"
            )
            sys.exit(1)
        else:
            env_config_handler = EnvConfigHandler(env_names=env_values)
    elif env_files:
        log.info(
            "A specific filename was provided for env, using legacy env file processing"
        )
        env_config_handler = LegacyEnvConfigHandler(env_files=env_files)
    else:
        env_config_handler = EnvConfigHandler(env_names=[])

    log.info("Using environments: %s", ", ".join(env_values or env_files))

    if not all_services and not sets and not pick:
        log.error("Error: no service sets or components selected for deploy."
                  " Use --sets, --all, or --pick")
        sys.exit(1)

    server = get_server_info()

    sets_selected = []
    specific_components = []

    if all_services:
        sets_selected = all_sets(template_dir)
    else:
        if pick:
            try:
                [p.split("/")[1] for p in pick.split(",")]
            except (ValueError, IndexError):
                log.error(
                    "Invalid format for '--pick', use: 'service_set/component'"
                )
                sys.exit(1)
            specific_components = list(set(pick.split(",")))
        if sets:
            sets_selected = list(set(sets.split(",")))

    joined_sets = ", ".join(sets_selected)
    joined_comps = ", ".join(specific_components)
    sets_string = f" service sets: [{joined_sets}]" if joined_sets else ""
    comps_string = f" components: [{joined_comps}]" if joined_comps else ""
    confirm_msg = (
        f"Deploying{sets_string}{comps_string} "
        f"to project '{dst_project}' on server {server} -- continue?")

    return template_dir, env_config_handler, specific_components, sets_selected, confirm_msg