Commit 264f73c7 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Reject volume reassign on pending action

Use validate_server_action() to make sure that the volume's reassignment
fails when another VM action is pending. For example, that you cannot
reassign a volume if the VM (and the volume) is being destroyed.
parent dddff57c
...@@ -20,7 +20,7 @@ from django.conf import settings ...@@ -20,7 +20,7 @@ from django.conf import settings
from snf_django.lib.api import faults from snf_django.lib.api import faults
from synnefo.db.models import Volume, VolumeMetadata from synnefo.db.models import Volume, VolumeMetadata
from synnefo.volume import util from synnefo.volume import util
from synnefo.logic import server_attachments, utils from synnefo.logic import server_attachments, utils, commands
from synnefo import quotas from synnefo import quotas
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -246,6 +246,11 @@ def reassign_volume(volume, project): ...@@ -246,6 +246,11 @@ def reassign_volume(volume, project):
if volume.index == 0: if volume.index == 0:
raise faults.Conflict("Cannot reassign: %s is a system volume" % raise faults.Conflict("Cannot reassign: %s is a system volume" %
volume.id) volume.id)
if volume.machine_id is not None:
server = util.get_server(volume.userid, volume.machine_id,
for_update=True, non_deleted=True,
exception=faults.BadRequest)
commands.validate_server_action(server, "REASSIGN")
action_fields = {"from_project": volume.project, "to_project": project} action_fields = {"from_project": volume.project, "to_project": project}
log.info("Reassigning volume %s from project %s to %s", log.info("Reassigning volume %s from project %s to %s",
volume.id, volume.project, project) volume.id, volume.project, project)
......
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