def OfflineLunBaseDisk(self): basedisk_info = common.GetBaseDiskInfoById(self.lun_info.Extensions[msg_pds.ext_luninfo_basedisk_id]) self.ios_request_body.node_name = g.node_info.node_name self.ios_request_body.lun_id = self.lun_info.lun_id self.ios_request_body.lun_name = self.lun_info.lun_name self.ios_request_body.lun_type = self.lun_info.lun_type self.ios_request_body.keep_res = True self.ios_request_body.Extensions[msg_ios.ext_lundroprequest_basedisk].CopyFrom(basedisk_info) self.SendRequest(g.ios_service.listen_ip, g.ios_service.listen_port, self.ios_request, self.Entry_OfflineLun) return MS_CONTINUE
def drop_lun(self): # 请求转发给对应的ios节点 self.ios_request = MakeRequest(msg_ios.LUN_DROP_REQUEST, self.request) self.ios_request_body = self.ios_request.body.Extensions[msg_ios.lun_drop_request] self.ios_request_body.node_name = g.node_info.node_name self.ios_request_body.lun_id = self.lun_info.lun_id self.ios_request_body.lun_name = self.lun_info.lun_name self.ios_request_body.lun_type = self.lun_info.lun_type self.ios_request_body.keep_res = False group_uuids = [] for guuid in self.lun_info.group_info: group_uuids.append(guuid.group_uuid) self.ios_request_body.group_name.extend(group_uuids) if self.lun_info.lun_type == msg_pds.LUN_TYPE_SMARTCACHE: smartcache_info = common.GetSmartCacheInfoById(self.lun_info.Extensions[msg_pds.ext_luninfo_smartcache_id]) self.ios_request_body.Extensions[msg_ios.ext_lundroprequest_smartcache].CopyFrom(smartcache_info) elif self.lun_info.lun_type == msg_pds.LUN_TYPE_BASEDISK: basedisk_info = common.GetBaseDiskInfoById(self.lun_info.Extensions[msg_pds.ext_luninfo_basedisk_id]) self.ios_request_body.Extensions[msg_ios.ext_lundroprequest_basedisk].CopyFrom(basedisk_info) elif self.lun_info.lun_type == msg_pds.LUN_TYPE_PALCACHE: palcache_info = common.GetPalCacheInfoById(self.lun_info.Extensions[msg_pds.ext_luninfo_palcache_id]) # palcache类型需要补充pool的名字, 解决palcache不可用时, 设置obsolete的过程 palcache_info.Extensions[msg_ios.ext_palcacheinfo_pool_name] = common.GetPoolInfoById(palcache_info.pool_id).pool_name self.ios_request_body.Extensions[msg_ios.ext_lundroprequest_palcache].CopyFrom(palcache_info) elif self.lun_info.lun_type == msg_pds.LUN_TYPE_PALRAW: palraw_info = common.GetPalRawInfoById(self.lun_info.Extensions[msg_pds.ext_luninfo_palraw_id]) self.ios_request_body.Extensions[msg_ios.ext_lundroprequest_palraw].CopyFrom(palraw_info) elif self.lun_info.lun_type == msg_pds.LUN_TYPE_PALPMT: palpmt_info = common.GetPalPmtInfoById(self.lun_info.Extensions[msg_pds.ext_luninfo_palpmt_id]) self.ios_request_body.Extensions[msg_ios.ext_lundroprequest_palpmt].CopyFrom(palpmt_info) elif self.lun_info.lun_type == msg_pds.LUN_TYPE_BASEDEV: basedev_info = common.GetBaseDevInfoById(self.lun_info.Extensions[msg_pds.ext_luninfo_basedev_id]) self.ios_request_body.Extensions[msg_ios.ext_lundroprequest_basedev].CopyFrom(basedev_info) else: assert(0) self.SendRequest(g.ios_service.listen_ip, g.ios_service.listen_port, self.ios_request, self.Entry_LunDrop) return MS_CONTINUE
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 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.GET_DISK_INFO_RESPONSE, request) self.request = request self.request_body = request.body.Extensions[msg_mds.get_disk_info_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 disk_info = None for _disk_info in g.disk_list.disk_infos: if _disk_info.disk_name == self.request_body.node_disk_name: disk_info = _disk_info break if disk_info == None: self.response.rc.retcode = msg_mds.RC_MDS_DISK_NOT_EXIST self.response.rc.message = "can't find disk %s" % self.request_body.node_disk_name self.SendResponse(self.response) return MS_FINISH # 补充使用该盘的lun列表 lun_infos = common.GetLunInfoByDiskID(disk_info.header.uuid) for lun_info in lun_infos: kv = msg_pds.SimpleKV() kv.value = lun_info.lun_name if lun_info.lun_type == msg_pds.LUN_TYPE_BASEDISK: basedisk_info = common.GetBaseDiskInfoById(lun_info.Extensions[msg_pds.ext_luninfo_basedisk_id]) kv.key = "%s.%s" % (basedisk_info.disk_id, basedisk_info.disk_part) disk_info.Extensions[msg_mds.ext_diskinfo_diskpart_to_lun_name].add().CopyFrom(kv) elif lun_info.lun_type == msg_pds.LUN_TYPE_PALCACHE: palcache_info = common.GetPalCacheInfoById(lun_info.Extensions[msg_pds.ext_luninfo_palcache_id]) kv.key = "%s.%s" % (palcache_info.disk_id, palcache_info.disk_part) disk_info.Extensions[msg_mds.ext_diskinfo_diskpart_to_lun_name].add().CopyFrom(kv) elif lun_info.lun_type == msg_pds.LUN_TYPE_PALRAW: palraw_info = common.GetPalRawInfoById(lun_info.Extensions[msg_pds.ext_luninfo_palraw_id]) kv.key = "%s.%s" % (palraw_info.disk_id, palraw_info.disk_part) disk_info.Extensions[msg_mds.ext_diskinfo_diskpart_to_lun_name].add().CopyFrom(kv) elif lun_info.lun_type == msg_pds.LUN_TYPE_SMARTCACHE: smartcache_info = common.GetSmartCacheInfoById(lun_info.Extensions[msg_pds.ext_luninfo_smartcache_id]) if smartcache_info.data_disk_id == disk_info.header.uuid: kv.key = "%s.%s" % (smartcache_info.data_disk_id, smartcache_info.data_disk_part) disk_info.Extensions[msg_mds.ext_diskinfo_diskpart_to_lun_name].add().CopyFrom(kv) if smartcache_info.cache_disk_id == disk_info.header.uuid: kv.key = "%s.%s" % (smartcache_info.cache_disk_id, smartcache_info.cache_disk_part) disk_info.Extensions[msg_mds.ext_diskinfo_diskpart_to_lun_name_smartcache].add().CopyFrom(kv) elif lun_info.lun_type == msg_pds.LUN_TYPE_BASEDEV: pass elif lun_info.lun_type == msg_pds.LUN_TYPE_PALPMT: pass else: assert(0) # 补充使用该盘的pool列表 pool_infos = common.GetPoolInfoByDiskID(disk_info.header.uuid) for pool_info in pool_infos: for pool_disk_info in pool_info.pool_disk_infos: if pool_disk_info.disk_id == disk_info.header.uuid: kv = msg_pds.SimpleKV() kv.value = pool_info.pool_name kv.key = "%s.%s" % (pool_disk_info.disk_id, pool_disk_info.disk_part) disk_info.Extensions[msg_mds.ext_diskinfo_diskpart_to_pool_name].add().CopyFrom(kv) self.response.body.Extensions[msg_mds.get_disk_info_response].disk_info.CopyFrom(disk_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.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_DISK_LIST_RESPONSE, request) self.request = request self.request_body = request.body.Extensions[ msg_mds.get_disk_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 # 初始化过的盘 inited_disk = {'dev_name': [], 'ces_addr': []} for _disk_info in g.disk_list.disk_infos: disk_info = msg_pds.DiskInfo() disk_info.CopyFrom(_disk_info) # 补充磁盘的剩余空间 free_size = disk_info.size for diskpart in disk_info.diskparts: # 减去被lun使用的空间 lun_info = common.GetLunInfoByDiskPart(disk_info.header.uuid, diskpart.disk_part) if lun_info != None: free_size -= diskpart.size # 减去被pool使用的空间 pool_info = common.GetPoolInfoByDiskPart( disk_info.header.uuid, diskpart.disk_part) if pool_info != None: free_size -= diskpart.size disk_info.Extensions[msg_mds.ext_diskinfo_free_size] = free_size # 补充使用该盘的lun列表 lun_infos = common.GetLunInfoByDiskID(disk_info.header.uuid) for lun_info in lun_infos: kv = msg_pds.SimpleKV() kv.value = lun_info.lun_name if lun_info.lun_type == msg_pds.LUN_TYPE_BASEDISK: basedisk_info = common.GetBaseDiskInfoById( lun_info.Extensions[msg_pds.ext_luninfo_basedisk_id]) kv.key = "%s.%s" % (basedisk_info.disk_id, basedisk_info.disk_part) disk_info.Extensions[ msg_mds.ext_diskinfo_diskpart_to_lun_name].add( ).CopyFrom(kv) elif lun_info.lun_type == msg_pds.LUN_TYPE_PALCACHE: palcache_info = common.GetPalCacheInfoById( lun_info.Extensions[msg_pds.ext_luninfo_palcache_id]) kv.key = "%s.%s" % (palcache_info.disk_id, palcache_info.disk_part) disk_info.Extensions[ msg_mds.ext_diskinfo_diskpart_to_lun_name].add( ).CopyFrom(kv) elif lun_info.lun_type == msg_pds.LUN_TYPE_PALRAW: palraw_info = common.GetPalRawInfoById( lun_info.Extensions[msg_pds.ext_luninfo_palraw_id]) kv.key = "%s.%s" % (palraw_info.disk_id, palraw_info.disk_part) disk_info.Extensions[ msg_mds.ext_diskinfo_diskpart_to_lun_name].add( ).CopyFrom(kv) elif lun_info.lun_type == msg_pds.LUN_TYPE_SMARTCACHE: smartcache_info = common.GetSmartCacheInfoById( lun_info.Extensions[msg_pds.ext_luninfo_smartcache_id]) if smartcache_info.data_disk_id == disk_info.header.uuid: kv.key = "%s.%s" % (smartcache_info.data_disk_id, smartcache_info.data_disk_part) disk_info.Extensions[ msg_mds.ext_diskinfo_diskpart_to_lun_name].add( ).CopyFrom(kv) if smartcache_info.cache_disk_id == disk_info.header.uuid: kv.key = "%s.%s" % (smartcache_info.cache_disk_id, smartcache_info.cache_disk_part) disk_info.Extensions[ msg_mds. ext_diskinfo_diskpart_to_lun_name_smartcache].add( ).CopyFrom(kv) elif lun_info.lun_type == msg_pds.LUN_TYPE_BASEDEV: pass else: assert (0) # 补充使用该盘的pool列表 pool_infos = common.GetPoolInfoByDiskID(disk_info.header.uuid) for pool_info in pool_infos: for pool_disk_info in pool_info.pool_disk_infos: if pool_disk_info.disk_id == disk_info.header.uuid: kv = msg_pds.SimpleKV() kv.value = pool_info.pool_name kv.key = "%s.%s" % (pool_disk_info.disk_id, pool_disk_info.disk_part) disk_info.Extensions[ msg_mds.ext_diskinfo_diskpart_to_pool_name].add( ).CopyFrom(kv) self.response.body.Extensions[ msg_mds.get_disk_list_response].disk_infos.add().CopyFrom( disk_info) inited_disk['dev_name'].append(disk_info.dev_name) if disk_info.HasField('raid_disk_info'): ces_addr = "%s:%s:%s" % (disk_info.raid_disk_info.ctl, disk_info.raid_disk_info.eid, disk_info.raid_disk_info.slot) inited_disk['ces_addr'].append(ces_addr) # 补充没有初始化过的盘 for _disk_info in g.disk_list_all.disk_infos: disk_info = msg_pds.DiskInfo() disk_info.CopyFrom(_disk_info) if disk_info.dev_name in inited_disk['dev_name']: continue disk_info.Extensions[ msg_mds.ext_diskinfo_free_size] = disk_info.size self.response.body.Extensions[ msg_mds.get_disk_list_response].disk_infos.add().CopyFrom( disk_info) # 补充没有盘符的raid卡盘 for _raid_disk_info in g.raid_disk_list_all.raid_disk_infos: raid_disk_info = msg_pds.RaidDiskInfo() raid_disk_info.CopyFrom(_raid_disk_info) if raid_disk_info.HasField( 'dev_name') and raid_disk_info.dev_name != "": continue ces_addr = "%s:%s:%s" % (raid_disk_info.ctl, raid_disk_info.eid, raid_disk_info.slot) if ces_addr in inited_disk['ces_addr']: continue self.response.body.Extensions[ msg_mds.get_disk_list_response].raid_disk_infos.add().CopyFrom( raid_disk_info) self.response.rc.retcode = msg_pds.RC_SUCCESS self.SendResponse(self.response) return MS_FINISH