def content_delete(self, account=None, reference=None, path=None, cid=None, version=None, **kwargs): """ Delete one object. :returns: True if the object has been deleted """ uri = self._make_uri('content/delete') params = self._make_params(account, reference, path, cid=cid, version=version) del_cached_object_metadata(account=account, reference=reference, path=path, cid=cid, version=version, **kwargs) resp, _ = self._direct_request('POST', uri, params=params, **kwargs) return resp.status == 204
def content_truncate(self, account=None, reference=None, path=None, cid=None, version=None, size=0, **kwargs): uri = self._make_uri('content/truncate') params = self._make_params(account, reference, path, cid=cid, version=version) params['size'] = size del_cached_object_metadata(account=account, reference=reference, path=path, cid=cid, version=version, **kwargs) _resp, body = self._direct_request('POST', uri, params=params, **kwargs) return body
def content_purge(self, account=None, reference=None, path=None, cid=None, maxvers=None, **kwargs): uri = self._make_uri('content/purge') params = self._make_params(account, reference, path, cid=cid) if maxvers is not None: params["maxvers"] = maxvers del_cached_object_metadata( account=account, reference=reference, path=path, cid=cid, **kwargs) self._direct_request('POST', uri, params=params, **kwargs)
def content_drain(self, account=None, reference=None, path=None, cid=None, version=None, **kwargs): uri = self._make_uri('content/drain') params = self._make_params(account, reference, path, cid=cid, version=version) del_cached_object_metadata( account=account, reference=reference, path=path, cid=cid, version=version, **kwargs) resp, _ = self._direct_request('POST', uri, params=params, **kwargs) return resp.status == 204
def content_delete_many(self, account=None, reference=None, paths=None, cid=None, **kwargs): """ Delete several objects. :param paths: an iterable of object paths (should not be a generator) :returns: a list of tuples with the path of the content and a boolean telling if the content has been deleted :rtype: `list` of `tuple` """ uri = self._make_uri('content/delete_many') params = self._make_params(account, reference, cid=cid) unformatted_data = list() for obj in paths: unformatted_data.append({'name': obj}) data = json.dumps({"contents": unformatted_data}) results = list() for path in paths: del_cached_object_metadata( account=account, reference=reference, path=path, cid=cid, **kwargs) try: _, resp_body = self._direct_request( 'POST', uri, data=data, params=params, **kwargs) for obj in resp_body["contents"]: results.append((obj["name"], obj["status"] == 204)) return results except exceptions.NotFound: for obj in paths: rc = self.content_delete(account, reference, obj, cid=cid, **kwargs) results.append((obj, rc)) return results except exceptions.TooLarge: pivot = len(paths) / 2 head = paths[:pivot] tail = paths[pivot:] if head: results += self.content_delete_many( account, reference, head, cid=cid, **kwargs) if tail: results += self.content_delete_many( account, reference, tail, cid=cid, **kwargs) return results except Exception: raise
def content_set_properties(self, account=None, reference=None, path=None, properties={}, cid=None, version=None, clear=False, **kwargs): """ Set properties on an object. :param properties: dictionary of properties """ uri = self._make_uri('content/set_properties') params = self._make_params(account, reference, path, cid=cid, version=version) if clear: params['flush'] = 1 data = json.dumps(properties) del_cached_object_metadata( account=account, reference=reference, path=path, cid=cid, version=version, **kwargs) _resp, _body = self._direct_request( 'POST', uri, data=data, params=params, **kwargs)
def content_del_properties(self, account=None, reference=None, path=None, properties=[], cid=None, version=None, **kwargs): """ Delete some properties from an object. :param properties: list of property keys to delete :type properties: `list` :returns: True is the property has been deleted """ uri = self._make_uri('content/del_properties') params = self._make_params(account, reference, path, cid=cid, version=version) # Build a list in case the parameter is a view (not serializable). data = json.dumps([x for x in properties]) del_cached_object_metadata( account=account, reference=reference, path=path, cid=cid, version=version, **kwargs) resp, _body = self._direct_request( 'POST', uri, data=data, params=params, **kwargs) return resp.status == 204
def content_create(self, account=None, reference=None, path=None, size=None, checksum=None, data=None, cid=None, content_id=None, stgpol=None, version=None, mime_type=None, chunk_method=None, headers=None, append=False, change_policy=False, force=False, **kwargs): """ Create a new object. This method does not upload any data, it just registers object metadata in the database. :param size: size of the object :type size: `int` :param checksum: checksum of the object (may be None when appending) :type checksum: hexadecimal `str` :param data: metadata of the object (list of chunks and dict of properties) :type data: `dict` :param cid: container id that can be used in place of `account` and `reference` :type cid: hexadecimal `str` :param content_id: the ID to set on the object, or the ID of the existing object when appending :param stgpol: name of the storage policy for the object :param version: version of the object :type version: `int` :param mime_type: MIME type to set on the object :param chunk_method: :param headers: extra headers to send to the proxy :param append: append to an existing object instead of creating it :type append: `bool` :param change_policy: change policy of an existing object :type change_policy: `bool` """ uri = self._make_uri('content/create') params = self._make_params(account, reference, path, cid=cid) if append: params['append'] = '1' if change_policy: params['change_policy'] = '1' # TODO(FVE): implement 'force' parameter if not isinstance(data, dict): warnings.simplefilter('once') warnings.warn("'data' parameter should be a dict, not a list", DeprecationWarning, stacklevel=3) if kwargs.get('meta_pos') is not None: data = data['chunks'] # TODO(FVE): change "id" into "content", and other occurrences params['id'] = content_id uri = self._make_uri('content/update') data = json.dumps(data) hdrs = { 'x-oio-content-meta-length': str(size), 'x-oio-content-meta-hash': checksum } hdrs.update(headers) if content_id is not None: hdrs['x-oio-content-meta-id'] = content_id if stgpol is not None: hdrs['x-oio-content-meta-policy'] = stgpol if version is not None: hdrs['x-oio-content-meta-version'] = str(version) if mime_type is not None: hdrs['x-oio-content-meta-mime-type'] = mime_type if chunk_method is not None: hdrs['x-oio-content-meta-chunk-method'] = chunk_method del_cached_object_metadata(account=account, reference=reference, path=path, cid=cid, version=version, **kwargs) resp, body = self._direct_request('POST', uri, data=data, params=params, headers=hdrs, **kwargs) return resp, body