def getMetadataInternal(self, params={}): try: lower = 0 upper = 0 retmap = {} sr_info_map = {} ret_vdi_info = {} length = getMetadataLength(self.fd) min_blk_size = get_min_blk_size_wrapper(self.fd) # Read in the metadata fil metadataxml = '' metadataxml = xs_file_read_wrapper(self.fd, 0, length, min_blk_size) # At this point we have the complete metadata in metadataxml offset = SECTOR_SIZE + len(XML_HEADER) sr_info = metadataxml[offset:SECTOR_SIZE * 4] offset = SECTOR_SIZE * 4 sr_info = sr_info.replace('\x00', '') parsable_metadata = '%s<%s>%s</%s>' % ( XML_HEADER, metadata.XML_TAG, sr_info, metadata.XML_TAG) retmap['sr_info'] = metadata._parseXML(parsable_metadata) # At this point we check if an offset has been passed in if params.has_key('offset'): upper = getBlockAlignedRange(min_blk_size, params['offset'], \ 0)[1] else: upper = length # Now look at the VDI objects while offset < upper: vdi_info = metadataxml[offset:offset + (SECTOR_SIZE * self.VDI_INFO_SIZE_IN_SECTORS)] vdi_info = vdi_info.replace('\x00', '') parsable_metadata = '%s<%s>%s</%s>' % ( XML_HEADER, metadata.XML_TAG, vdi_info, metadata.XML_TAG) vdi_info_map = metadata._parseXML(parsable_metadata)[VDI_TAG] vdi_info_map[OFFSET_TAG] = offset if not params.has_key('includeDeletedVdis') and \ vdi_info_map[VDI_DELETED_TAG] == '1': offset += SECTOR_SIZE * self.VDI_INFO_SIZE_IN_SECTORS continue if params.has_key('indexByUuid'): ret_vdi_info[vdi_info_map[UUID_TAG]] = vdi_info_map else: ret_vdi_info[offset] = vdi_info_map if params.has_key('vdi_uuid'): if vdi_info_map[UUID_TAG] == params['vdi_uuid']: retmap['offset'] = offset (lower, upper) = \ getBlockAlignedRange(min_blk_size, offset, \ SECTOR_SIZE * self.VDI_INFO_SIZE_IN_SECTORS) elif params.has_key('firstDeleted'): if vdi_info_map[VDI_DELETED_TAG] == '1': retmap['foundDeleted'] = 1 retmap['offset'] = offset (lower, upper) = \ getBlockAlignedRange(min_blk_size, offset, \ SECTOR_SIZE * self.VDI_INFO_SIZE_IN_SECTORS) offset += SECTOR_SIZE * self.VDI_INFO_SIZE_IN_SECTORS retmap['lower'] = lower retmap['upper'] = upper retmap['vdi_info'] = ret_vdi_info return retmap except Exception, e: util.SMlog("Exception getting metadata with params" \ "%s. Error: %s" % (params, str(e))) raise
def getMetadataInternal(self, params = {}): try: lower = 0; upper = 0 retmap = {}; sr_info_map = {}; ret_vdi_info = {} length = getMetadataLength(self.fd) min_blk_size = get_min_blk_size_wrapper(self.fd) # Read in the metadata fil metadataxml = '' metadataxml = xs_file_read_wrapper(self.fd, 0, length, min_blk_size) # At this point we have the complete metadata in metadataxml offset = SECTOR_SIZE + len(XML_HEADER) sr_info = metadataxml[offset: SECTOR_SIZE * 4] offset = SECTOR_SIZE * 4 sr_info = sr_info.replace('\x00','') parsable_metadata = '%s<%s>%s</%s>' % (XML_HEADER, metadata.XML_TAG, sr_info, metadata.XML_TAG) retmap['sr_info'] = metadata._parseXML(parsable_metadata) # At this point we check if an offset has been passed in if params.has_key('offset'): upper = getBlockAlignedRange(min_blk_size, params['offset'], \ 0)[1] else: upper = length # Now look at the VDI objects while offset < upper: vdi_info = metadataxml[offset: offset + (SECTOR_SIZE * self.VDI_INFO_SIZE_IN_SECTORS)] vdi_info = vdi_info.replace('\x00','') parsable_metadata = '%s<%s>%s</%s>' % (XML_HEADER, metadata.XML_TAG, vdi_info, metadata.XML_TAG) vdi_info_map = metadata._parseXML(parsable_metadata)[VDI_TAG] vdi_info_map[OFFSET_TAG] = offset if not params.has_key('includeDeletedVdis') and \ vdi_info_map[VDI_DELETED_TAG] == '1': offset += SECTOR_SIZE * self.VDI_INFO_SIZE_IN_SECTORS continue if params.has_key('indexByUuid'): ret_vdi_info[vdi_info_map[UUID_TAG]] = vdi_info_map else: ret_vdi_info[offset] = vdi_info_map if params.has_key('vdi_uuid'): if vdi_info_map[UUID_TAG] == params['vdi_uuid']: retmap['offset'] = offset (lower, upper) = \ getBlockAlignedRange(min_blk_size, offset, \ SECTOR_SIZE * self.VDI_INFO_SIZE_IN_SECTORS) elif params.has_key('firstDeleted'): if vdi_info_map[VDI_DELETED_TAG] == '1': retmap['foundDeleted'] = 1 retmap['offset'] = offset (lower, upper) = \ getBlockAlignedRange(min_blk_size, offset, \ SECTOR_SIZE * self.VDI_INFO_SIZE_IN_SECTORS) offset += SECTOR_SIZE * self.VDI_INFO_SIZE_IN_SECTORS retmap['lower'] = lower retmap['upper'] = upper retmap['vdi_info'] = ret_vdi_info return retmap except Exception, e: util.SMlog("Exception getting metadata with params" \ "%s. Error: %s" % (params, str(e))) raise