summaryrefslogtreecommitdiff
path: root/openstack.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2012-12-05 16:48:56 -0200
committerdrebs <drebs@leap.se>2012-12-05 16:48:56 -0200
commit5c2426df451b80ddea03a651614100ebacf118b0 (patch)
treedf987e12e190f964ddd2e596233a9f8f0d2d70d6 /openstack.py
parent449429948583706393200d24972cbb2a83c43bdc (diff)
OpenStack backend can delete docs.
Diffstat (limited to 'openstack.py')
-rw-r--r--openstack.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/openstack.py b/openstack.py
index ebb97ac5..e7d62751 100644
--- a/openstack.py
+++ b/openstack.py
@@ -41,9 +41,12 @@ class OpenStackDatabase(CommonBackend):
Conflicts do not happen on server side, so there's no need to check
for them.
"""
- response, contents = self._connection.get_object(self._container, doc_id)
- rev = response['x-object-meta-rev']
- return self._factory(doc_id, rev, contents)
+ try:
+ response, contents = self._connection.get_object(self._container, doc_id)
+ rev = response['x-object-meta-rev']
+ return self._factory(doc_id, rev, contents)
+ except: swiftclient.ClientException
+ return None
def get_doc(self, doc_id, include_deleted=False):
doc = self._get_doc(doc_id, check_for_conflicts=True)
@@ -83,7 +86,20 @@ class OpenStackDatabase(CommonBackend):
return new_rev
def delete_doc(self, doc):
- raise NotImplementedError(self.delete_doc)
+ old_doc = self._get_doc(doc.doc_id, check_for_conflicts=True)
+ if old_doc is None:
+ raise errors.DocumentDoesNotExist
+ if old_doc.rev != doc.rev:
+ raise errors.RevisionConflict()
+ if old_doc.is_tombstone():
+ raise errors.DocumentAlreadyDeleted
+ if old_doc.has_conflicts:
+ raise errors.ConflictedDoc()
+ new_rev = self._allocate_doc_rev(doc.rev)
+ doc.rev = new_rev
+ doc.make_tombstone()
+ self._put_doc(olddoc)
+ return new_rev
# start of index-related methods: these are not supported by this backend.