# coding=utf-8

from utils.common.message import Message
from utils.DBAdapter.DBConnector import BaseOps
from utils.common.exception import HCCIException
from utils.common.fic_base import StepBaseInterface
from plugins.DistributedStorage.Deploy.scripts.PreCheck.implement.Job_ExpandNode_Cache_Check import CheckPoolNodeSSD


class CheckPoolNodeSSDIntf(StepBaseInterface):
    def __init__(self, project_id, pod_id):
        super(CheckPoolNodeSSDIntf, self).__init__(project_id, pod_id)
        self.project_id = project_id
        self.pod_id = pod_id
        self.db = BaseOps()
        root_and_user_passward = self.db.get_user_input_cloud_param_by_key(
                project_id, "original_az_storagenode_password").split(",")
        fs_args = dict()
        fs_args['fsm_float_ip'] = self.db.get_user_input_cloud_param_by_key(
            self.project_id, "expansion_az_fsm_float_ip")
        fs_args['fsm_admin_password'] = self.db.get_user_input_cloud_param_by_key(
            self.project_id, "reuse_fsm_admin_passwd")
        fs_args['ex_osd_list'] = self.db.get_install_os_list_info(self.pod_id)
        fs_args['login_user'] = root_and_user_passward[2]
        fs_args['login_passwd'] = root_and_user_passward[3]
        self.implement = CheckPoolNodeSSD(project_id, pod_id, fs_args)

    def pre_check(self, project_id, pod_id):
        """
        插件内部接口：执行安装前的资源预检查，该接口由execute接口调用，工具框架不会直接调用此接口。
        :param project_id:
        :param pod_id:
        :return:Message类对象
        """
        return Message(200)

    def execute(self, project_id, pod_id):
        try:
            self.implement.procedure()
        except HCCIException as e1:
            return Message(500, e1)
        except Exception as e2:
            return Message(500, e2)
        return Message(200)

    def rollback(self, project_id, pod_id):
        """
        标准调用接口：执行回滚
        :param project_id:
        :param pod_id:
        :return:Message类对象
        """
        return Message(200)

    def retry(self, project_id, pod_id):
        """
        标准调用接口：重试
        :return: Message类对象
        """
        return self.execute(project_id, pod_id)

    def check(self, project_id, pod_id):
        """
        标准调用接口：重试
        :param project_id:
        :param pod_id:
        :return:Message类对象
        """
        return Message(200)
