def CreateLunMetaData(self): lun_info = msg_pds.LunInfo() lun_info.lun_id = self.ios_request_body.lun_id lun_info.lun_name = self.ios_request_body.lun_name lun_info.lun_type = self.ios_request_body.lun_type lun_info.config_state = True lun_info.actual_state = True lun_info.last_heartbeat_time = int(time.time()) if self.group_uuid: for k in self.group_uuid: info = lun_info.group_info.add() info.group_uuid = k info.group_state = 1 lun_info.group_name.extend([self.request_body.group_name]) if lun_info.lun_type == msg_pds.LUN_TYPE_SMARTCACHE: smartcache_id = self.ios_request_body.Extensions[ msg_ios.ext_lunaddrequest_smartcache].smartcache_id lun_info.Extensions[ msg_pds.ext_luninfo_smartcache_id] = smartcache_id elif lun_info.lun_type == msg_pds.LUN_TYPE_BASEDISK: basedisk_id = self.ios_request_body.Extensions[ msg_ios.ext_lunaddrequest_basedisk].basedisk_id lun_info.Extensions[msg_pds.ext_luninfo_basedisk_id] = basedisk_id elif lun_info.lun_type == msg_pds.LUN_TYPE_PALCACHE: palcache_id = self.ios_request_body.Extensions[ msg_ios.ext_lunaddrequest_palcache].palcache_id lun_info.Extensions[msg_pds.ext_luninfo_palcache_id] = palcache_id elif lun_info.lun_type == msg_pds.LUN_TYPE_PALRAW: palraw_id = self.ios_request_body.Extensions[ msg_ios.ext_lunaddrequest_palraw].palraw_id lun_info.Extensions[msg_pds.ext_luninfo_palraw_id] = palraw_id elif lun_info.lun_type == msg_pds.LUN_TYPE_PALPMT: palpmt_id = self.ios_request_body.Extensions[ msg_ios.ext_lunaddrequest_palpmt].palpmt_id lun_info.Extensions[msg_pds.ext_luninfo_palpmt_id] = palpmt_id elif lun_info.lun_type == msg_pds.LUN_TYPE_BASEDEV: basedev_id = self.ios_request_body.Extensions[ msg_ios.ext_lunaddrequest_basedev].basedev_id lun_info.Extensions[msg_pds.ext_luninfo_basedev_id] = basedev_id # 将lun配置信息持久化 data = pb2dict_proxy.pb2dict("lun_info", lun_info) e, _ = dbservice.srv.create("/lun/%s" % lun_info.lun_id, data) if e: logger.run.error("Create 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列表 g.lun_list.lun_infos.add().CopyFrom(lun_info) self.response.rc.retcode = msg_pds.RC_SUCCESS self.SendResponse(self.response) return MS_FINISH
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
def Entry_OfflineLun(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 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) lun_info = msg_pds.LunInfo() lun_info.CopyFrom(self.lun_info) if self.del_groups: for info in lun_info.group_info: group = msg_pds.GroupInfo() if info.group_uuid in self.del_groups: self.lun_info.group_info.remove(info) if self.del_common_groups: for info in self.lun_info.group_info: if info.group_uuid in self.del_common_groups: info.group_state -= 1 if not ios: if len(self.lun_info.group_info) == 0: self.lun_info.config_state = False self.lun_info.ClearExtension(msg_mds.ext_luninfo_lun_export_info) else: self.lun_info.config_state = True self.lun_info.group_name.remove(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
def lun_info(self, is_to_pb, data): if is_to_pb: lun_info = msg_pds.LunInfo() lun_info.lun_name = data['lun_name'] lun_info.lun_id = data['lun_id'] lun_info.lun_type = data['lun_type'] lun_info.config_state = data['config_state'] if data.has_key('qos_template_id'): lun_info.qos_template_id = data['qos_template_id'] if data.has_key('qos_template_name'): lun_info.qos_template_name = data['qos_template_name'] if data.has_key('qos_template_name'): lun_info.qos_template_name = data['qos_template_name'] if data.has_key('ext_luninfo_basedisk_id'): lun_info.Extensions[msg_pds.ext_luninfo_basedisk_id] = data[ 'ext_luninfo_basedisk_id'] if data.has_key('ext_luninfo_basedev_id'): lun_info.Extensions[msg_pds.ext_luninfo_basedev_id] = data[ 'ext_luninfo_basedev_id'] if data.has_key('ext_luninfo_smartcache_id'): lun_info.Extensions[msg_pds.ext_luninfo_smartcache_id] = data[ 'ext_luninfo_smartcache_id'] if data.has_key('ext_luninfo_palcache_id'): lun_info.Extensions[msg_pds.ext_luninfo_palcache_id] = data[ 'ext_luninfo_palcache_id'] if data.has_key('ext_luninfo_palraw_id'): lun_info.Extensions[msg_pds.ext_luninfo_palraw_id] = data[ 'ext_luninfo_palraw_id'] if data.has_key('ext_luninfo_palpmt_id'): lun_info.Extensions[msg_pds.ext_luninfo_palpmt_id] = data[ 'ext_luninfo_palpmt_id'] if data.has_key('group_info'): for k in data["group_info"].keys(): info = lun_info.group_info.add() info.group_uuid = k info.group_state = data["group_info"][k]["group_state"] if data.has_key('group_name'): lun_info.group_name.extend(data["group_name"]) return lun_info else: lun_info = {} lun_info['lun_name'] = data.lun_name lun_info['lun_id'] = data.lun_id lun_info['lun_type'] = data.lun_type lun_info['config_state'] = data.config_state lun_info['group_info'] = {} for info in data.group_info: lun_info['group_info'][info.group_uuid] = {} lun_info['group_info'][ info.group_uuid]["group_state"] = info.group_state lun_info["group_name"] = [] for i in data.group_name: lun_info["group_name"].append(i) lun_info['qos_template_id'] = data.qos_template_id lun_info['qos_template_name'] = data.qos_template_name if data.HasExtension(msg_pds.ext_luninfo_basedev_id): lun_info['ext_luninfo_basedev_id'] = data.Extensions[ msg_pds.ext_luninfo_basedev_id] if data.HasExtension(msg_pds.ext_luninfo_basedisk_id): lun_info['ext_luninfo_basedisk_id'] = data.Extensions[ msg_pds.ext_luninfo_basedisk_id] if data.HasExtension(msg_pds.ext_luninfo_smartcache_id): lun_info['ext_luninfo_smartcache_id'] = data.Extensions[ msg_pds.ext_luninfo_smartcache_id] if data.HasExtension(msg_pds.ext_luninfo_palcache_id): lun_info['ext_luninfo_palcache_id'] = data.Extensions[ msg_pds.ext_luninfo_palcache_id] if data.HasExtension(msg_pds.ext_luninfo_palraw_id): lun_info['ext_luninfo_palraw_id'] = data.Extensions[ msg_pds.ext_luninfo_palraw_id] if data.HasExtension(msg_pds.ext_luninfo_palpmt_id): lun_info['ext_luninfo_palpmt_id'] = data.Extensions[ msg_pds.ext_luninfo_palpmt_id] return lun_info
# -*- coding: utf-8 -* # vim: tabstop=4 shiftwidth=4 softtabstop=4 import sys, os, time, json sys.path.append(os.path.abspath(os.path.join(__file__, '../../'))) from pdsframe.common.config import init_config, config init_config('../files/conf/test/service.mds.215.ini') import message.pds_pb2 as msg_pds import message.mds_pb2 as msg_mds if __name__ == "__main__": lun_info = msg_pds.LunInfo() lun_info.lun_name = "name" lun_export_info = msg_pds.LunExportInfo() lun_export_info.lun_name = "xx" lun_info.Extensions[msg_mds.ext_luninfo_lun_export_info].CopyFrom( lun_export_info) print dir(lun_info) print lun_info lun_info.ClearExtension(msg_mds.ext_luninfo_lun_export_info) print lun_info # print lun_info.HasExtension(msg_pds.ext_luninfo_basedisk_id) # print dir(lun_info) # disk_info = msg_pds.DiskInfo() # disk_info.dev_name = "/dev/x"
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)
def INIT(self, request): self.response = MakeResponse(msg_mds.GET_LUN_LIST_RESPONSE, request) self.request = request self.request_body = request.body.Extensions[ msg_mds.get_lun_list_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.qos_name = "" if self.request_body.HasField("qos_name"): self.qos_name = self.request_body.qos_name self.qos_template_info = common.GetQosTemplateInfoByName( self.qos_name) if not self.qos_template_info: self.response.rc.retcode = msg_mds.RC_MDS_QOS_TEMPLATE_NOT_EXIST self.response.rc.message = "QoS '%s' is not exist" % self.qos_name self.SendResponse(self.response) return MS_FINISH self.group_name = "" if self.request_body.HasField("group_name"): self.group_name = self.request_body.group_name error, self.group_info = common.GetGroupInfoFromName( self.group_name) if error: self.response.rc.retcode = msg_mds.RC_MDS_GROUP_FIND_FAIL self.response.rc.message = "Not found group %s" % self.group_name self.SendResponse(self.response) return MS_FINISH for _lun_info in g.lun_list.lun_infos: # 过滤指定qos下的lun if self.qos_name and _lun_info.qos_template_name != self.qos_name: continue if self.group_name and self.group_name not in _lun_info.group_name: continue lun_info = msg_pds.LunInfo() lun_info.CopyFrom(_lun_info) for group in lun_info.group_info: error, index = common.GetIndexFromUUID(group.group_uuid) if not error: lun_info.node_index.extend([index]) if lun_info.lun_type == msg_pds.LUN_TYPE_BASEDISK: basedisk_info = common.GetBaseDiskInfoById( lun_info.Extensions[msg_pds.ext_luninfo_basedisk_id]) data_disk_info = common.GetDiskInfoByID(basedisk_info.disk_id) data_part_info = common.GetDiskPartByID( basedisk_info.disk_id, basedisk_info.disk_part) lun_info.Extensions[ msg_mds.ext_luninfo_size] = data_part_info.size lun_info.Extensions[msg_mds.ext_luninfo_scsiid] = "xx" lun_info.Extensions[ msg_mds.ext_luninfo_node_name] = g.node_info.node_name lun_info.Extensions[ msg_mds. ext_luninfo_data_dev_name] = data_part_info.dev_name lun_info.Extensions[ msg_mds.ext_luninfo_data_disk_name] = "%sp%s" % ( data_disk_info.disk_name, data_part_info.disk_part) lun_info.Extensions[ msg_mds. ext_luninfo_data_actual_state] = data_part_info.actual_state elif lun_info.lun_type == msg_pds.LUN_TYPE_BASEDEV: basedev_info = common.GetBaseDevInfoById( lun_info.Extensions[msg_pds.ext_luninfo_basedev_id]) lun_info.Extensions[ msg_mds.ext_luninfo_size] = basedev_info.size lun_info.Extensions[msg_mds.ext_luninfo_scsiid] = "xx" lun_info.Extensions[ msg_mds.ext_luninfo_node_name] = g.node_info.node_name lun_info.Extensions[ msg_mds.ext_luninfo_data_dev_name] = basedev_info.dev_name lun_info.Extensions[msg_mds.ext_luninfo_data_disk_name] = "" elif lun_info.lun_type == msg_pds.LUN_TYPE_SMARTCACHE: smartcache_info = common.GetSmartCacheInfoById( lun_info.Extensions[msg_pds.ext_luninfo_smartcache_id]) data_disk_info = common.GetDiskInfoByID( smartcache_info.data_disk_id) data_part_info = common.GetDiskPartByID( smartcache_info.data_disk_id, smartcache_info.data_disk_part) cache_disk_info = common.GetDiskInfoByID( smartcache_info.cache_disk_id) cache_part_info = common.GetDiskPartByID( smartcache_info.cache_disk_id, smartcache_info.cache_disk_part) lun_info.Extensions[ msg_mds.ext_luninfo_size] = data_part_info.size lun_info.Extensions[ msg_mds.ext_luninfo_cache_size] = cache_part_info.size lun_info.Extensions[msg_mds.ext_luninfo_scsiid] = "xx" lun_info.Extensions[ msg_mds.ext_luninfo_node_name] = g.node_info.node_name lun_info.Extensions[ msg_mds. ext_luninfo_data_dev_name] = data_part_info.dev_name lun_info.Extensions[ msg_mds.ext_luninfo_data_disk_name] = "%sp%s" % ( data_disk_info.disk_name, data_part_info.disk_part) lun_info.Extensions[ msg_mds.ext_luninfo_cache_disk_name] = "%sp%s" % ( cache_disk_info.disk_name, cache_part_info.disk_part) lun_info.Extensions[msg_mds.ext_luninfo_cache_dev_name].append( cache_part_info.dev_name) lun_info.Extensions[ msg_mds. ext_luninfo_data_actual_state] = data_part_info.actual_state lun_info.Extensions[ msg_mds.ext_luninfo_cache_actual_state].append( cache_part_info.actual_state) elif lun_info.lun_type == msg_pds.LUN_TYPE_PALCACHE: palcache_info = common.GetPalCacheInfoById( lun_info.Extensions[msg_pds.ext_luninfo_palcache_id]) data_disk_info = common.GetDiskInfoByID(palcache_info.disk_id) data_part_info = common.GetDiskPartByID( palcache_info.disk_id, palcache_info.disk_part) pool_info = common.GetPoolInfoById(palcache_info.pool_id) pool_disk = common.GetDiskInfoByID( pool_info.pool_disk_infos[0].disk_id) pool_part = common.GetDiskPartByID( pool_info.pool_disk_infos[0].disk_id, pool_info.pool_disk_infos[0].disk_part) lun_info.Extensions[ msg_mds.ext_luninfo_size] = data_part_info.size lun_info.Extensions[ msg_mds.ext_luninfo_cache_size] = pool_part.size lun_info.Extensions[msg_mds.ext_luninfo_scsiid] = "xx" lun_info.Extensions[ msg_mds.ext_luninfo_node_name] = g.node_info.node_name lun_info.Extensions[ msg_mds. ext_luninfo_data_dev_name] = data_part_info.dev_name lun_info.Extensions[ msg_mds.ext_luninfo_data_disk_name] = "%sp%s" % ( data_disk_info.disk_name, data_part_info.disk_part) lun_info.Extensions[ msg_mds.ext_luninfo_cache_disk_name] = pool_info.pool_name lun_info.Extensions[msg_mds.ext_luninfo_cache_dev_name].append( pool_part.dev_name) if palcache_info.HasExtension( msg_mds.ext_palcache_export_info): palcache_cache_model = palcache_info.Extensions[ msg_mds.ext_palcache_export_info].palcache_cache_model lun_info.Extensions[ msg_mds. ext_luninfo_palcache_cache_model] = palcache_cache_model lun_info.Extensions[ msg_mds. ext_luninfo_data_actual_state] = data_part_info.actual_state lun_info.Extensions[ msg_mds.ext_luninfo_cache_actual_state].append( pool_part.actual_state) elif lun_info.lun_type == msg_pds.LUN_TYPE_PALRAW: palraw_info = common.GetPalRawInfoById( lun_info.Extensions[msg_pds.ext_luninfo_palraw_id]) data_disk_info = common.GetDiskInfoByID(palraw_info.disk_id) data_part_info = common.GetDiskPartByID( palraw_info.disk_id, palraw_info.disk_part) lun_info.Extensions[ msg_mds.ext_luninfo_size] = data_part_info.size lun_info.Extensions[msg_mds.ext_luninfo_scsiid] = "xx" lun_info.Extensions[ msg_mds.ext_luninfo_node_name] = g.node_info.node_name lun_info.Extensions[ msg_mds. ext_luninfo_data_dev_name] = data_part_info.dev_name lun_info.Extensions[ msg_mds.ext_luninfo_data_disk_name] = "%sp%s" % ( data_disk_info.disk_name, data_part_info.disk_part) lun_info.Extensions[ msg_mds. ext_luninfo_data_actual_state] = data_part_info.actual_state elif lun_info.lun_type == msg_pds.LUN_TYPE_PALPMT: palpmt_info = common.GetPalPmtInfoById( lun_info.Extensions[msg_pds.ext_luninfo_palpmt_id]) pool_info = common.GetPoolInfoById(palpmt_info.pool_id) data_part_info = common.GetDiskPartByID( pool_info.pool_disk_infos[0].disk_id, pool_info.pool_disk_infos[0].disk_part) lun_info.Extensions[ msg_mds.ext_luninfo_size] = palpmt_info.size lun_info.Extensions[ msg_mds.ext_luninfo_node_name] = g.node_info.node_name lun_info.Extensions[ msg_mds.ext_luninfo_data_disk_name] = pool_info.pool_name lun_info.Extensions[ msg_mds. ext_luninfo_data_dev_name] = data_part_info.dev_name lun_info.Extensions[ msg_mds. ext_luninfo_data_actual_state] = data_part_info.actual_state else: assert (0) self.response.body.Extensions[ msg_mds.get_lun_list_response].lun_infos.add().CopyFrom( lun_info) self.response.rc.retcode = msg_pds.RC_SUCCESS self.SendResponse(self.response) return MS_FINISH
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)
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)