def PalRawCheck(self): data_disk_name = self.request_body.Extensions[ msg_mds.ext_lunaddrequest_palraw].data_disk_name rc, self.data_disk_info = self.check_disk_available(data_disk_name) if rc.retcode != msg_pds.RC_SUCCESS: logger.run.error("Check disk faild %s:%s" % (data_disk_name, rc.message)) self.response.rc.CopyFrom(rc) self.SendResponse(self.response) return MS_FINISH data_disk_part = common.GetDiskPartByID( self.data_disk_info.header.uuid, int(data_disk_name.split('p')[1])) # data大小不能超过2T if data_disk_part.size >= 2000 * 1024 * 1024 * 1024 / 512: self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS self.response.rc.message = "Data disk size is bigger then limit size 2000G" self.SendResponse(self.response) return MS_FINISH return self.AddLunPalRaw()
def PalCacheCheck(self): data_disk_name = self.request_body.Extensions[ msg_mds.ext_lunaddrequest_palcache].data_disk_name pool_name = self.request_body.Extensions[ msg_mds.ext_lunaddrequest_palcache].pool_name rc, self.data_disk_info = self.check_disk_available(data_disk_name) if rc.retcode != msg_pds.RC_SUCCESS: logger.run.error("Check disk faild %s:%s" % (data_disk_name, rc.message)) self.response.rc.CopyFrom(rc) self.SendResponse(self.response) return MS_FINISH data_disk_part = common.GetDiskPartByID( self.data_disk_info.header.uuid, int(data_disk_name.split('p')[1])) # data大小不能超过2T if data_disk_part.size >= 2000 * 1024 * 1024 * 1024 / 512: self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS self.response.rc.message = "Data disk size is bigger then limit size 2000G" self.SendResponse(self.response) return MS_FINISH # 磁盘类型必须是HDD if self.data_disk_info.disk_type != msg_pds.DISK_TYPE_HDD: self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS self.response.rc.message = "Only support HDD disk as data dev for pal-palcache" self.SendResponse(self.response) return MS_FINISH rc, self.pool_info = self.check_pool_available(pool_name) if rc.retcode != msg_pds.RC_SUCCESS: logger.run.error("Check pool faild %s:%s" % (pool_name, rc.message)) self.response.rc.CopyFrom(rc) self.SendResponse(self.response) return MS_FINISH return self.AddLunPalCache()
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 SmartCacheCheck(self): data_disk_name = self.request_body.Extensions[ msg_mds.ext_lunaddrequest_smartcache].data_disk_name cache_disk_name = self.request_body.Extensions[ msg_mds.ext_lunaddrequest_smartcache].cache_disk_name rc, self.data_disk_info = self.check_disk_available(data_disk_name) if rc.retcode != msg_pds.RC_SUCCESS: logger.run.error("Check disk faild %s:%s" % (data_disk_name, rc.message)) self.response.rc.CopyFrom(rc) self.SendResponse(self.response) return MS_FINISH rc, self.cache_disk_info = self.check_disk_available(cache_disk_name) if rc.retcode != msg_pds.RC_SUCCESS: logger.run.error("Check disk faild %s:%s" % (cache_disk_name, rc.message)) self.response.rc.CopyFrom(rc) self.SendResponse(self.response) return MS_FINISH # 磁盘类型必须是SSD if self.cache_disk_info.disk_type != msg_pds.DISK_TYPE_SSD: self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS self.response.rc.message = "Only support SSD disk as cache dev" self.SendResponse(self.response) return MS_FINISH data_disk_part = common.GetDiskPartByID( self.data_disk_info.header.uuid, int(data_disk_name.split('p')[1])) cache_disk_part = common.GetDiskPartByID( self.cache_disk_info.header.uuid, int(cache_disk_name.split('p')[1])) # data大小不能超过2T if data_disk_part.size >= 2000 * 1024 * 1024 * 1024 / 512: self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS self.response.rc.message = "Data disk size is bigger then limit size 2000G" self.SendResponse(self.response) return MS_FINISH # cache大小不能超过1T if cache_disk_part.size >= 1024 * 1024 * 1024 * 1024 / 512: self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS self.response.rc.message = "Cache disk size is bigger then limit size 1T" self.SendResponse(self.response) return MS_FINISH # cache大小不能超过data if cache_disk_part.size >= data_disk_part.size: self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS self.response.rc.message = "Cache disk size is bigger then data disk size" self.SendResponse(self.response) return MS_FINISH # cache和data不能在一个盘上 if self.data_disk_info.header.uuid == self.cache_disk_info.header.uuid: self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS self.response.rc.message = "Data disk and cache disk can not be on the same physical device" self.SendResponse(self.response) return MS_FINISH return self.AddLunSmartCache()
def check_lun_state_faulty(self, lun_info): if lun_info.config_state == True and lun_info.actual_state == True: if lun_info.Extensions[ msg_mds.ext_luninfo_lun_export_info].io_error != 0: return True if lun_info.lun_type == msg_pds.LUN_TYPE_BASEDISK: basedisk_info = common.GetBaseDiskInfoById( lun_info.Extensions[msg_pds.ext_luninfo_basedisk_id]) data_part_info = common.GetDiskPartByID( basedisk_info.disk_id, basedisk_info.disk_part) data_actual_state = data_part_info.actual_state elif lun_info.lun_type == msg_pds.LUN_TYPE_BASEDEV: data_actual_state = True elif lun_info.lun_type == msg_pds.LUN_TYPE_SMARTCACHE: smartcache_info = common.GetSmartCacheInfoById( lun_info.Extensions[msg_pds.ext_luninfo_smartcache_id]) data_part_info = common.GetDiskPartByID( smartcache_info.data_disk_id, smartcache_info.data_disk_part) cache_part_info = common.GetDiskPartByID( smartcache_info.cache_disk_id, smartcache_info.cache_disk_part) 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_part_info = common.GetDiskPartByID( palcache_info.disk_id, palcache_info.disk_part) pool_info = common.GetPoolInfoById(palcache_info.pool_id) pool_part = common.GetDiskPartByID( pool_info.pool_disk_infos[0].disk_id, pool_info.pool_disk_infos[0].disk_part) 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_part_info = common.GetDiskPartByID( palraw_info.disk_id, palraw_info.disk_part) 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) data_actual_state = data_part_info.actual_state else: assert (0) if data_actual_state == False or False in lun_info.Extensions[ msg_mds.ext_luninfo_cache_actual_state]: return True return False
def INIT(self, request): self.response = MakeResponse(msg_mds.DISK_REPLACE_RESPONSE, request) self.request = request self.request_body = request.body.Extensions[ msg_mds.disk_replace_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 # 获取被替换磁盘信息 old_disk_info = common.GetDiskInfoByName(self.request_body.disk_name) if old_disk_info == None: self.response.rc.retcode = msg_mds.RC_MDS_DISK_NOT_EXIST self.response.rc.message = "Disk %s is not exist" % ( self.request_body.disk_name) self.SendResponse(self.response) return MS_FINISH self.ces_addr = None self.dev_name = None # 检查dev_name参数 if self.request_body.dev_name.startswith("/dev"): # 检查所有raid, 如果有盘的盘符为dev_name, 则提示使用ces操作 for rdisk in g.raid_disk_list_all.raid_disk_infos: if rdisk.HasField( 'dev_name' ) and rdisk.dev_name == self.request_body.dev_name: self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS self.response.rc.message = "Please use Raid.Addr as params" self.SendResponse(self.response) return MS_FINISH self.dev_name = self.request_body.dev_name else: # ces items = self.request_body.dev_name.split(":") if len(items) not in [3, 4]: self.response.rc.retcode = msg_mds.RC_MDS_ERROR_PARAMS self.response.rc.message = "param 'Raid.Addr' is ilegal" self.SendResponse(self.response) return MS_FINISH self.ces_addr = self.request_body.dev_name # 检查新磁盘是否已经初始化过了 for disk in g.disk_list.disk_infos: # 以盘符查找 if self.dev_name != None and disk.dev_name == self.dev_name: self.response.rc.retcode = msg_mds.RC_MDS_NOT_SUPPORT self.response.rc.message = "Disk %s already initialized" % self.dev_name self.SendResponse(self.response) return MS_FINISH # 以ces查找 elif disk.HasField('raid_disk_info'): ces_addr = "%s:%s:%s" % (disk.raid_disk_info.ctl, disk.raid_disk_info.eid, disk.raid_disk_info.slot) if ces_addr == self.ces_addr: self.response.rc.retcode = msg_mds.RC_MDS_NOT_SUPPORT self.response.rc.message = "Disk %s already initialized" % self.ces_addr self.SendResponse(self.response) return MS_FINISH self.raid_disk_info = None # 检查目标盘是否存在 # 以盘符查找 if self.dev_name != None: disk = [ disk for disk in g.disk_list_all.disk_infos if disk.dev_name == self.dev_name ] if len(disk) == 0: self.response.rc.retcode = msg_mds.RC_MDS_DISK_NOT_EXIST self.response.rc.message = "Disk %s not exist" % self.dev_name self.SendResponse(self.response) return MS_FINISH if disk[0].HasField('raid_disk_info'): self.raid_disk_info = msg_pds.RaidDiskInfo() self.raid_disk_info.CopyFrom(disk[0].raid_disk_info) # 以ces查找 if self.ces_addr != None: raid_disk = [] for disk in g.raid_disk_list_all.raid_disk_infos: if "%s:%s:%s" % (disk.ctl, disk.eid, disk.slot) == self.ces_addr: raid_disk.append(disk) if len(raid_disk) == 0: self.response.rc.retcode = msg_mds.RC_MDS_DISK_NOT_EXIST self.response.rc.message = "Disk %s not exist" % self.ces_addr self.SendResponse(self.response) return MS_FINISH if raid_disk[0].HasField( 'dev_name') and raid_disk[0].dev_name != "": # 如果raid有盘符, 则直接通过盘符初始化, 不再通过ces_addr self.dev_name = raid_disk[0].dev_name self.ces_addr = None self.raid_disk_info = msg_pds.RaidDiskInfo() self.raid_disk_info = raid_disk[0] if raid_disk[0].drive_type.lower() == "ssd": disk_type = msg_pds.DISK_TYPE_SSD else: disk_type = msg_pds.DISK_TYPE_HDD # ces类型 检查新磁盘和被替换磁盘类型是否一致 if disk_type != old_disk_info.disk_type: self.response.rc.retcode = msg_mds.RC_MDS_NOT_SUPPORT self.response.rc.message = "Disk '%s' type must be the same as '%s'" % ( self.request_body.dev_name, self.request_body.disk_name) self.SendResponse(self.response) return MS_FINISH # 检查新磁盘大小 if self.raid_disk_info.size < old_disk_info.size: self.response.rc.retcode = msg_mds.RC_MDS_NOT_SUPPORT self.response.rc.message = "Disk '%s' size must be greater than or equal to '%s'" % ( self.request_body.dev_name, self.request_body.disk_name) self.SendResponse(self.response) return MS_FINISH lun_infos = common.GetLunInfoByDiskID(old_disk_info.header.uuid) if old_disk_info.disk_type == msg_pds.DISK_TYPE_SSD: pool_infos = common.GetPoolInfoByDiskID(old_disk_info.header.uuid) for pool_info in pool_infos: pool_lun_infos = common.GetLunInfoByPoolID(pool_info.pool_id) lun_infos.extend(pool_lun_infos) # 检查是否被smartcache盘引用 smartcache_list = [ lun_info for lun_info in lun_infos if lun_info.lun_type == msg_pds.LUN_TYPE_SMARTCACHE ] if len(smartcache_list) > 0: self.response.rc.retcode = msg_mds.RC_MDS_NOT_SUPPORT self.response.rc.message = "Disk '%s' contains smartcache lun, not support" % ( self.request_body.disk_name) self.SendResponse(self.response) return MS_FINISH # 整理换盘需要的信息 self.old_disk_info = {} self.old_disk_info['disk_id'] = old_disk_info.header.uuid self.old_disk_info['disk_name'] = self.request_body.disk_name self.old_disk_info['disk_type'] = old_disk_info.disk_type self.old_disk_info['partition_count'] = len(old_disk_info.diskparts) if old_disk_info.disk_type == msg_pds.DISK_TYPE_SSD: self.old_disk_info['pools'] = [] for pool_info in pool_infos: pool = {} pool['pool_name'] = pool_info.pool_name pool['size'] = pool_info.Extensions[ msg_mds.ext_poolinfo_pool_export_info].size pool['max_size'] = pool_info.Extensions[ msg_mds.ext_poolinfo_pool_export_info].max_size pool['disk_part'] = pool_info.pool_disk_infos[0].disk_part pool['is_variable'] = pool_info.is_variable if pool_info.HasField("extent"): pool['extent'] = pool_info.extent if pool_info.HasField("bucket"): pool['bucket'] = pool_info.bucket if pool_info.HasField("sippet"): pool['sippet'] = pool_info.sippet self.old_disk_info['pools'].append(pool) self.old_disk_info['luns'] = [] for lun_info in lun_infos: lun = {} lun['lun_name'] = lun_info.lun_name lun['lun_type'] = lun_info.lun_type lun['group_name'] = lun_info.group_name lun['config_state'] = lun_info.config_state if lun_info.lun_type == msg_pds.LUN_TYPE_BASEDISK: basedisk_info = common.GetBaseDiskInfoById( lun_info.Extensions[msg_pds.ext_luninfo_basedisk_id]) data_part_info = common.GetDiskPartByID( basedisk_info.disk_id, basedisk_info.disk_part) data_disk_name = "%sp%s" % (self.request_body.disk_name, data_part_info.disk_part) lun['data_disk_name'] = data_disk_name elif lun_info.lun_type == msg_pds.LUN_TYPE_PALRAW: palraw_info = common.GetPalRawInfoById( lun_info.Extensions[msg_pds.ext_luninfo_palraw_id]) data_part_info = common.GetDiskPartByID( palraw_info.disk_id, palraw_info.disk_part) data_disk_name = "%sp%s" % (self.request_body.disk_name, data_part_info.disk_part) lun['data_disk_name'] = data_disk_name 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) data_disk_name = "%sp%s" % (data_disk_info.disk_name, data_part_info.disk_part) pool_info = common.GetPoolInfoById(palcache_info.pool_id) lun['pool_name'] = pool_info.pool_name lun['data_disk_name'] = data_disk_name elif lun_info.lun_type == msg_pds.LUN_TYPE_PALPMT: palpmt_info = common.GetPalPmtInfoById( lun_info.Extensions[msg_pds.ext_luninfo_palpmt_id]) size = palpmt_info.size pool_info = common.GetPoolInfoById(palpmt_info.pool_id) lun['pool_name'] = pool_info.pool_name lun['lun_size'] = size self.old_disk_info['luns'].append(lun) if len(self.old_disk_info['luns']) > 0: self.lun_offline_flag = 0 return self.send_lun_offline_request() if self.old_disk_info['disk_type'] == msg_pds.DISK_TYPE_SSD and len( self.old_disk_info['pools']) > 0: self.pool_drop_flag = 0 return self.send_pool_drop_request() mds_request = MakeRequest(msg_mds.DISK_DROP_REQUEST) mds_request.body.Extensions[ msg_mds.disk_drop_request].disk_name = self.request_body.disk_name self.SendRequest(g.listen_ip, g.listen_port, mds_request, self.Entry_DiskDrop) return MS_CONTINUE
def INIT(self, request): self.response = MakeResponse(msg_mds.GET_POOL_LIST_RESPONSE, request) self.request = request self.request_body = request.body.Extensions[ msg_mds.get_pool_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 for _pool_info in g.pool_list.pool_infos: pool_info = msg_pds.PoolInfo() pool_info.CopyFrom(_pool_info) # 补充磁盘的实时信息 for pool_disk_info in pool_info.pool_disk_infos: disk_info = common.GetDiskInfoByID(pool_disk_info.disk_id) diskpart = common.GetDiskPartByID(pool_disk_info.disk_id, pool_disk_info.disk_part) pool_disk_info.Extensions[ msg_mds.ext_pool_disk_info_dev_name] = diskpart.dev_name pool_disk_info.Extensions[ msg_mds.ext_pool_disk_info_disk_name] = "%sp%s" % ( disk_info.disk_name, pool_disk_info.disk_part) pool_disk_info.Extensions[ msg_mds.ext_pool_disk_info_size] = diskpart.size # 补充pool cache mode count = {'wb': 0, 'wt': 0, 'un': 0} for palcache_info in g.palcache_list.palcache_infos: if palcache_info.pool_id != pool_info.pool_id: continue if not palcache_info.HasExtension( msg_mds.ext_palcache_export_info): continue if palcache_info.Extensions[ msg_mds. ext_palcache_export_info].palcache_cache_model == msg_pds.PALCACHE_CACHE_MODEL_UNKNOWN: count['un'] += 1 if palcache_info.Extensions[ msg_mds. ext_palcache_export_info].palcache_cache_model == msg_pds.PALCACHE_CACHE_MODEL_WRITEBACK: count['wb'] += 1 if palcache_info.Extensions[ msg_mds. ext_palcache_export_info].palcache_cache_model == msg_pds.PALCACHE_CACHE_MODEL_WRITETHROUGH: count['wt'] += 1 if count['wb'] == 0 and count['wt'] != 0: pool_info.Extensions[ msg_mds. ext_poolinfo_pool_cache_model] = msg_pds.POOL_CACHE_MODEL_WRITETHROUGH elif count['wb'] != 0 and count['wt'] == 0: pool_info.Extensions[ msg_mds. ext_poolinfo_pool_cache_model] = msg_pds.POOL_CACHE_MODEL_WRITEBACK elif count['wb'] != 0 and count['wt'] != 0: pool_info.Extensions[ msg_mds. ext_poolinfo_pool_cache_model] = msg_pds.POOL_CACHE_MODEL_MIX # 补充使用该pool的lun的总容量 pmt_size = 0 for palpmt_info in g.palpmt_list.palpmt_infos: if palpmt_info.pool_id == pool_info.pool_id: pmt_size += palpmt_info.size pool_info.Extensions[msg_mds.ext_poolinfo_pool_pmt_size] = pmt_size self.response.body.Extensions[ msg_mds.get_pool_list_response].pool_infos.add().CopyFrom( pool_info) self.response.rc.retcode = msg_pds.RC_SUCCESS self.SendResponse(self.response) return MS_FINISH