def k8s_set_environment(self, args):
     if args.config_path != None:
         args.config_path = os.path.expanduser(args.config_path)
         cluster_object_model_instance = cluster_object_model(
             args.config_path)
         com = cluster_object_model_instance.kubernetes_config()
     else:
         com = None
     kubectl_install_worker = kubectl_install.kubectl_install(com)
     kubectl_install_worker.run()
Example #2
0
File: paictl.py Project: yds05/pai
def kubectl_env_checking(cluster_object_mode):

    kubectl_conf_ck_worker = kubectl_conf_check.kubectl_conf_check(
        cluster_object_mode)
    if kubectl_conf_ck_worker.check() == False:
        count_input = 0

        while True:
            user_input = raw_input(
                "Do you want to re-install kubectl by paictl? (Y/N) ")

            if user_input == "N":
                count_quit = 0
                while True:
                    quit_or_not = raw_input(
                        "Do you want to quit by this operation? (Y/N) ")
                    if quit_or_not == "Y":
                        return False
                    elif quit_or_not == "N":
                        return True
                    else:
                        print(" Please type Y or N.")
                    count_quit = count_quit + 1
                    if count_quit == 3:
                        logger.warning(
                            "3 Times.........  Sorry,  we will force stopping your operation."
                        )
                        return False

            elif user_input == "Y":
                kubectl_install_worker = kubectl_install.kubectl_install(
                    cluster_object_mode)
                kubectl_install_worker.run()
                return True

            else:
                print(" Please type Y or N.")

            count_input = count_input + 1
            if count_input == 3:
                logger.warning(
                    "3 Times.........  Sorry,  we will force stopping your operation."
                )
                return False
    return True
Example #3
0
File: paictl.py Project: yds05/pai
 def install_kubectl(self, args):
     cluster_object_model_k8s = cluster_object_model_generate_k8s(
         args.config_path)
     kubectl_install_worker = kubectl_install.kubectl_install(
         cluster_object_model_k8s)
     kubectl_install_worker.run()
Example #4
0
def pai_cluster():
    if len(sys.argv) < 2:
        pai_cluster_info()
        return
    option = sys.argv[1]
    del sys.argv[1]
    if option not in [
            "k8s-bootup", "k8s-clean", "generate-configuration",
            "install-kubectl"
    ]:
        pai_cluster_info()
        return
    if option == "k8s-bootup":
        parser = argparse.ArgumentParser()
        parser.add_argument('-p',
                            '--config-path',
                            dest="config_path",
                            required=True,
                            help="path of cluster configuration file")
        args = parser.parse_args(sys.argv[1:])
        config_path = args.config_path
        cluster_config = cluster_object_model_generate_k8s(config_path)
        logger.info("Begin to initialize PAI k8s cluster.")
        cluster_util.maintain_cluster_k8s(cluster_config,
                                          option_name="deploy",
                                          clean=True)
        logger.info("Finish initializing PAI k8s cluster.")
    elif option == "generate-configuration":
        parser = argparse.ArgumentParser(
            description=
            "Generate configuration files based on a quick-start yaml file.",
            formatter_class=argparse.RawDescriptionHelpFormatter)
        parser.add_argument(
            '-i',
            '--input',
            dest="quick_start_config_file",
            required=True,
            help=
            "the path of the quick-start configuration file (yaml format) as the input"
        )
        parser.add_argument(
            '-o',
            '--output',
            dest="configuration_directory",
            required=True,
            help=
            "the path of the directory the configurations will be generated to"
        )
        parser.add_argument('-f',
                            '--force',
                            dest='force',
                            action='store_true',
                            required=False,
                            help="overwrite existing files")
        parser.set_defaults(force=False)
        args = parser.parse_args()
        cluster_util.generate_configuration(args.quick_start_config_file,
                                            args.configuration_directory,
                                            args.force)
    elif option == "k8s-clean":
        # just use 'k8s-clean' for testing temporarily  .
        parser = argparse.ArgumentParser()
        parser.add_argument('-p',
                            '--config-path',
                            dest="config_path",
                            required=True,
                            help="path of cluster configuration file")
        parser.add_argument('-f',
                            '--force',
                            dest="force",
                            required=False,
                            action="store_true",
                            help="clean all the data forcefully")
        args = parser.parse_args(sys.argv[1:])
        config_path = args.config_path
        force = args.force
        cluster_config = cluster_object_model_generate_k8s(config_path)

        logger.warning(
            "--------------------------------------------------------")
        logger.warning(
            "--------------------------------------------------------")
        logger.warning(
            "----------     Dangerous Operation!!!    ---------------")
        logger.warning(
            "------     Your k8s Cluster will be destroyed    -------")
        logger.warning(
            "------     PAI service on k8s will be stopped    -------")
        logger.warning(
            "--------------------------------------------------------")
        if force:
            logger.warning(
                "--------------------------------------------------------")
            logger.warning(
                "----------    ETCD data will be cleaned.    ------------")
            logger.warning(
                "-----    If you wanna keep pai's user data.    ---------")
            logger.warning(
                "-----         Please backup etcd data.         ---------")
            logger.warning(
                "-----      And restore it after k8s-bootup     ---------")
            logger.warning(
                "---     And restore it before deploy pai service    ----")
            logger.warning(
                "--------------------------------------------------------")
        logger.warning(
            "--------------------------------------------------------")
        logger.warning(
            "----    Please ensure you wanna do this operator, ------")
        logger.warning(
            "-------        after knowing all risk above.     -------")
        logger.warning(
            "--------------------------------------------------------")
        logger.warning(
            "--------------------------------------------------------")

        count_input = 0

        while True:
            user_input = raw_input(
                "Do you want to continue this operation? (Y/N) ")
            if user_input == "N":
                return
            elif user_input == "Y":
                break
            else:
                print(" Please type Y or N.")
            count_input = count_input + 1
            if count_input == 3:
                logger.warning(
                    "3 Times.........  Sorry,  we will force stopping your operation."
                )
                return

        logger.info("Begin to clean up whole cluster.")
        cluster_util.maintain_cluster_k8s(cluster_config,
                                          option_name="clean",
                                          force=force,
                                          clean=True)
        logger.info("Clean up job finished")
    elif option == "install-kubectl":
        parser = argparse.ArgumentParser()
        parser.add_argument('-p',
                            '--config-path',
                            dest="config_path",
                            required=True,
                            help="path of cluster configuration file")
        args = parser.parse_args(sys.argv[1:])

        cluster_object_model_k8s = cluster_object_model_generate_k8s(
            args.config_path)
        kubectl_install_worker = kubectl_install.kubectl_install(
            cluster_object_model_k8s)
        kubectl_install_worker.run()