Add volume attachment status
This commit is contained in:
parent
1f618a3cb5
commit
b4176050e2
@ -1513,11 +1513,12 @@ class SecurityGroupIngress(object):
|
||||
|
||||
|
||||
class VolumeAttachment(object):
|
||||
def __init__(self, volume, instance, device):
|
||||
def __init__(self, volume, instance, device, status):
|
||||
self.volume = volume
|
||||
self.attach_time = utc_date_and_time()
|
||||
self.instance = instance
|
||||
self.device = device
|
||||
self.status = status
|
||||
|
||||
@classmethod
|
||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||
@ -1578,6 +1579,8 @@ class Volume(TaggedEC2Resource):
|
||||
return self.attachment.device
|
||||
if filter_name == 'attachment.instance-id':
|
||||
return self.attachment.instance.id
|
||||
if filter_name == 'attachment.status':
|
||||
return self.attachment.status
|
||||
|
||||
if filter_name == 'create-time':
|
||||
return self.create_time
|
||||
@ -1688,7 +1691,7 @@ class EBSBackend(object):
|
||||
if not volume or not instance:
|
||||
return False
|
||||
|
||||
volume.attachment = VolumeAttachment(volume, instance, device_path)
|
||||
volume.attachment = VolumeAttachment(volume, instance, device_path, 'attached')
|
||||
# Modify instance to capture mount of block device.
|
||||
bdt = BlockDeviceType(volume_id=volume_id, status=volume.status, size=volume.size,
|
||||
attach_time=utc_date_and_time())
|
||||
@ -1702,6 +1705,7 @@ class EBSBackend(object):
|
||||
old_attachment = volume.attachment
|
||||
if not old_attachment:
|
||||
raise InvalidVolumeAttachmentError(volume_id, instance_id)
|
||||
old_attachment.status = 'detached'
|
||||
|
||||
volume.attachment = None
|
||||
return old_attachment
|
||||
|
@ -93,6 +93,9 @@ def test_volume_filters():
|
||||
volumes_by_attach_instance_id = conn.get_all_volumes(filters={'attachment.instance-id': instance.id})
|
||||
set([vol.id for vol in volumes_by_attach_instance_id]).should.equal(set([block_mapping.volume_id]))
|
||||
|
||||
volumes_by_attach_status = conn.get_all_volumes(filters={'attachment.status': 'attached'})
|
||||
set([vol.id for vol in volumes_by_attach_status]).should.equal(set([block_mapping.volume_id]))
|
||||
|
||||
volumes_by_create_time = conn.get_all_volumes(filters={'create-time': volume4.create_time})
|
||||
set([vol.create_time for vol in volumes_by_create_time]).should.equal(set([volume4.create_time]))
|
||||
|
||||
@ -142,6 +145,7 @@ def test_volume_attach_and_detach():
|
||||
|
||||
volume.update()
|
||||
volume.volume_state().should.equal('in-use')
|
||||
volume.attachment_state().should.equal('attached')
|
||||
|
||||
volume.attach_data.instance_id.should.equal(instance.id)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user