Пример #1
0
    def INIT(self, request):
        self.response        = MakeResponse(msg_mds.LUN_INACTIVE_RESPONSE, request)
        self.request         = request
        self.request_body    = request.body.Extensions[msg_mds.lun_inactive_request]

        if g.is_ready == False:
            self.response.rc.retcode = msg_mds.RC_MDS_SERVICE_IS_NOT_READY
            self.response.rc.message = "MDS service is not ready"
            self.SendResponse(self.response)
            return MS_FINISH

        items = self.request_body.lun_name.split("_")
        if len(items) != 2 or items[0] != g.node_info.node_name:
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_NOT_EXIST
            self.response.rc.message = "Lun '%s' is not exist" % self.request_body.lun_name
            self.SendResponse(self.response)
            return MS_FINISH
        lun_name = items[1]

        lun_info = common.GetLunInfoByName(lun_name)
        if lun_info == None:
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_NOT_EXIST
            self.response.rc.message = "Lun %s not exist" % (self.request_body.lun_name)
            self.SendResponse(self.response)
            return MS_FINISH

        if lun_info.asm_status == "INACTIVE":
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_INACTIVE_NOT_ALLOWED
            self.response.rc.message = "Lun %s already inactive state" % self.request_body.lun_name
            self.SendResponse(self.response)
            return MS_FINISH

        if lun_info.asm_status != "ACTIVE":
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_INACTIVE_NOT_ALLOWED
            self.response.rc.message = "Lun %s not active state, please active first!" % self.request_body.lun_name
            self.SendResponse(self.response)
            return MS_FINISH

        self.database_node_list = [node_info for node_info in g.nsnode_list.nsnode_infos if node_info.sys_mode != "storage"]
        self.mds_database_request = MakeRequest(msg_mds.ASMDISK_OFFLINE_REQUEST)
        asmdisk_info = common.GetASMDiskInfoByLunName(self.request_body.lun_name)
        self.mds_database_request.body.Extensions[msg_mds.asmdisk_offline_request].asmdisk_name = asmdisk_info.asmdisk_name

        # 先向第一个计算节点发送请求
        self.request_num = 1
        return self.send_asm_request()
Пример #2
0
    def active_lun(self, params={}):
        rc = msg_pds.ResponseCode()

        time.sleep(5)
        lun_info = common.GetLunInfoByName(self.lun_name)
        if lun_info.asm_status != "INACTIVE":
            logger.run.error(
                "[Lun Active] lun %s online success, but active failed! because it not in asm group."
                % self.request_body.lun_name)
            rc.retcode = msg_mds.RC_MDS_LUN_ACTIVE_NOT_ALLOWED
            return rc, None

        self.mds_database_request = MakeRequest(msg_mds.ASMDISK_ONLINE_REQUEST)
        asmdisk_info = common.GetASMDiskInfoByLunName(
            self.request_body.lun_name)
        self.mds_database_request.body.Extensions[
            msg_mds.asmdisk_online_request].asmdisk_name = asmdisk_info.dskname

        # 先向第一个计算节点发送请求
        self.request_num = 1
        return self.send_asm_request()
Пример #3
0
    def INIT(self, request):
        self.default_timeout = 45

        self.response     = MakeResponse(msg_mds.LUN_DROP_RESPONSE, request)
        self.request      = request
        self.request_body = request.body.Extensions[msg_mds.lun_drop_request]

        if g.is_ready == False:
            self.response.rc.retcode = msg_mds.RC_MDS_SERVICE_IS_NOT_READY
            self.response.rc.message = "MDS service is not ready"
            self.SendResponse(self.response)
            return MS_FINISH
        
        items = self.request_body.lun_name.split("_")
        if len(items) != 2 or items[0] != g.node_info.node_name:
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_NOT_EXIST
            self.response.rc.message = "Lun '%s' is not exist" % self.request_body.lun_name
            self.SendResponse(self.response)
            return MS_FINISH
        self.lun_name = items[1]
        
        if self.lun_name == "lvvote" and self.request_body.force == False:
            self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS
            self.response.rc.message = "Please use params [-f] to drop lvvote lun"
            self.SendResponse(self.response)
            return MS_FINISH

        # 获取lun信息
        self.lun_info = common.GetLunInfoByName(self.lun_name)
        if self.lun_info == None:
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_NOT_EXIST
            self.response.rc.message = "Lun '%s' is not exist" % self.request_body.lun_name
            self.SendResponse(self.response)
            return MS_FINISH

        # 如果lun的状态是配置online,则禁止删除
        if self.lun_info.config_state == True:
            if not self.lun_info.HasField("asm_status") or self.lun_info.asm_status == "ONLINE":
                self.response.rc.retcode = msg_mds.RC_MDS_NOT_SUPPORT
                self.response.rc.message = "Lun %s is online state, please offline first." % self.lun_name
                self.SendResponse(self.response)
                return MS_FINISH

        # 删除offline的asmdisk,必须使用-f
        if self.lun_info.asm_status == 'INACTIVE' and not self.request_body.force:
            self.response.rc.retcode = msg_mds.RC_MDS_NOT_SUPPORT
            self.response.rc.message = "Lun %s is inactive state, please use -f."
            self.SendResponse(self.response)
            return MS_FINISH

        # 需先在计算节点删掉asm
        self.database_node_list = [node_info for node_info in g.nsnode_list.nsnode_infos if node_info.sys_mode != "storage"]
        if self.lun_info.asm_status in ['ACTIVE', 'INACTIVE']:
            self.mds_database_request = MakeRequest(msg_mds.ASMDISK_DROP_REQUEST)
            asmdisk_info = common.GetASMDiskInfoByLunName(self.request_body.lun_name)
            if self.lun_info.asm_status == 'ACTIVE':
                self.mds_database_request.body.Extensions[msg_mds.asmdisk_drop_request].asmdisk_name = asmdisk_info.asmdisk_name
            else:
                self.mds_database_request.body.Extensions[msg_mds.asmdisk_drop_request].asmdisk_name = asmdisk_info.dskname
            if self.request_body.force:
                self.mds_database_request.body.Extensions[msg_mds.asmdisk_drop_request].force = True
            rebalance_power = self.request_body.rebalance_power
            if rebalance_power:
                self.mds_database_request.body.Extensions[msg_mds.asmdisk_drop_request].rebalance_power = rebalance_power

            # 先向第一个计算节点发送请求
            self.request_num = 1
            return self.send_asm_request()
        else:
            return self.drop_lun()
Пример #4
0
    def INIT(self, request):
        self.default_timeout = 60
        self.response = MakeResponse(msg_mds.LUN_OFFLINE_RESPONSE, request)
        self.request = request
        self.request_body = request.body.Extensions[
            msg_mds.lun_offline_request]

        if g.is_ready == False:
            self.response.rc.retcode = msg_mds.RC_MDS_SERVICE_IS_NOT_READY
            self.response.rc.message = "MDS service is not ready"
            self.SendResponse(self.response)
            return MS_FINISH

        self.offline_node = None
        if self.request_body.group_uuid:
            self.offline_node = self.request_body.group_uuid

        items = self.request_body.lun_name.split("_")
        if len(items) != 2 or items[0] != g.node_info.node_name:
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_NOT_EXIST
            self.response.rc.message = "Lun '%s' is not exist" % self.request_body.lun_name
            self.SendResponse(self.response)
            return MS_FINISH
        lun_name = items[1]

        lun_info = common.GetLunInfoByName(lun_name)
        if lun_info == None:
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_NOT_EXIST
            self.response.rc.message = "Lun %s not exist" % (
                self.request_body.lun_name)
            self.SendResponse(self.response)
            return MS_FINISH

        self.lun_info = msg_pds.LunInfo()
        self.lun_info.CopyFrom(lun_info)

        if not lun_info.config_state and not self.offline_node:
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_ALREADY_OFFLINE
            self.response.rc.message = "Lun %s already offline state" % (
                self.request_body.lun_name)
            self.SendResponse(self.response)
            return MS_FINISH

        # 如果是faulty状态,并且在asm中,则不能offline
        lun_faulty = self.check_lun_state_faulty(self.lun_info)
        if lun_faulty and lun_info.asm_status != "ONLINE":
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_USED_IN_ASM
            self.response.rc.message = "Lun '%s' is used in asm" % (
                self.request_body.lun_name)
            self.SendResponse(self.response)
            return MS_FINISH

        # 在offline之前 需要计算节点将磁盘offline掉
        self.database_node_list = [
            node_info for node_info in g.nsnode_list.nsnode_infos
            if node_info.sys_mode != "storage"
        ]
        if lun_info.asm_status == "ACTIVE":
            self.mds_database_request = MakeRequest(
                msg_mds.ASMDISK_OFFLINE_REQUEST)
            asmdisk_info = common.GetASMDiskInfoByLunName(
                self.request_body.lun_name)
            self.mds_database_request.body.Extensions[
                msg_mds.
                asmdisk_offline_request].asmdisk_name = asmdisk_info.asmdisk_name

            # 先向第一个计算节点发送请求
            self.request_num = 1
            return self.send_asm_request()
        else:
            return self.Entry_LunOffline(None)
Пример #5
0
    def INIT(self, request):
        self.default_timeout = 20
        self.response = MakeResponse(msg_mds.LUN_ACTIVE_RESPONSE, request)
        self.request = request
        self.request_body = request.body.Extensions[msg_mds.lun_active_request]

        if g.is_ready == False:
            self.response.rc.retcode = msg_mds.RC_MDS_SERVICE_IS_NOT_READY
            self.response.rc.message = "MDS service is not ready"
            self.SendResponse(self.response)
            return MS_FINISH

        items = self.request_body.lun_name.split("_")
        if len(items) != 2 or items[0] != g.node_info.node_name:
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_NOT_EXIST
            self.response.rc.message = "Lun '%s' is not exist" % self.request_body.lun_name
            self.SendResponse(self.response)
            return MS_FINISH
        self.lun_name = items[1]

        self.lun_info = common.GetLunInfoByName(self.lun_name)
        if self.lun_info == None:
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_NOT_EXIST
            self.response.rc.message = "Lun %s not exist" % (
                self.request_body.lun_name)
            self.SendResponse(self.response)
            return MS_FINISH

        if self.lun_info.asm_status == "ACTIVE":
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_ACTIVE_NOT_ALLOWED
            self.response.rc.message = "Lun %s already active state" % self.request_body.lun_name
            self.SendResponse(self.response)
            return MS_FINISH

        if self.lun_info.config_state == True and self.lun_info.asm_status == "ONLINE":
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_ACTIVE_NOT_ALLOWED
            self.response.rc.message = "Lun %s not in asm group, please add to group first!" % self.request_body.lun_name
            self.SendResponse(self.response)
            return MS_FINISH

        self.database_node_list = [
            node_info for node_info in g.nsnode_list.nsnode_infos
            if node_info.sys_mode != "storage"
        ]
        if self.lun_info.asm_status == "INACTIVE":
            self.mds_database_request = MakeRequest(
                msg_mds.ASMDISK_ONLINE_REQUEST)
            asmdisk_info = common.GetASMDiskInfoByLunName(
                self.request_body.lun_name)
            self.mds_database_request.body.Extensions[
                msg_mds.
                asmdisk_online_request].asmdisk_name = asmdisk_info.dskname

            # 先向第一个计算节点发送请求
            self.request_num = 1
            return self.send_asm_request()
        elif self.lun_info.config_state == False:
            self.LongWork(self.online_lun, {})

            self.response.rc.retcode = msg_pds.RC_SUCCESS
            self.SendResponse(self.response)
            return MS_FINISH
        else:
            self.response.rc.retcode = msg_mds.RC_MDS_NOT_SUPPORT
            self.response.rc.message = "Lun active only support lun state is inactive or offline"
            self.SendResponse(self.response)
            return MS_FINISH