Commit 2b6c70f9 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Check image and snapshots states

When creating a volume from an image or snapshot we must check that
the image/snapshot is in 'AVAILABLE' status.
parent 5dc49413
......@@ -331,6 +331,7 @@ fixed_image.return_value = {'location': 'pithos://foo',
"name": "test_image",
"size": 1024,
"is_snapshot": False,
"status": "AVAILABLE",
'disk_format': 'diskdump'}
......
......@@ -178,6 +178,7 @@ def get_image_dict(image_id, user_id):
image["format"] = img["disk_format"]
image["location"] = img["location"]
image["is_snapshot"] = img["is_snapshot"]
image["status"] = img["status"]
size = image["size"] = img["size"]
mapfile = img["mapfile"]
......
......@@ -46,6 +46,7 @@ fixed_image.return_value = {'location': 'pithos://foo',
'mapfile': 'test_mapfile',
"id": 1,
"name": "test_image",
"status": "AVAILABLE",
"size": 1024,
"is_snapshot": False,
'disk_format': 'diskdump'}
......
......@@ -35,6 +35,9 @@ def create(user_id, volume, name, description, metadata, force=False):
# Check that taking a snapshot is feasible
if volume.machine is None:
raise faults.BadRequest("Cannot snapshot a detached volume!")
if volume.status not in ["AVAILABLE", "IN_USE"]:
raise faults.BadRequest("Cannot create snapshot while volume is in"
" '%s' status" % volume.status)
flavor = volume.machine.flavor
if not flavor.disk_template.startswith("ext_"):
......
......@@ -85,6 +85,11 @@ def _create_volume(server, user_id, size, source_type, source_uuid,
elif source_type == "snapshot":
source_snapshot = util.get_snapshot(user_id, source_uuid,
exception=faults.BadRequest)
snap_status = source_snapshot.get("status", "").upper()
if snap_status != "AVAILABLE":
raise faults.BadRequest("Cannot create volume from snapshot, while"
" snapshot is in '%s' status" %
snap_status)
source = Volume.prefix_source(source_uuid,
source_type="snapshot")
if size is None:
......@@ -97,6 +102,10 @@ def _create_volume(server, user_id, size, source_type, source_uuid,
elif source_type == "image":
source_image = util.get_image(user_id, source_uuid,
exception=faults.BadRequest)
img_status = source_image.get("status", "").upper()
if img_status != "AVAILABLE":
raise faults.BadRequest("Cannot create volume from image, while"
" image is in '%s' status" % img_status)
if size is None:
raise faults.BadRequest("Volume size is required")
elif (size << 30) < int(source_image["size"]):
......
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