Example #1
0
File: paictl.py Project: yds05/pai
 def k8s_bootup(self, args):
     cluster_config = cluster_object_model_generate_k8s(args.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.")
Example #2
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"]:
        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)
Example #3
0
    def k8s_clean(self, args):
        # just use 'k8s-clean' for testing temporarily  .
        cluster_config = cluster_object_model_generate_k8s(args.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 args.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=args.force, clean=True)
        logger.info("Clean up job finished")
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()