Exemple #1
0
def check_secrets(docker_compose_path: str, no_prompt: bool = False):
    log.info("Checking Coral secrets...")
    required_secrets = swarmadmin.get_objs_from_compose(
        "secret", docker_compose_path)
    missing_secrets = list(
        filter(lambda x: not swarmadmin.obj_exists("secret", x),
               required_secrets))

    if len(missing_secrets) > 0:
        log.info("Some required secrets are missing")

        if no_prompt:
            raise Exception(
                "When running in test mode, all secrets must be manually created beforehand."
            )
        else:
            prompt_secrets(missing_secrets)
    else:
        if not no_prompt:
            question = "All required secrets are defined. Do you wish to redefine them? (y/n) "
            answer = fish.valid_answer_from_prompt(
                question, valid_answers=settings.get("prompt_boolean_answers"))
            log_file.info(question + answer)

            if fish.user_prompt_yes(answer):
                manage.remove_coral_objects("secret",
                                            silent=True,
                                            list_found_objs=False,
                                            prompt=False)
                prompt_secrets(required_secrets)
Exemple #2
0
def remove_coral_objects(obj_type: str,
                         silent: bool = False,
                         list_found_objs: bool = True,
                         prompt: bool = True,
                         is_dep: bool = False):
    if not silent:
        log.info(
            f"Removing{' dependent ' if is_dep else ' '}Coral {obj_type}s...")

    cleanup_params = settings.get("cleanup_params")[obj_type]
    rm_confirmation_msg, all_, quiet, format_, filters, force = [
        value for value in cleanup_params.values()
    ]

    obj_list = get_coral_objs(obj_type,
                              all_=all_,
                              quiet=quiet,
                              format_=f"\"{format_}\"",
                              filters=filters)

    if obj_list:
        bullets_obj_list = "\n".join(
            [f"- {line}" for line in obj_list.split("\n")])

        if list_found_objs and not silent:
            log.info(
                f"The following Coral {obj_type}s were found:\n{bullets_obj_list}"
            )
            log_stdout.info("")

        if prompt:
            question = f"{rm_confirmation_msg}\nAre you sure you want to remove these {obj_type}s? (y/n) "
            answer = fish.valid_answer_from_prompt(
                question, valid_answers=settings.get("prompt_boolean_answers"))
            log_file.info(question.replace("\n", " ") + answer)

        if not prompt or fish.user_prompt_yes(answer):
            remove_coral_obj_dependencies(obj_type, silent=silent)

            obj_ids = [
                i for i, j in (obj.split("\t") for obj in obj_list.split("\n"))
            ]
            if not silent: log.info(f"Removing {obj_type}s...")
            res = swarmadmin.rm(obj_type,
                                obj_ids,
                                force=force,
                                suppress_stdout=silent)
            fish.handle(res)
            if not silent: log.info(f"Done!")
    else:
        if not silent:
            log.info(f"No Coral {obj_type}s were found. Skipping...")
Exemple #3
0
def update():
    question = "Coral will be stopped in order to perform the update. Do you wish to continue? (y/n) "
    answer = fish.valid_answer_from_prompt(
        question, valid_answers=settings.get("prompt_boolean_answers"))
    log_file.info(question + answer)

    if fish.user_prompt_yes(answer):
        docker_compose_path = settings.get("compose_path")
        original_compose_file = None

        log.info("Updating Coral Docker images...")

        # check if a current deployment is using dev images
        curr_depl_conf = deploy.get_curr_depl_config()
        if curr_depl_conf is not None:
            original_compose_file = fish.read_file(docker_compose_path)
            dev = curr_depl_conf["advanced"]["dev_images"]
            if dev:
                deploy.switch_to_dev_images(
                    docker_compose_path)  # switch to dev images

        try:
            registry_login()
            pull_coral_images(docker_compose_path)
        finally:
            if original_compose_file is not None:
                fish.write_file(original_compose_file, docker_compose_path)

        log_stdout.info("")
        log.info("Coral Docker images successfully updated!")

        curr_depl_conf = deploy.get_curr_depl_config()

        if (curr_depl_conf is None):
            log.info("Cannot start Coral. Please deploy first.")
        else:
            domain = curr_depl_conf["basic"][
                "domain"]  # needed for logs after deployment
            deploy.prepare(skip_depl_config=True,
                           is_update=True,
                           docker_compose_path=docker_compose_path,
                           domain=domain,
                           email=None,
                           cert_type=None,
                           stack_name=None,
                           no_prompt=True)
Exemple #4
0
def check_skip_depl_config(no_prompt: bool = False):
    curr_depl_conf = get_curr_depl_config()

    if curr_depl_conf is None: return False

    curr_depl_conf = json.dumps(curr_depl_conf, indent=2)
    log.info(
        "Previous deployment configuration found:\n{0}".format(curr_depl_conf))

    if no_prompt:
        return True
    else:
        question = f"Do you wish to reuse the configuration above? (y/n) "
        answer = fish.valid_answer_from_prompt(
            question, valid_answers=settings.get("prompt_boolean_answers"))
        log_file.info(question + answer)

        return fish.user_prompt_yes(answer)
Exemple #5
0
def check_central_mon(env_file_path: str, no_prompt: bool = False):
    log.info("Checking for central monitoring configuration...")
    central_mon_url = get_central_monitor_url()

    if (len(central_mon_url["value"]) == 0):
        log.warn(
            f"A central monitoring URL has not been defined in {env_file_path}, line {str(central_mon_url['index'] + 1)}.\nThe monitoring features described in the 'Coral Monitor Stack' section of README.md will be disabled."
        )

        if not no_prompt:
            question = "Do you wish to continue? (y/n) "
            answer = fish.valid_answer_from_prompt(
                question, valid_answers=settings.get("prompt_boolean_answers"))
            log_file.info(question + answer)

            if fish.user_prompt_no(answer):
                sys.exit(0)

        return False
    else:
        log.info(f"Using {central_mon_url['value']} for central monitoring...")
        return True