def read_chunk_metadata(fd, chunk_id, check_chunk_id=True): chunk_id = chunk_id.upper() raw_meta = read_user_xattr(fd) raw_meta_copy = None meta = {} meta['links'] = dict() raw_chunk_id = container_id = path = version = content_id = None for k, v in raw_meta.iteritems(): # New chunk if k.startswith(CHUNK_XATTR_CONTENT_FULLPATH_PREFIX): chunkid = k[len(CHUNK_XATTR_CONTENT_FULLPATH_PREFIX):] if chunkid == chunk_id: raw_chunk_id = chunkid meta['full_path'] = v account, container, path, version, content_id = \ decode_fullpath(v) container_id = cid_from_name(account, container) else: meta['links'][chunkid] = v if raw_chunk_id: raw_meta_copy = raw_meta.copy() raw_meta[chunk_xattr_keys['chunk_id']] = raw_chunk_id raw_meta[chunk_xattr_keys['container_id']] = container_id raw_meta[chunk_xattr_keys['content_path']] = path raw_meta[chunk_xattr_keys['content_version']] = version raw_meta[chunk_xattr_keys['content_id']] = content_id for k, v in chunk_xattr_keys.iteritems(): if v not in raw_meta: if k not in chunk_xattr_keys_optional: raise exc.MissingAttribute(v) else: meta[k] = raw_meta[v] if check_chunk_id and meta['chunk_id'] != chunk_id: raise exc.MissingAttribute(chunk_xattr_keys['chunk_id']) return meta, raw_meta_copy if raw_meta_copy else raw_meta
def read_chunk_metadata(fd, chunk_id, check_chunk_id=True): chunk_id = chunk_id.upper() raw_meta = read_user_xattr(fd) raw_meta_copy = None meta = {} meta['links'] = dict() attr_vers = 0.0 raw_chunk_id = container_id = path = version = content_id = None missing = list() for k, v in raw_meta.iteritems(): # New chunks have a version if k == chunk_xattr_keys['oio_version']: attr_vers = float(v) # Chunks with version >= 4.2 have a "full_path" elif k.startswith(CHUNK_XATTR_CONTENT_FULLPATH_PREFIX): parsed_chunk_id = k[len(CHUNK_XATTR_CONTENT_FULLPATH_PREFIX):] if parsed_chunk_id == chunk_id: raw_chunk_id = parsed_chunk_id meta['full_path'] = v account, container, path, version, content_id = \ decode_fullpath(v) container_id = cid_from_name(account, container) else: meta['links'][parsed_chunk_id] = v if raw_chunk_id: raw_meta_copy = raw_meta.copy() raw_meta[chunk_xattr_keys['chunk_id']] = raw_chunk_id raw_meta[chunk_xattr_keys['container_id']] = container_id raw_meta[chunk_xattr_keys['content_path']] = path raw_meta[chunk_xattr_keys['content_version']] = version raw_meta[chunk_xattr_keys['content_id']] = content_id if attr_vers >= 4.2 and 'full_path' not in meta: # TODO(FVE): in that case, do not warn about other attributes # that could be deduced from this one. missing.append( exc.MissingAttribute(CHUNK_XATTR_CONTENT_FULLPATH_PREFIX + chunk_id)) for k, v in chunk_xattr_keys.iteritems(): if v not in raw_meta: if k not in chunk_xattr_keys_optional: missing.append(exc.MissingAttribute(v)) else: meta[k] = raw_meta[v] if missing: raise exc.FaultyChunk(*missing) if check_chunk_id and meta['chunk_id'] != chunk_id: raise exc.MissingAttribute(chunk_xattr_keys['chunk_id']) return meta, raw_meta_copy if raw_meta_copy else raw_meta
def extract_headers_meta(headers, check=True): """ Extract chunk metadata from a dictionary of rawx response headers. :param headers: a dictionary of headers, as returned by a HEAD or GET request to a rawx service. :keyword check: if True (the default), raise FaultyChunk if one or several mandatory response headers are missing. :returns: a dictionary of chunk metadata. """ meta = {} missing = list() for mkey, hkey in CHUNK_HEADERS.items(): try: if mkey == 'full_path': meta[mkey] = headers[hkey] else: meta[mkey] = unquote(headers[hkey]) except KeyError: if check and mkey not in CHUNK_XATTR_KEYS_OPTIONAL: missing.append(exc.MissingAttribute(mkey)) if check and missing: raise exc.FaultyChunk(*missing) mtime = meta.get('chunk_mtime') if mtime: meta['chunk_mtime'] = mktime(parsedate(mtime)) return meta
def read_chunk_metadata(fd): raw_meta = read_user_xattr(fd) meta = {} for k, v in chunk_xattr_keys.iteritems(): if v not in raw_meta: raise exc.MissingAttribute(v) meta[k] = raw_meta[v] return meta
def read_chunk_metadata(fd): raw_meta = read_user_xattr(fd) meta = {} for k, v in iteritems(chunk_xattr_keys): if v not in raw_meta: if k not in chunk_xattr_keys_optional: raise exc.MissingAttribute(v) else: meta[k] = raw_meta[v] return meta