Example #1
0
    def Entry_OfflineLun(self, response):
        if response.rc.retcode != msg_pds.RC_SUCCESS:
            self.response.rc.CopyFrom(response.rc)
            self.SendResponse(self.response)
            return MS_FINISH
        num = int(
            response.body.Extensions[msg_ios.lun_drop_response].exist_lun)
        logger.run.info("After do action offline lun export num [%s]" % num)
        if num:
            self.lun_info.config_state = True
        else:
            self.lun_info.config_state = False
            self.lun_info.ClearExtension(msg_mds.ext_luninfo_lun_export_info)

        data = pb2dict_proxy.pb2dict("lun_info", self.lun_info)
        e, _ = dbservice.srv.update("/lun/%s" % self.lun_info.lun_id, data)
        if e:
            logger.run.error("Update lun info faild %s:%s" % (e, _))
            self.response.rc.retcode = msg_mds.RC_MDS_UPDATE_DB_DATA_FAILED
            self.response.rc.message = "Keep data failed"
            self.SendResponse(self.response)
            return MS_FINISH

        lun_info = common.GetLunInfoByName(self.lun_info.lun_name)
        lun_info.CopyFrom(self.lun_info)

        self.response.rc.retcode = msg_pds.RC_SUCCESS
        self.SendResponse(self.response)
        return MS_FINISH
Example #2
0
    def Entry_OnlineLun(self, response):
        if response.rc.retcode != msg_pds.RC_SUCCESS:
            self.response.rc.CopyFrom(response.rc)
            self.SendResponse(self.response)
            return MS_FINISH

        self.lun_info.config_state = True
        self.lun_info.actual_state = True
        self.lun_info.last_heartbeat_time = int(time.time())

        data = pb2dict_proxy.pb2dict("lun_info", self.lun_info)
        e, _ = dbservice.srv.update("/lun/%s" % self.lun_info.lun_id, data)
        if e:
            logger.run.error("Update lun info faild %s:%s" % (e, _))
            self.response.rc.retcode = msg_mds.RC_MDS_UPDATE_DB_DATA_FAILED
            self.response.rc.message = "Keep data failed"
            self.SendResponse(self.response)
            return MS_FINISH

        lun_info = common.GetLunInfoByName(self.lun_info.lun_name)
        lun_info.CopyFrom(self.lun_info)

        self.response.rc.retcode = msg_pds.RC_SUCCESS
        self.SendResponse(self.response)
        return MS_FINISH
Example #3
0
    def INIT(self, request):
        self.response     = MakeResponse(msg_mds.UNLINK_QOS_TEMPLATE_RESPONSE, request)
        self.request      = request
        self.request_body = request.body.Extensions[msg_mds.unlink_qos_template_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]
    
        # 获取lun信息
        lun_info = common.GetLunInfoByName(self.lun_name)
        if lun_info == None:
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_NOT_EXIST
            self.response.rc.message = "Lun '%s' is not exist" % self.lun_name
            self.SendResponse(self.response)
            return MS_FINISH

        if lun_info.qos_template_id == "":
            self.response.rc.retcode = msg_mds.RC_MDS_LUN_NOT_LINKED
            self.response.rc.message = "Lun '%s' is not linked qos template" % self.lun_name
            self.SendResponse(self.response)
            return MS_FINISH

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

        self.lun_info.qos_template_id = ""
        self.lun_info.qos_template_name = ""
        # 将lun配置信息持久化
        data = pb2dict_proxy.pb2dict("lun_info",self.lun_info)
        e, _ = dbservice.srv.update("/lun/%s" % self.lun_info.lun_id, data)
        if e:
            logger.run.error("Update lun info faild %s:%s" % (e, _))
            self.response.rc.retcode = msg_mds.RC_MDS_CREATE_DB_DATA_FAILED
            self.response.rc.message = "Keep data failed"
            self.SendResponse(self.response)
            return MS_FINISH

        # 更新lun列表
        lun_info.CopyFrom(self.lun_info)

        self.response.rc.retcode = msg_pds.RC_SUCCESS
        self.SendResponse(self.response)
        return MS_FINISH
Example #4
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()
Example #5
0
    def rebalance_wait(self, params={}):
        rc = msg_pds.ResponseCode()
        while True:
            time.sleep(1)
            lun_info = common.GetLunInfoByName(self.lun_name)
            if lun_info.asm_status != "DROPPING":
                break

        if lun_info.asm_status == "HUNG":
            logger.run.error("Lun drop faild: asm drop filed because disk space not enough")
            rc.retcode = msg_mds.RC_MDS_LUN_DROP_FAILED
            return rc, None
        
        self.LongWork(self.offline_lun, {})

        rc.retcode = msg_pds.RC_SUCCESS
        return rc, None
Example #6
0
    def BaseDevCheck(self):
        for basedev_info in g.basedev_list.basedev_infos:
            if basedev_info.dev_name == self.request_body.Extensions[
                    msg_mds.ext_lunaddrequest_basedev].dev_name:
                self.response.rc.retcode = msg_mds.RC_MDS_LUN_ALREADY_EXIST
                self.response.rc.message = "Dev %s already exist" % basedev_info.dev_name
                self.SendResponse(self.response)
                return MS_FINISH

        dev_name = self.request_body.Extensions[
            msg_mds.ext_lunaddrequest_basedev].dev_name
        if dev_name.startswith(
                "/dev/mapper/") and dev_name.find("lvvote") != -1:
            self.lun_name = dev_name.split("-")[1]
            if common.GetLunInfoByName(self.lun_name) != None:
                self.response.rc.retcode = msg_mds.RC_MDS_LUN_ALREADY_EXIST
                self.response.rc.message = "Lun %s already exist" % self.lun_name
                self.SendResponse(self.response)
                return MS_FINISH
        return self.AddLunBaseDev()
Example #7
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()
Example #8
0
    def Entry_OnlineLun(self, response,ios=True):
        if ios:
            if response.rc.retcode != msg_pds.RC_SUCCESS:
                self.response.rc.CopyFrom(response.rc)
                self.SendResponse(self.response)
                return MS_FINISH

        self.lun_info.config_state = True
        self.lun_info.actual_state = True
        self.lun_info.last_heartbeat_time = int(time.time())
        
        if self.add_groups:
            for k in self.add_groups:
                info = self.lun_info.group_info.add()
                info.group_uuid = k
                info.group_state = 1
        if self.add_common_groups:
            for info in self.lun_info.group_info:
                if info.group_uuid in self.add_common_groups:
                    info.group_state += 1
        self.lun_info.group_name.extend([self.request_body.group_name])

        data = pb2dict_proxy.pb2dict("lun_info", self.lun_info)
        e, _ = dbservice.srv.update("/lun/%s" % self.lun_info.lun_id, data)
        if e:
            logger.run.error("Update lun info faild %s:%s" % (e, _))
            self.response.rc.retcode = msg_mds.RC_MDS_UPDATE_DB_DATA_FAILED
            self.response.rc.message = "Keep data failed"
            self.SendResponse(self.response)
            return MS_FINISH

        lun_info = common.GetLunInfoByName(self.lun_info.lun_name)
        lun_info.CopyFrom(self.lun_info)

        self.response.rc.retcode = msg_pds.RC_SUCCESS
        self.SendResponse(self.response)
        return MS_FINISH
Example #9
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()
Example #10
0
    def INIT(self, request):
        self.default_timeout = 120
        self.response        = MakeResponse(msg_mds.LUN_CONFIG_RESPONSE, request)
        self.request         = request
        self.request_body    = request.body.Extensions[msg_mds.lun_config_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

        # 如果给组参数查询组
        if self.request_body.HasField("group_name"):
            error,group_info = common.GetGroupInfoFromName(self.request_body.group_name)
            if error:
                self.response.rc.retcode = msg_mds.RC_MDS_GROUP_FIND_FAIL
                self.response.rc.message = "Not found group %s"% self.request_body.group_name
                self.SendResponse(self.response)
                return MS_FINISH

            group_uuid = group_info.node_uuids
            if not group_uuid:
               self.response.rc.retcode = msg_mds.RC_MDS_GROUP_FIND_FAIL
               self.response.rc.message = "Group %s not configure node"%self.request_body.group_name
               self.SendResponse(self.response)
               return MS_FINISH
        else:
            self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS
            self.response.rc.message = "Not specify group name"
            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
        
        self.lun_info = msg_pds.LunInfo()
        self.lun_info.CopyFrom(lun_info)

        if not self.request_body.del_group:
            if self.request_body.group_name in self.lun_info.group_name:
                self.response.rc.retcode = msg_mds.RC_MDS_GROUP_FIND_FAIL
                self.response.rc.message = "Group %s already config"%self.request_body.group_name
                self.SendResponse(self.response)
                return MS_FINISH
        else:
            if self.request_body.group_name not in self.lun_info.group_name:
                self.response.rc.retcode = msg_mds.RC_MDS_GROUP_FIND_FAIL
                self.response.rc.message = "Group %s not find in lun"%self.request_body.group_name
                self.SendResponse(self.response)
                return MS_FINISH

        exsist_groups=set()
        eqone_groups=set()
        if self.lun_info.group_info:
            for info in self.lun_info.group_info:
                exsist_groups.add(info.group_uuid)
                if info.group_state == 1:
                    eqone_groups.add(info.group_uuid)

        param_groups=set(group_uuid)
        self.add_groups = list(param_groups - exsist_groups) #独有的
        self.add_common_groups = list(param_groups & exsist_groups) #共有的
        self.del_groups = list(set(self.add_common_groups) & eqone_groups) #共有的且值为1
        self.del_common_groups = list(set(self.add_common_groups) - eqone_groups)#共有的且值不为1
        
        # 判断是添加配置还是删除配置
        if self.request_body.del_group:
            if not self.del_groups:
                self.response.rc.retcode = msg_pds.RC_SUCCESS
                return  self.Entry_OfflineLun(self.response,ios=False)
            return self.del_group(self.del_groups)
        else:
            if not self.add_groups:
                self.response.rc.retcode = msg_pds.RC_SUCCESS
                return  self.Entry_OnlineLun(self.response,ios=False)
            return self.add_group(self.add_groups)
Example #11
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)
Example #12
0
    def INIT(self, request):
        self.default_timeout = 120
        self.response = MakeResponse(msg_mds.LUN_ONLINE_RESPONSE, request)
        self.request = request
        self.request_body = request.body.Extensions[msg_mds.lun_online_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

        online_node = None
        if self.request_body.group_uuid:
            online_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)

        self.ios_request = MakeRequest(msg_ios.LUN_ADD_REQUEST, self.request)
        self.ios_request_body = self.ios_request.body.Extensions[
            msg_ios.lun_add_request]

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

        if not online_node:
            group_uuid = []
            for group in self.lun_info.group_info:
                group_uuid.append(group.group_uuid)
            if group_uuid:
                self.ios_request_body.group_name.extend(group_uuid)
            else:
                self.response.rc.retcode = msg_mds.RC_MDS_GROUP_FIND_FAIL
                self.response.rc.message = "Lun %s not configure group" % (
                    self.request_body.lun_name)
                self.SendResponse(self.response)
                return MS_FINISH
        else:
            info = self.lun_info.group_info.add()
            info.group_uuid = online_node
            info.group_state = 1
            self.ios_request_body.group_name.extend([online_node])

        g.srp_rescan_flag = True
        if self.lun_info.lun_type == msg_pds.LUN_TYPE_BASEDISK:
            return self.OnlineLunBaseDisk()
        elif self.lun_info.lun_type == msg_pds.LUN_TYPE_SMARTCACHE:
            return self.OnlineLunSmartCache()
        elif self.lun_info.lun_type == msg_pds.LUN_TYPE_PALCACHE:
            return self.OnlineLunPalCache()
        elif self.lun_info.lun_type == msg_pds.LUN_TYPE_PALRAW:
            return self.OnlineLunPalRaw()
        elif self.lun_info.lun_type == msg_pds.LUN_TYPE_PALPMT:
            return self.OnlineLunPalPmt()
        elif self.lun_info.lun_type == msg_pds.LUN_TYPE_BASEDEV:
            return self.OnlineLunBaseDev()
        else:
            assert (0)
Example #13
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