예제 #1
0
    def join(self, ip, password):
        config = configuration()
        ssh_obj = ssh()
        config_api = ConfigAPI()

        if os.path.exists(config_api.get_cluster_info_file_path()):
            os.remove(config_api.get_cluster_info_file_path())
        Network().clean_bonding()
        logger.info("Starting node join")

        if ssh_obj.copy_public_key_from_host(ip, password):
            logger.info("Successfully copied public keys.")
            if ssh_obj.copy_private_key_from_host(ip, password):
                ssh_obj.create_authorized_key_file()
                logger.info("Successfully copied private keys.")
                config.set_password(password)
                logger.info("password set successfully.")

        else:
            raise SSHKeyException(
                "Error while copying keys or setting password.")

        if not ssh_obj.call_command(
                ip, "python {}".format(
                    config_api.get_cluster_status_for_join_path())):
            raise JoinException("ceph monitor status not healthy.")

        if not os.listdir(
                os.path.dirname(config_api.get_cluster_info_file_path())):
            os.makedirs(
                os.path.dirname(config_api.get_cluster_info_file_path()))
        logger.info("Start copying  cluster info file.")

        if not ssh_obj.copy_file_from_host(
                ip, config_api.get_cluster_info_file_path()):
            raise Exception("Error while copy cluster info file.")
        logger.info("Successfully copied cluster info file.")

        cluster_name = config.get_cluster_name(True)
        logger.info("Joined cluster {}".format(cluster_name))
        self.__copy_current_tunings(ip)
        return cluster_name
예제 #2
0
    def replace(self, ip, password):
        config = configuration()
        ssh_obj = ssh()
        config_api = ConfigAPI()
        logger.info("Starting replace.")
        if os.path.exists(config_api.get_cluster_info_file_path()):
            os.remove(config_api.get_cluster_info_file_path())

        if ssh_obj.copy_public_key_from_host(ip, password):
            logger.info("Successfully copied public keys.")
            if ssh_obj.copy_private_key_from_host(ip, password):
                ssh_obj.create_authorized_key_file()
                logger.info("Successfully copied private keys.")

        else:
            raise SSHKeyException("Error copying keys")

        out, err = ssh_obj.exec_command(
            ip,
            "python {}".format(config_api.get_cluster_status_for_join_path()))
        out = int(out)
        if out == -1:
            raise ReplaceException("core_deploy_replace_mon_not_healthy_err")
        elif out == 0:
            raise ReplaceException(
                "core_deploy_replace_cluster_in_progress_err")
        elif out == 1:
            raise ReplaceException(
                "core_deploy_replace_two_management_node_down_err")
        elif out == 3:
            raise ReplaceException("core_deploy_replace_cluster_running_err")

        if not os.listdir(
                os.path.dirname(config_api.get_cluster_info_file_path())):
            os.makedirs(
                os.path.dirname(config_api.get_cluster_info_file_path()))

        logger.info("Starting to copy config file")
        if not ssh_obj.copy_file_from_host(
                ip, config_api.get_cluster_info_file_path()):
            raise Exception("Error copying  config file")

        logger.info("Successfully copied config file.")
        cluster_name = config.get_cluster_name(True)
        logger.info("Successfully joined to cluster {}".format(cluster_name))

        wrong_name = True
        wrong_ip = True
        for node_info in config.get_management_nodes_config():
            if node_info.name == config.get_node_name(
            ) or node_info.management_ip == Network().get_node_management_ip():
                if node_info.name == config.get_node_name():
                    wrong_name = False

                if node_info.management_ip == Network().get_node_management_ip(
                ):
                    wrong_ip = False

                if not wrong_name and not wrong_ip:
                    config.set_node_info(node_info, True)
                    open(config_api.get_replace_file_path(), 'w+').close()
                break

        if wrong_name and wrong_ip:
            os.remove(config_api.get_cluster_info_file_path())
            raise ReplaceException("core_deploy_replace_node_do_not_match_err")
        elif wrong_name:
            os.remove(config_api.get_cluster_info_file_path())
            raise ReplaceException(
                "core_deploy_replace_node_do_not_match_name_err")
        elif wrong_ip:
            os.remove(config_api.get_cluster_info_file_path())
            raise ReplaceException(
                "core_deploy_replace_node_do_not_match_ip_err")

        config.set_password(password)
        logger.info("password set successfully.")
        self.__copy_current_tunings(ip)
        return cluster_name