Correct response when trying to delete a volume that is attached to an EC2 instance. Created a VolumeInUse error and did a simple check on the delete_volume method.
This commit is contained in:
parent
584352aaf6
commit
4a402b01cf
@ -244,6 +244,15 @@ class InvalidVolumeAttachmentError(EC2ClientError):
|
|||||||
.format(volume_id, instance_id))
|
.format(volume_id, instance_id))
|
||||||
|
|
||||||
|
|
||||||
|
class VolumeInUseError(EC2ClientError):
|
||||||
|
|
||||||
|
def __init__(self, volume_id, instance_id):
|
||||||
|
super(VolumeInUseError, self).__init__(
|
||||||
|
"VolumeInUse",
|
||||||
|
"Volume {0} is currently attached to {1}"
|
||||||
|
.format(volume_id, instance_id))
|
||||||
|
|
||||||
|
|
||||||
class InvalidDomainError(EC2ClientError):
|
class InvalidDomainError(EC2ClientError):
|
||||||
|
|
||||||
def __init__(self, domain):
|
def __init__(self, domain):
|
||||||
|
@ -45,6 +45,7 @@ from .exceptions import (
|
|||||||
InvalidAMIAttributeItemValueError,
|
InvalidAMIAttributeItemValueError,
|
||||||
InvalidSnapshotIdError,
|
InvalidSnapshotIdError,
|
||||||
InvalidVolumeIdError,
|
InvalidVolumeIdError,
|
||||||
|
VolumeInUseError,
|
||||||
InvalidVolumeAttachmentError,
|
InvalidVolumeAttachmentError,
|
||||||
InvalidDomainError,
|
InvalidDomainError,
|
||||||
InvalidAddressError,
|
InvalidAddressError,
|
||||||
@ -1813,6 +1814,10 @@ class EBSBackend(object):
|
|||||||
|
|
||||||
def delete_volume(self, volume_id):
|
def delete_volume(self, volume_id):
|
||||||
if volume_id in self.volumes:
|
if volume_id in self.volumes:
|
||||||
|
volume = self.volumes[volume_id]
|
||||||
|
instance_id = volume.attachment.instance.id
|
||||||
|
if volume.attachment is not None:
|
||||||
|
raise VolumeInUseError(volume_id, instance_id)
|
||||||
return self.volumes.pop(volume_id)
|
return self.volumes.pop(volume_id)
|
||||||
raise InvalidVolumeIdError(volume_id)
|
raise InvalidVolumeIdError(volume_id)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user