Exemple #1
0
    def reset_cluster_interface(self):
        try:
            config = configuration()
            cluster_info = config.get_cluster_info()

            cluster_info.bonds = []
            cluster_info.jumbo_frames = []
            config.set_cluster_network_info(cluster_info)
            logger.info("Updated cluster interface successfully.")

        except Exception as ex:
            logger.exception(ex.message)
            return Status().error
        return Status().done
Exemple #2
0
    def add_management_node(self):
        """
        :type node_info: NodeInfo
        """
        try:

            ci = self.get_cluster_info()
            ci.management_nodes.append(self.get_node_info())
            self.set_cluster_network_info(ci)

        except Exception as ex:
            logger.error("Cannot add management node")
            return Status().error
        return Status().done
Exemple #3
0
    def start_node_backend_networks(self):
        config_api = ConfigAPI()
        try:
            if call_script(config_api.get_node_start_ips_script_path()) != 0:
                raise Exception("Error starting backend networks")

        except Exception as ex:
            return Status().error
Exemple #4
0
    def set_node_info_role(self, is_storage, is_iscsi, is_backup):
        """
        :param is_storage: bool
        :param is_iscsi: bool
        :param is_backup: bool
        """
        try:
            config = configuration()
            current_node_info = config.get_node_info()
            current_node_info.is_storage = is_storage
            current_node_info.is_iscsi = is_iscsi
            current_node_info.is_backup = is_backup
            config.set_node_info(current_node_info)
            logger.info("Set node role completed successfully.")

        except Exception as ex:
            logger.exception(ex.message)
            return Status().error
        return Status().done
Exemple #5
0
    def set_cluster_interface(self, bonds=[], jumbo_frames_eths=[]):
        try:
            if (not bonds
                    or len(bonds) == 0) and (not jumbo_frames_eths
                                             or len(jumbo_frames_eths) == 0):
                return Status().done
            config = configuration()
            cluster_info = config.get_cluster_info()

            cluster_info.bonds = bonds
            cluster_info.jumbo_frames = jumbo_frames_eths
            config.set_cluster_network_info(cluster_info)
            logger.info("Updated cluster interface successfully.")

        except Exception as ex:
            logger.exception(ex.message)
            return Status().error

        return Status().done
Exemple #6
0
    def set_node_info(self, node_info):
        """
        :type node_info: NodeInfo
        """
        try:
            config = configuration()
            net = Network()
            node_info.name = config.get_node_name()
            node_info.management_ip = net.get_node_management_ip()
            config.set_node_info(node_info)
            config_api = ConfigAPI()

            if call_script(config_api.get_node_start_ips_script_path()) != 0:
                raise Exception("Error could not start backend network.")
            logger.info("Set node info completed successfully.")

        except Exception as ex:
            logger.exception(ex.message)
            return Status().error

        return Status().done
Exemple #7
0
    def set_cluster_network_info(self, cluster_info):
        """
        :type cluster_info: ClusterInfo
        """
        try:
            config = configuration()
            net = Network()
            current_cluster_info = config.get_cluster_info()
            cluster_info.name = current_cluster_info.name
            cluster_info.bonds = current_cluster_info.bonds
            cluster_info.jumbo_frames = current_cluster_info.jumbo_frames
            cluster_info.eth_count = len(net.get_node_interfaces())
            cluster_info.management_eth_name = net.get_node_management_interface(
            )
            config.set_cluster_network_info(cluster_info)
            logger.info("Updated cluster network successfully.")

        except Exception as ex:
            logger.exception(ex.message)
            return Status().error
        return Status().done
Exemple #8
0
    def create_cluster_info(self, password, cluster_name):
        config = configuration()
        ssh_obj = ssh()
        try:
            ssh_obj.create_id(True)
            ssh_obj.create_authorized_key_file()
            logger.info("Created keys for cluster {}".format(cluster_name))
            config.set_cluster_name(cluster_name)
            logger.info(
                "Created cluster file and set cluster name to {}".format(
                    cluster_name))

            Network().clean_bonding()
            if not config.set_password(password):
                logger.error("Could not set root password.")
                return Status().error
            logger.info("password set successfully.")

        except Exception as ex:
            logger.exception(ex.message)
            return Status().error
        return Status().done
Exemple #9
0
    def build(self):
        try:
            self.__status_report = StatusReport()
            conf = configuration()

            if len(conf.get_cluster_info().management_nodes) == 0:
                node_num = len(conf.get_cluster_info().management_nodes) + 1
                self.__status_report.nod_num = node_num
                NTPConf().setup_ntp_local()
                if conf.add_management_node() != Status().done:
                    self.__status_report.success = False
                    self.__status_report.failed_tasks.append(
                        "core_cluster_deploy_cant_add_node")

                logger.info(
                    "Node 1 added, cluster requires 2 other nodes to build.")
                self.run_post_deploy_script()
                return BuildStatus().OneManagementNode

            elif len(conf.get_cluster_info().management_nodes) == 1:
                node_num = len(conf.get_cluster_info().management_nodes) + 1
                self.__status_report.nod_num = node_num

                connection_status = self.check_connections()
                if not connection_status.success:
                    self.__status_report.failed_tasks.extend(
                        connection_status.failed_tasks)
                    logger.error("Connection ping error.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().connection_error

                NTPConf().setup_ntp_local()

                if conf.add_management_node() != Status().done:
                    self.__status_report.success = False
                    self.__status_report.failed_tasks.append(
                        "core_cluster_deploy_cant_add_node")
                    return BuildStatus().error
                if not self.__sync_cluster_config_file():
                    return BuildStatus().error

                logger.info(
                    "Node 2 is added, cluster requires 1 other node to build.")
                self.run_post_deploy_script()
                return BuildStatus().TwoManagementNodes

            elif len(conf.get_cluster_info().management_nodes) == 2:
                node_num = len(conf.get_cluster_info().management_nodes) + 1
                self.__status_report.nod_num = node_num

                connection_status = self.check_connections()
                if not connection_status.success:
                    self.__status_report.failed_tasks.extend(
                        connection_status.failed_tasks)
                    logger.error("Connection ping error.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().connection_error

                status = self.check_remote_connection()
                if not status.success:
                    self.__status_report = status
                    return BuildStatus().error

                NTPConf().setup_ntp_local()

                logger.info("Stopping petasan services on all nodes.")
                self.stop_petasan_services()
                logger.info("Starting local clean_ceph.")
                clean_ceph()
                logger.info("Starting local clean_consul.")
                clean_consul()

                status = build_consul()
                if not status.success:
                    self.__status_report.failed_tasks.extend(
                        status.failed_tasks)
                    logger.error("Could not build consul.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().build_consul_error

                status = build_monitors()
                if not status.success:
                    self.__status_report = status
                    logger.error("Could not build ceph monitors.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().build_monitors_error

                status = build_osds()
                if not status.success:
                    self.__status_report = status
                    logger.error("Could not build ceph OSDs.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().build_osd_error
                else:
                    self.__status_report.failed_tasks.extend(
                        status.failed_tasks)

                logger.info("Main core components deployed.")

                if not self.__commit_management_nodes():
                    self.__status_report.success = False
                    logger.error("Could not commit node.")
                    self.__status_report.failed_tasks.append(
                        "core_cluster_deploy_couldnt_commit_node")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().error

                logger.info("Starting all services.")
                self.start_petasan_services()

                if not self.add__node_to_hosts_file():
                    self.__status_report.success = False
                    logger.error("Could not add node to hosts file.")
                    self.__status_report.failed_tasks.append(
                        "core_cluster_deploy_couldnt_add_node_hosts")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().error

                SharedFS().setup_management_nodes()

                if conf.add_management_node() != Status().done:
                    self.__status_report.success = False
                    self.__status_report.failed_tasks.append(
                        "core_cluster_deploy_couldnt_add_node_config")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().error

                logger.info("Updating rbd pool.")
                if not create_rbd_pool():
                    self.__status_report.success = False
                    self.__status_report.failed_tasks.append(
                        "core_cluster_deploy_couldnt_update_rbd")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().error

                logger.info("Creating EC Profiles.")
                if not create_ec_profiles():
                    self.__status_report.success = False
                    self.__status_report.failed_tasks.append(
                        "core_cluster_deploy_couldnt_create_ec_profiles")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().error

                logger.info(
                    "Waiting for ceph to reach active and clean status.")
                test_active_clean()
                if not self.__sync_cluster_config_file():
                    return BuildStatus().error

                self.run_post_deploy_script()
                self.kill_petasan_console(True)
                logger.info("Node 3 added and cluster is now ready.")

            elif len(
                    conf.get_cluster_info().management_nodes
            ) == 3 and not os.path.exists(ConfigAPI().get_replace_file_path()):
                # ------------------------------ Join ------------------------------ #
                # ------------------------------------------------------------------ #
                node_num = len(conf.get_cluster_info().management_nodes) + 1
                self.__status_report.nod_num = node_num
                logger.info("Joining node to running cluster.")

                connection_status = self.check_connections()
                if not connection_status.success:
                    self.__status_report.failed_tasks.extend(
                        connection_status.failed_tasks)
                    logger.error("Connection ping error.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().connection_error

                status = self.check_remote_connection()
                NTPConf().setup_ntp_local()

                if not status.success:
                    self.__status_report = status
                    return BuildStatus().error

                logger.info("Stopping petasan services on local node.")
                self.stop_petasan_services(remote=False)
                logger.info("Starting local clean_ceph.")
                clean_ceph_local()
                logger.info("Starting local clean_consul.")
                clean_consul_local()

                status = build_consul_client()
                if not status.success:
                    self.__status_report.failed_tasks.extend(
                        status.failed_tasks)
                    logger.error("Could not build consul client.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().build_consul_error

                status = copy_ceph_config_from_mon()
                if not status.success:
                    self.__status_report.failed_tasks.extend(
                        status.failed_tasks)
                    logger.error("Could not copy ceph config.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().build_consul_error

                status = create_osds_local()
                if not status.success:
                    self.__status_report = status
                    logger.error("Could not build ceph OSDs.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().build_osd_error
                else:
                    self.__status_report.failed_tasks.extend(
                        status.failed_tasks)

                logger.info("Main core components deployed.")
                logger.info("Staring all services")
                self.start_petasan_services(remote=False)
                test_active_clean()
                if not self.__commit_local_node():
                    test_active_clean()
                    if not self.__commit_local_node():
                        self.__status_report.success = False
                        logger.error("Could not commit node.")
                        self.__status_report.failed_tasks.append(
                            "core_cluster_deploy_couldnt_commit_node_join")
                        logger.error(self.__status_report.failed_tasks)
                        os.remove(ConfigAPI().get_cluster_info_file_path())
                        return BuildStatus().error

                if not self.add__node_to_hosts_file(remote=False):
                    test_active_clean()
                    if not self.add__node_to_hosts_file(remote=False):
                        self.__status_report.success = False
                        logger.error("Could not add node to hosts file.")
                        self.__status_report.failed_tasks.append(
                            "core_cluster_deploy_couldnt_add_node_hosts")
                        logger.error(self.__status_report.failed_tasks)
                        os.remove(ConfigAPI().get_cluster_info_file_path())
                        return BuildStatus().error

                logger.info("Node successfully joined to cluster.")
                self.kill_petasan_console(False)
                if os.path.exists(ConfigAPI().get_replace_file_path()):
                    os.remove(ConfigAPI().get_replace_file_path())

                self.run_post_deploy_script()
                return BuildStatus().done_joined

            elif len(conf.get_cluster_info().management_nodes
                     ) == 3 and os.path.exists(
                         ConfigAPI().get_replace_file_path()):
                # ----------------------------- Replace ---------------------------- #
                # ------------------------------------------------------------------ #
                node_num = len(conf.get_cluster_info().management_nodes) + 1
                self.__status_report.nod_num = node_num
                logger.info("Replace node is starting.")

                connection_status = self.check_connections()
                if not connection_status.success:
                    self.__status_report.failed_tasks.extend(
                        connection_status.failed_tasks)
                    logger.error("Connection ping error.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().connection_error

                status = self.check_remote_connection()
                NTPConf().setup_ntp_local()

                if not status.success:
                    self.__status_report = status
                    return BuildStatus().error

                logger.info("Stopping petasan services on local node.")
                self.stop_petasan_services(remote=False)
                logger.info("Starting clean_ceph.")
                clean_ceph_local()
                logger.info("Starting local clean_consul.")
                clean_consul_local()

                status = replace_consul_leader()
                if not status.success:
                    self.__status_report.failed_tasks.extend(
                        status.failed_tasks)
                    logger.error("Could not replace consul leader.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().build_consul_error

                status = replace_local_monitor()
                if not status.success:
                    self.__status_report.failed_tasks.extend(
                        status.failed_tasks)
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().build_monitors_error

                status = create_osds_local()
                if not status.success:
                    self.__status_report = status
                    logger.error("Could not build ceph OSDs.")
                    logger.error(self.__status_report.failed_tasks)
                    return BuildStatus().build_osd_error
                else:
                    self.__status_report.failed_tasks.extend(
                        status.failed_tasks)

                logger.info("Main core components deployed.")
                logger.info("Starting all services.")
                self.start_petasan_services(remote=False)
                test_active_clean()

                SharedFS().rebuild_management_node()

                logger.info("Node successfully added to cluster.")
                self.run_post_deploy_script()
                self.kill_petasan_console(False)
                os.remove(ConfigAPI().get_replace_file_path())
                return BuildStatus().done_replace

        except Exception as ex:
            config_api = ConfigAPI()
            if os.path.exists(config_api.get_cluster_info_file_path()):
                os.remove(config_api.get_cluster_info_file_path())
            logger.exception(ex.message)
            return BuildStatus().error

        return BuildStatus().done