# -*- coding:utf-8 -*-

import os
from utils.common.fic_base import StepBaseInterface
from utils.common.message import Message
import utils.common.log as logger
from utils.common.exception import FCUException
from utils.DBAdapter.DBConnector import BaseOps
from plugins.eBackup.common.util import get_cascaded_reverse_ips
from plugins.eBackup.common.eBackupUpgrade import eBackupUpgrader
from plugins.eBackup.common.eBackupDriverUpgrade import eBackupDriverUpgrader
from utils.common.ssh_util import Ssh
from plugins.eBackup.common.util import Utils, CommonConfig, get_deploy_info_from_cmdb
from utils.business.manageone_cmdb_util import ManageOneCmdbUtil
from utils.business.project_util import ProjectApi


class DatamoverUpgrade(StepBaseInterface):
    def __init__(self, project_id, pod_id, regionid_list):
        super(DatamoverUpgrade, self).__init__(project_id, pod_id, regionid_list)
        self.project_id = project_id
        self.pod_id = pod_id
        self.regionid_list = regionid_list
        self.__db_param_dict = Utils.init_system_params(project_id, regionid_list[0])
        self.result_file = os.path.abspath(__file__ + '/../{}_datamover_upgrade_result.txt'.format(regionid_list[0]))

    def execute(self, project_id, pod_id, regionid_list):
        try:
            host_info = self.__db_param_dict["eBackup_Datamover_nodes"]
            host_info = host_info.replace(" ", "").split("|")

            all_result = []
            with open(self.result_file, mode='w') as fp:
                fp.truncate()

            logger.info("Begin to upgrade all datamover nodes(%s)" % str(host_info))
            for group in host_info:
                host_ips = group.split(";")
                logger.info("Begin to upgrade datamover nodes(%s)" % str(host_ips))
                ebackup_upgrade = eBackupUpgrader(host_ips, self.__db_param_dict, "datamover")
                is_true = ebackup_upgrade.upgrade()
                if is_true:
                    logger.info("Upgrade eBackup datamover(%s) successfully." % str(host_ips))
                else:
                    logger.error("Fail to upgrade eBackup datamover(%s)." % str(host_ips))
                    with open(self.result_file, mode='a') as fp:
                        fp.write(','.join(host_ips) + '\n')
                all_result.append(is_true)

            if False in all_result:
                logger.error("Fail to upgrade all eBackup datamover nodes.")
                return Message(500, error_msg_cn="升级Datamover失败，请登录DMK查看失败原因，请勿直接重试",
                               error_msg_en="Upgrade Datamover failed, please log in DMK to see the details"
                                            ", do not directly retry")

            logger.info("Upgrade all eBackup datamover successfully.")
            if os.path.exists(self.result_file):
                os.remove(self.result_file)
            return Message(200)

        except Exception as ex:
            logger.error(str(ex))
            return Message(500, error_msg_cn="升级Datamover出现异常，请勿直接重试：{}".format(str(ex)),
                           error_msg_en="Exception occurs when upgrade Datamover,do not directly retry:{}".format(str(ex)))

    def rollback(self, project_id, pod_id, regionid_list):
        return Message(200)

    def retry(self, project_id, pod_id, regionid_list):
        try:
            if not os.path.exists(self.result_file):
                logger.error("There is no result file:" + self.result_file)
                raise FCUException(650032, self.result_file + " does not exist", self.result_file)

            with open(self.result_file, mode='r') as fp:
                host_group_list = fp.readlines()

            if 0 == len(host_group_list):
                logger.error("Get ips from {} failed.".format(self.result_file))
                raise FCUException(650032, "There is no IP address of the node which need to be retried in "
                                   + self.result_file, self.result_file)

            for group in host_group_list:
                if 0 == len(group.replace('\n', '')):
                    logger.info("There is no host.")
                    continue
                host_ips = group.replace('\n', '').split(",")

                ebackup_upgrade = eBackupUpgrader(host_ips, self.__db_param_dict, "datamover")
                is_true = ebackup_upgrade.rollback_force()
                if not is_true:
                    logger.error("Rollback %s failed." % str(group))
                    return Message(500, error_msg_cn="回退Datamover[%s]失败，请联系华为技术工程师" % str(group),
                                   error_msg_en="Rollback eBackup Datamover[%s]failed,"
                                                "please contact huawei technical engineers." % str(group))

            return self.execute(project_id, pod_id, regionid_list)
        except FCUException as ex:
            logger.error("Exception occurs when retry to upgrade eBackup: " + str(ex))
            return Message(500, ex)
        except Exception as e:
            logger.error("Exception occurs when retry to upgrade eBackup: " + str(e))
            return Message(500, error_msg_cn="重试出现异常，请联系华为技术工程师",
                           error_msg_en="Exception occurs when retry to upgrade eBackup,"
                                        "please contact huawei technical engineers")


class WorkflowUpgrade(StepBaseInterface):
    def __init__(self, project_id, pod_id, regionid_list):
        super(WorkflowUpgrade, self).__init__(project_id, pod_id, regionid_list)
        self.project_id = project_id
        self.pod_id = pod_id
        self.database = BaseOps()
        self.regionid_list = regionid_list
        self.__db_param_dict = Utils.init_system_params(project_id, regionid_list[0])
        self.result_file = os.path.abspath(__file__ + '/../{}_workflow_upgrade_result.txt'.format(regionid_list[0]))

    def execute(self, project_id, pod_id, regionid_list):
        region_type = self.database.get_region_type(self.project_id)
        logger.info("The network type is %s" % region_type)
        try:
            host_info = self.__db_param_dict["eBackup_Workflow_nodes"]
            host_info = host_info.replace(" ", "").split("|")

            all_result = []
            with open(self.result_file, mode='w') as fp:
                fp.truncate()

            logger.info("Begin to upgrade all workflow nodes(%s)" % str(host_info))
            for group in host_info:
                host_ips = group.split(";")
                logger.info("Begin to upgrade workflow nodes(%s)" % str(host_ips))
                ebackup_upgrade = eBackupUpgrader(host_ips, self.__db_param_dict, "workflow")
                is_true = ebackup_upgrade.upgrade()
                if is_true:
                    logger.info("Upgrade eBackup workflow(%s) successfully." % str(host_ips))
                else:
                    logger.error("Fail to upgrade eBackup workflow(%s)." % str(host_ips))
                    with open(self.result_file, mode='a') as fp:
                        fp.write(','.join(host_ips) + '\n')
                all_result.append(is_true)

            if False in all_result:
                logger.error("Fail to upgrade all eBackup workflow nodes.")
                return Message(500, error_msg_cn="升级Workflow失败，请登录DMK查看失败原因，请勿直接重试",
                               error_msg_en="Upgrade Workflow failed, please log in DMK to see the details,"
                                            " do not directly retry")
            if region_type.lower() != "type1":
                common_config = CommonConfig(self.__db_param_dict)
                common_config.config("FspScene")

            logger.info("Upgrade all eBackup workflow successfully.")
            if os.path.exists(self.result_file):
                os.remove(self.result_file)
            return Message(200)

        except Exception as ex:
            logger.error(str(ex))
            return Message(500, error_msg_cn="升级Workflow出现异常，请勿直接重试：{}".format(str(ex)),
                           error_msg_en="Exception occurs when upgrade Workflow,do not directly retry:{}".format(str(ex)))

    def rollback(self, project_id, pod_id, regionid_list):
        return Message(200)

    def retry(self, project_id, pod_id, regionid_list):
        try:
            if not os.path.exists(self.result_file):
                logger.error("There is no result file:" + self.result_file)
                raise FCUException(650032, self.result_file + " does not exist", self.result_file)
            with open(self.result_file, mode='r') as fp:
                host_group_list = fp.readlines()

            if 0 == len(host_group_list):
                logger.error("Get ips from {} failed.".format(self.result_file))
                raise FCUException(650032, "There is no IP address of the node which need to be retried in "
                                   + self.result_file, self.result_file)

            for group in host_group_list:
                if 0 == len(group.replace('\n', '')):
                    logger.info("There is no host.")
                    continue
                host_ips = group.replace('\n', '').split(",")
                ebackup_upgrade = eBackupUpgrader(host_ips, self.__db_param_dict, "workflow")
                is_true = ebackup_upgrade.rollback_force()
                if not is_true:
                    logger.error("Rollback %s failed." % str(group))
                    return Message(500, error_msg_cn="回退workflow[%s]失败，请联系华为技术工程师" % str(group),
                                   error_msg_en="Rollback eBackup 回退workflow[%s]failed,"
                                                "please contact huawei technical engineers." % str(group))

            return self.execute(project_id, pod_id, regionid_list)
        except FCUException as ex:
            logger.error("Exception occurs when retry to upgrade eBackup: " + str(ex))
            return Message(500, ex)
        except Exception as e:
            logger.error("Exception occurs when retry to upgrade eBackup: " + str(e))
            return Message(500, error_msg_cn="重试出现异常，请联系华为技术工程师",
                           error_msg_en="Exception occurs when retry to upgrade "
                                        "eBackup,please contact huawei technical engineers")


class DriverUpgrade(StepBaseInterface):
    def __init__(self, project_id, pod_id, regionid_list):
        super(DriverUpgrade, self).__init__(project_id, pod_id, regionid_list)
        self.project_id = project_id
        self.pod_id = pod_id
        self.regionid_list = regionid_list
        self.region_id = regionid_list[0]
        self.database = BaseOps()
        self.__db_param_dict = Utils.init_system_params(project_id, regionid_list[0])
        self.__ssh = Ssh()

    def _execute_upgrade(self, reverse_proxy_ip):
        try:
            driver_upgrade = eBackupDriverUpgrader(reverse_proxy_ip, self.__db_param_dict)
            upgrade_result = driver_upgrade.upgrade()

            return upgrade_result
        except Exception as ex:
            logger.error(str(ex))
            return False

    def execute(self, project_id, pod_id, regionid_list):
        region_type = self.database.get_region_type(self.project_id)
        logger.info("The network type is %s" % region_type)
        if region_type.lower() == "type1":
            try:
                cascaded_reverse_ips = get_cascaded_reverse_ips(self.__db_param_dict)
                if 0 == len(cascaded_reverse_ips):
                    logger.error("Fail to get reverse proxy ips of the cascaded layers.")
                    raise Exception("Fail to get reverse proxy ips of the cascaded layers.")

                all_cascaded_result = []
                for each_reverse_ip in cascaded_reverse_ips:
                    logger.info("Begin to upgrade the cascaded layer %s" % each_reverse_ip)
                    is_true = self._execute_upgrade(each_reverse_ip)
                    if is_true:
                        logger.info("Upgrade eBackup driver successfully in the cascaded layer(%s)" % each_reverse_ip)
                    else:
                        logger.error("Fail to upgrade eBackup driver in the cascaded layer(%s)" % each_reverse_ip)
                    all_cascaded_result.append(is_true)

                if False in all_cascaded_result:
                    logger.error("Fail to upgrade eBackup driver in the all cascaded layer")
                    return Message(500, "Fail to upgrade all cascaded layer")

                logger.info("Upgrade eBackup driver in the all cascaded layer successfully.")
                return Message(200)

            except Exception as ex:
                logger.error(str(ex))
                return Message(500, str(ex), str(ex))
        else:
            try:
                reverse_proxy_ip = self.__db_param_dict['openstack_reverse_proxy_ip']
                if reverse_proxy_ip is None:
                    logger.info("openstack_reverse_proxy_ip is None,eBackup driver upgrade skipped...")
                    return Message(200)
                is_true = self._execute_upgrade(reverse_proxy_ip)
                if not is_true:
                    logger.info("Fail to Upgrade eBackup driver.")
                    return Message(500, "Fail to Upgrade eBackup driver.")
                return Message(200)

            except Exception as ex:
                logger.error(str(ex))
                return Message(500, str(ex), str(ex))

    def rollback(self, project_id, pod_id, regionid_list):
        return Message(200)

    def retry(self, project_id, pod_id, regionid_list):
        return self.execute(project_id, pod_id, regionid_list)


class ConfigeBackup(StepBaseInterface):
    def __init__(self, project_id, pod_id, regionid_list):
        super(ConfigeBackup, self).__init__(project_id, pod_id, regionid_list)
        self.project_id = project_id
        self.pod_id = pod_id
        self.regionid_list = regionid_list
        self.__db_param_dict = Utils.init_system_params(project_id, regionid_list[0])

    def execute(self, project_id, pod_id, regionid_list):
        try:
            configer = CommonConfig(self.__db_param_dict)
            all_result = []
            error_msg = {
                'msg_en': {},
                'msg_cn': {}
            }
            # set workflow
            workflow_hosts_list = self.__db_param_dict["eBackup_Workflow_nodes"].split(";")
            web_ip = Utils.find_float_ip(workflow_hosts_list, self.__db_param_dict["eBackup_hcp_pwd"],
                                         self.__db_param_dict["eBackup_root_pwd"])
            logger.info("Begin to config operation log reporting info on web[https://%s:8088]" % web_ip)
            is_true = configer.config_operation_log_reporting(web_ip)
            all_result.append(is_true)
            if not is_true:
                logger.error("Config operation log reporting failed for workflow nodes[%s]." % str(workflow_hosts_list))
                error_msg['msg_cn'].update({'[Step1]' + web_ip: '设置操作日志上报到ManageOne失败'})
                error_msg['msg_en'].update({'[Step1]' + web_ip: 'Setting operation logs reporting to ManageOne failed'})
            else:
                logger.info("Config operation log reporting successfully for workflow nodes[%s]."
                            % str(workflow_hosts_list))

            logger.info("Begin to set cert for workflow nodes[%s],the float ip is %s"
                        % (str(workflow_hosts_list), web_ip))
            is_true = configer.set_cert(web_ip)
            all_result.append(is_true)
            if not is_true:
                logger.error("Set cert failed for workflow nodes[%s]." % str(workflow_hosts_list))
                error_msg['msg_cn'].update({'[Step2]' + web_ip: 'workflow对接ManageOne统一证书管理失败'})
                error_msg['msg_en'].update({'[Step2]' + web_ip: 'Set ManageOne unified certificate management '
                                                                'failed on workflow'})
            else:
                logger.info("Set cert successfully for workflow nodes[%s]." % str(workflow_hosts_list))

            # workflow set Openstack info
            solution, version = ProjectApi.get_solution_and_version(self.project_id)
            logger.info("The solution name is:" + str(solution))
            if solution == "HUAWEI CLOUD Stack":
                logger.info("Begin to config Openstack info on web[https://%s:8088]" % web_ip)
                is_true = configer.config_openstack_info(web_ip)
                all_result.append(is_true)
                if not is_true:
                    logger.error("Config Openstack failed for workflow nodes[%s]." % str(workflow_hosts_list))
                    error_msg['msg_cn'].update({'[Step3]' + web_ip: '配置OpenStack信息失败'})
                    error_msg['msg_en'].update({'[Step3]' + web_ip: 'Set OpenStack info failed'})
                else:
                    logger.info("Config Openstack successfully for workflow nodes[%s]." % str(workflow_hosts_list))
            else:
                logger.info("The solution is not HCS,skip to config Openstack info on workflow.")
            # workflow set alarm info
            logger.info("Begin to config OC alarm info on web[https://%s:8088]" % web_ip)
            is_true = configer.config_alarm_info(web_ip)
            all_result.append(is_true)
            if not is_true:
                logger.error("Config OC alarm failed for workflow nodes[%s] failed." % str(workflow_hosts_list))
                error_msg['msg_cn'].update({'[Step4]' + web_ip: '修改告警上报URL为域名失败'})
                error_msg['msg_en'].update({'[Step4]' + web_ip: 'Modify the alarm URL as the domain name failed.'})
            else:
                logger.info("Config OC alarm successfully for workflow nodes[%s] successfully."
                            % str(workflow_hosts_list))
            # query oc alarm base url
            manageone_oc_base_url = Utils.query_alarm_info(web_ip, self.__db_param_dict['eBackup_admin_pwd'])
            if len(manageone_oc_base_url) == 0:
                logger.error("Query alarm info failed.")
                raise Exception("Query alarm info failed.")
            # set unified backup for workflow
            is_true = configer.set_unified_backup(web_ip, manageone_oc_base_url + ':26335')
            if not is_true:
                logger.error("set unified backup for workflow nodes {} failed.".format(workflow_hosts_list))
                error_msg['msg_cn'].update({'[Step5]' + web_ip: 'Workflow对接ManageOne统一管理数据备份失败'})
                error_msg['msg_en'].update({'[Step5]' + web_ip: 'Config ManageOne Unified Management Data Backup'
                                                                ' Failed on workflow'})
            else:
                logger.info("set unified backup for workflow nodes {} successfully.".format(workflow_hosts_list))
            all_result.append(is_true)

            # datamover set cert
            datamover_host_group = self.__db_param_dict["eBackup_Datamover_nodes"].replace(" ", "").split("|")
            for datamover_hosts in datamover_host_group:
                host_list = datamover_hosts.split(";")
                web_ip = Utils.find_float_ip(host_list, self.__db_param_dict["eBackup_hcp_pwd"],
                                             self.__db_param_dict["eBackup_root_pwd"])
                logger.info("Begin to config manager address on server.")
                is_true = configer.config_manager_address_on_server(web_ip)
                all_result.append(is_true)
                if not is_true:
                    logger.error("Config manager address on server failed.Set cert will be skipped on [%s]" % web_ip)
                    error_msg['msg_cn'].update({'[Step6]' + web_ip: '设置Manager地址到datamover失败'})
                    error_msg['msg_en'].update({'[Step6]' + web_ip: 'Setting Manager address to datamover failed'})
                    continue
                logger.info("Config manager address on server successfully on [%s]." % web_ip)
                logger.info("Begin to set cert for datamover nodes[%s],the float ip is %s"
                            % (str(datamover_hosts), web_ip))
                is_true = configer.set_cert(web_ip)
                all_result.append(is_true)
                if not is_true:
                    logger.error("Set cert failed for datamover nodes[%s]." % str(datamover_hosts))
                    error_msg['msg_cn'].update({'[Step7]' + web_ip: 'Datamover对接ManageOne统一证书管理失败'})
                    error_msg['msg_en'].update({'[Step7]' + web_ip: 'Set ManageOne unified certificate management'
                                                                    ' failed on datamover'})
                else:
                    logger.info("Set cert successfully for datamover nodes[%s]." % str(datamover_hosts))
                logger.info("Begin to set unified backup for datamover nodes {}.".format(datamover_hosts))
                is_ture = configer.set_unified_backup(web_ip, manageone_oc_base_url + ':26335')
                if not is_ture:
                    logger.error("set unified backup for datamover nodes {} failed.".format(datamover_hosts))
                    error_msg['msg_cn'].update({'[Step8]' + web_ip: 'Datamover对接ManageOne统一管理数据备份失败'})
                    error_msg['msg_en'].update({'[Step8]' + web_ip: 'Config ManageOne Unified Management Data Backup'
                                                                    ' Failed on datamover'})
                else:
                    logger.info("set unified backup for datamover nodes {} successfully.".format(datamover_hosts))
                all_result.append(is_ture)
            if False in all_result:
                return Message(500, error_msg_cn=str(error_msg['msg_cn']), error_msg_en=str(error_msg['msg_en']))
            logger.info("Config eBackup successfully.")
            return Message(200)

        except Exception as e:
            logger.error(str(e))
            return Message(500, str(e), str(e))

    def rollback(self, project_id, pod_id, regionid_list):
        return Message(200)

    def retry(self, project_id, pod_id, regionid_list):
        return self.execute(project_id, pod_id, regionid_list)


class UpdateVM(StepBaseInterface):
    def __init__(self, project_id, pod_id, regionid_list):
        super(UpdateVM, self).__init__(project_id, pod_id, regionid_list)
        self.project_id = project_id
        self.pod_id = pod_id
        self.regionid_list = regionid_list
        self.__db_param_dict = Utils.init_system_params(project_id, regionid_list[0])

    def execute(self, project_id, pod_id, regionid_list):
        try:
            config = CommonConfig(self.__db_param_dict)
            is_true = config.update_server_info()
            if not is_true:
                logger.error("Update VMs name failed.")
                return Message(500, error_msg_cn="更新Manager&Workflow虚拟机名称失败",
                               error_msg_en="Failed to update Manager&Workflow VMs name")
            logger.info("Update VMs name success.")
            return Message(200)
        except Exception as e:
            logger.error(str(e))
            return Message(500, error_msg_cn="更新Manager&Workflow虚拟机名称出现异常：{}".format(str(e)),
                           error_msg_en="Exception occurs when update Manager&Workflow VMs name:{}".format(str(e)))

    def rollback(self, project_id, pod_id, regionid_list):
        return Message(200)

    def retry(self, project_id, pod_id, regionid_list):
        return self.execute(project_id, pod_id, regionid_list)


class UpdateCMDB(StepBaseInterface):
    def __init__(self, project_id, pod_id, regionid_list):
        super(UpdateCMDB, self).__init__(project_id, pod_id, regionid_list)
        self.project_id = project_id
        self.pod_id = pod_id
        self.regionid_list = regionid_list
        self.param_dict = Utils.init_system_params(project_id, regionid_list[0])
        self.cmdb_util = ManageOneCmdbUtil(project_id)

    def execute(self, project_id, pod_id, regionid_list):
        try:
            logger.info("Begin to register eBackup info to CMDB.")
            datamover_hosts = self.param_dict["eBackup_Datamover_nodes"]
            ebackup_workflow_ips = self.param_dict["eBackup_Workflow_nodes"].split(';')
            index_name = 'eBackup'
            current_version = self.param_dict['eBackup_Version']

            ebackup_workflow_info = {
                "indexName": index_name,
                "version": current_version,
                "name": "workflow_service" + '_' + self.param_dict['current_region_id'],
                "deployNodeInfos":[
                    {
                        "name": "eBackup-Manager",
                        "ipAddresses": [{"ip": ebackup_workflow_ips[0]}]
                    },
                    {
                        "name": "eBackup-Workflow",
                        "ipAddresses": [{"ip": ebackup_workflow_ips[1]}]
                    }
                ]
            }
            logger.info("The workflow registration info is:" + str(ebackup_workflow_info))
            self.cmdb_util.set_cloud_service_info(self.param_dict['current_region_id'], ebackup_workflow_info)
            datamover_index = 1
            for index, group in enumerate(datamover_hosts.split('|')):
                ebackup_datamover_ips = group.split(';')
                datamover_group_name = "eBackup_service" + str(index + 1) + '_' + self.param_dict['current_region_id']
                ebackup_datamover_info = {
                    "indexName": index_name,
                    "version": current_version,
                    "name": datamover_group_name,
                    "deployNodeInfos": []
                }

                for ip in ebackup_datamover_ips:
                    node_name = "eBackup_service" + str(index + 1) + "_node" + str(datamover_index)
                    node_info = {
                        "name": node_name,
                        "ipAddresses": [{"ip": ip}]
                    }
                    ebackup_datamover_info["deployNodeInfos"].append(node_info)
                    datamover_index += 1
                logger.info("The datamover group %s registration info is: %s"
                            % (str(index+1), str(ebackup_datamover_info)))
                self.cmdb_util.set_cloud_service_info(self.param_dict['current_region_id'], ebackup_datamover_info)

            # logger.info("Begin to check the register info.")
            # get_deploy_info_from_cmdb(self.project_id, self.param_dict['current_region_id'])
            logger.info("Register deploy node info to CMDB completed.")

            return Message(200)
        except FCUException as ex:
            logger.error(str(ex))
            return Message(500, ex)
        except Exception as e:
            return Message(500, error_msg_cn="更新eBackup CMDB信息出现异常：{}".format(str(e)),
                           error_msg_en="Exception occurs when update eBackup info in CMDB:{}".format(str(e)))

    def rollback(self, project_id, pod_id, regionid_list):
        return Message(200)

    def retry(self, project_id, pod_id, regionid_list):
        return self.execute(project_id, pod_id, regionid_list)


class SpecialOperation(StepBaseInterface):
    def __init__(self, project_id, pod_id, regionid_list):
        super(SpecialOperation, self).__init__(project_id, pod_id, regionid_list)
        self.project_id = project_id
        self.pod_id = pod_id
        self.regionid_list = regionid_list
        self.param_dict = Utils.init_system_params(project_id, regionid_list[0])

    def execute(self, project_id, pod_id, regionid_list):
        try:
            logger.info("Begin to config eBackup.")
            manageone_oc_base_url = ""

            all_result = []
            workflow_nodes = self.param_dict['eBackup_Workflow_nodes'].split(';')
            workflow_float_ip = Utils.find_float_ip(workflow_nodes, self.param_dict["eBackup_hcp_pwd"],
                                                    self.param_dict["eBackup_root_pwd"])
            manageone_oc_base_url = Utils.query_alarm_info(workflow_float_ip, self.param_dict['eBackup_admin_pwd'])
            if len(manageone_oc_base_url) == 0:
                logger.error("Query alarm info failed.")
                raise Exception("Query alarm info failed.")
            logger.info("Begin to set unified backup on workflow nodes {}".format(workflow_nodes))
            configer = CommonConfig(self.param_dict)
            is_ture = configer.set_unified_backup(workflow_float_ip, manageone_oc_base_url + ':26335')
            if not is_ture:
                logger.error("set unified backup for workflow nodes {} failed.".format(workflow_nodes))
            else:
                logger.info("set unified backup for workflow nodes {} successfully.".format(workflow_nodes))
            all_result.append(is_ture)

            datamover_host_group = self.param_dict["eBackup_Datamover_nodes"].replace(" ", "").split("|")
            for datamover_hosts in datamover_host_group:
                host_list = datamover_hosts.split(";")
                web_ip = Utils.find_float_ip(host_list, self.param_dict["eBackup_hcp_pwd"],
                                             self.param_dict["eBackup_root_pwd"])
                logger.info("Begin to set unified backup for datamover nodes {}.".format(host_list))
                is_ture = configer.set_unified_backup(web_ip, manageone_oc_base_url + ':26335')
                if not is_ture:
                    logger.error("set unified backup for datamover nodes {} failed.".format(host_list))
                else:
                    logger.info("set unified backup for datamover nodes {} successfully.".format(host_list))
                all_result.append(is_ture)

            return Message(200)

        except FCUException as ex:
            logger.error(str(ex))
            return Message(500, ex)
        except Exception as ex:
            logger.error(str(ex))
            return Message(500, error_msg_cn="配置eBackup出现异常，请联系华为技术工程师",
                           error_msg_en="Exception occurs when config eBackup,"
                                        "please contact huawei technical engineers")

    def retry(self, project_id, pod_id, regionid_list):
        return self.execute(project_id, pod_id, regionid_list)
