Commit 0d1b405d authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Invalidate snapshots when job fails

Make Cyclades invalidate snapshots in case of failure to submit the job
to Ganeti, or when the job fails. In either case invalidation is
performed by marking...
TODO: Add states sto API

fixes grnet/synnefo#231
parent 63c066a1
......@@ -26,6 +26,7 @@ from synnefo import quotas
from synnefo.api.util import release_resource
from synnefo.util.mac2eui64 import mac2eui64
from synnefo.logic import rapi
from synnefo import volume
from logging import getLogger
log = getLogger(__name__)
......@@ -583,7 +584,13 @@ def adopt_instance_disk(server, gnt_disk):
def update_snapshot(snap_id, user_id, job_id, job_status, etime):
"""Update a snapshot based on result of a Ganeti job."""
return
if job_status in rapi.JOB_STATUS_FINALIZED:
if (job_status == rapi.JOB_STATUS_SUCCESS):
status = "AVAILABLE"
else:
status = "ERROR"
log.debug("Updating status of snapshot '%s' to '%s'", snap_id, status)
volume.util.update_snapshot_status(snap_id, user_id, status=status)
@transaction.commit_on_success
......
......@@ -424,6 +424,7 @@ class PlanktonBackend(object):
images = []
for (location, metadata, permissions) in _images:
print metadata
location = Location(*location.split("/", 2))
images.append(image_to_dict(location, metadata, permissions))
......@@ -486,6 +487,14 @@ class PlanktonBackend(object):
def delete_snapshot(self, snapshot_uuid):
self.backend.delete_by_uuid(self.user, snapshot_uuid)
@handle_pithos_backend
def update_status(self, image_uuid, status):
"""Update status of snapshot"""
location, _ = self._get_raw_metadata(image_uuid)
properties = {"status": status.upper()}
self._update_metadata(image_uuid, location, properties, replace=False)
return self._get_image(image_uuid)
def create_url(account, container, name):
"""Create a Pithos URL from the object info"""
......
......@@ -103,3 +103,8 @@ def volume_to_links(volume_id):
def snapshot_to_links(snapshot_id):
href = join_urls(SNAPSHOTS_URL, str(snapshot_id))
return [{"rel": rel, "href": href} for rel in ("self", "bookmark")]
def update_snapshot_status(snapshot_id, user_id, status):
with backend.PlanktonBackend(user_id) as b:
return b.update_status(snapshot_id, status=status)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment