Don't create volumes for AMIs (#1456)
* Delete the volume used during AMI creation Creating an AMI doesn't actually result in the creation of an EBS volume, although the associated snapshot does reference one. To that end, delete the volume once we've used it. * Add `owner_id` to `Snapshot`, verify AMI snapshots The default AMIs which are created by moto have EBS volume mappings but the snapshots associated with those don't have the correct owners set. This adds the owner to the snapshot model and passes it through from the JSON data.
This commit is contained in:
parent
39e9379195
commit
5d51329c34
3 changed files with 54 additions and 20 deletions
|
|
@ -1088,7 +1088,8 @@ class Ami(TaggedEC2Resource):
|
|||
# AWS auto-creates these, we should reflect the same.
|
||||
volume = self.ec2_backend.create_volume(15, region_name)
|
||||
self.ebs_snapshot = self.ec2_backend.create_snapshot(
|
||||
volume.id, "Auto-created snapshot for AMI %s" % self.id)
|
||||
volume.id, "Auto-created snapshot for AMI %s" % self.id, owner_id)
|
||||
self.ec2_backend.delete_volume(volume.id)
|
||||
|
||||
@property
|
||||
def is_public(self):
|
||||
|
|
@ -1840,7 +1841,7 @@ class Volume(TaggedEC2Resource):
|
|||
|
||||
|
||||
class Snapshot(TaggedEC2Resource):
|
||||
def __init__(self, ec2_backend, snapshot_id, volume, description, encrypted=False):
|
||||
def __init__(self, ec2_backend, snapshot_id, volume, description, encrypted=False, owner_id='123456789012'):
|
||||
self.id = snapshot_id
|
||||
self.volume = volume
|
||||
self.description = description
|
||||
|
|
@ -1849,6 +1850,7 @@ class Snapshot(TaggedEC2Resource):
|
|||
self.ec2_backend = ec2_backend
|
||||
self.status = 'completed'
|
||||
self.encrypted = encrypted
|
||||
self.owner_id = owner_id
|
||||
|
||||
def get_filter_value(self, filter_name):
|
||||
if filter_name == 'description':
|
||||
|
|
@ -1940,11 +1942,13 @@ class EBSBackend(object):
|
|||
volume.attachment = None
|
||||
return old_attachment
|
||||
|
||||
def create_snapshot(self, volume_id, description):
|
||||
def create_snapshot(self, volume_id, description, owner_id=None):
|
||||
snapshot_id = random_snapshot_id()
|
||||
volume = self.get_volume(volume_id)
|
||||
snapshot = Snapshot(self, snapshot_id, volume,
|
||||
description, volume.encrypted)
|
||||
params = [self, snapshot_id, volume, description, volume.encrypted]
|
||||
if owner_id:
|
||||
params.append(owner_id)
|
||||
snapshot = Snapshot(*params)
|
||||
self.snapshots[snapshot_id] = snapshot
|
||||
return snapshot
|
||||
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ CREATE_SNAPSHOT_RESPONSE = """<CreateSnapshotResponse xmlns="http://ec2.amazonaw
|
|||
<status>pending</status>
|
||||
<startTime>{{ snapshot.start_time}}</startTime>
|
||||
<progress>60%</progress>
|
||||
<ownerId>123456789012</ownerId>
|
||||
<ownerId>{{ snapshot.owner_id }}</ownerId>
|
||||
<volumeSize>{{ snapshot.volume.size }}</volumeSize>
|
||||
<description>{{ snapshot.description }}</description>
|
||||
<encrypted>{{ snapshot.encrypted }}</encrypted>
|
||||
|
|
@ -245,7 +245,7 @@ DESCRIBE_SNAPSHOTS_RESPONSE = """<DescribeSnapshotsResponse xmlns="http://ec2.am
|
|||
<status>{{ snapshot.status }}</status>
|
||||
<startTime>{{ snapshot.start_time}}</startTime>
|
||||
<progress>100%</progress>
|
||||
<ownerId>123456789012</ownerId>
|
||||
<ownerId>{{ snapshot.owner_id }}</ownerId>
|
||||
<volumeSize>{{ snapshot.volume.size }}</volumeSize>
|
||||
<description>{{ snapshot.description }}</description>
|
||||
<encrypted>{{ snapshot.encrypted }}</encrypted>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue