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()
    def process_args(self, args):
        cluster_object_model_instance = cluster_object_model(args.config_path)
        com = cluster_object_model_instance.kubernetes_config()
        node_list = file_handler.load_yaml_config(args.node_list)

        if not kubectl_env_checking(com):
            raise RuntimeError("failed to do kubectl checking")

        for host in node_list["machine-list"]:
            if "nodename" not in host:
                host["nodename"] = host["hostip"]

        return com, node_list
Example #3
0
def validate_config(config_path):
    layout_file = os.path.join(config_path, "layout.yaml")
    old_cluster_config_file = os.path.join(config_path,
                                           "cluster-configuration.yaml")
    if (os.path.exists(old_cluster_config_file)
            and not os.path.exists(layout_file)):
        logger.error("[Error] - Please upgrade config files!")
        exit(-1)

    # kubernetes config
    my_cluster_object_model = cluster_object_model(config_path)
    kubernetes_config = my_cluster_object_model.kubernetes_config()
    logger.info("[OK] vaildate kubernetes config.")

    # pai service config
    service_config = my_cluster_object_model.service_config()
    logger.info("[OK] vaildate PAI services config.")
Example #4
0
    def check(self, args):
        # validate config

        logger.info("Begin to check config files. ")
        config_path = os.path.expanduser(args.config_path)
        logger.info("Config files directory: %s", config_path)

        layout_file = os.path.join(config_path, "layout.yaml")
        old_cluster_config_file = os.path.join(config_path,
                                               "cluster-configuration.yaml")
        if (os.path.exists(old_cluster_config_file)
                and not os.path.exists(layout_file)):
            logger.error("[Error], please upgrade config files!")
            exit(-1)

        # kubernetes config
        my_cluster_object_model = cluster_object_model(args.config_path)
        kubernetes_config = my_cluster_object_model.kubernetes_config()
        logger.info("[OK] vaildate kubernetes config.")

        # pai service config
        service_config = my_cluster_object_model.service_config()
        logger.info("[OK] vaildate PAI services config.")
    def k8s_clean(self, args):
        # just use 'k8s-clean' for testing temporarily.
        cluster_object_model_instance = cluster_object_model(args.config_path)
        com = cluster_object_model_instance.kubernetes_config()
        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.")
        k8s_util.maintain_cluster_k8s(com,
                                      option_name="clean",
                                      force=args.force,
                                      clean=True)
        logger.info("Clean up job finished")
 def k8s_bootup(self, args):
     cluster_object_model_instance = cluster_object_model(args.config_path)
     com = cluster_object_model_instance.kubernetes_config()
     logger.info("Begin to initialize PAI k8s cluster.")
     k8s_util.maintain_cluster_k8s(com, option_name="deploy", clean=True)
     logger.info("Finish initializing PAI k8s cluster.")
Example #7
0
 def get_machine_list(self, config_path):
     objectModelFactoryHandler = cluster_object_model(configuration_path=config_path)
     return objectModelFactoryHandler.kubernetes_config()["machine"]["machine-list"]