implementing mockable EBS snapshot copies
This commit is contained in:
parent
783504c897
commit
a44b7e7f5c
@ -1971,6 +1971,15 @@ class EBSBackend(object):
|
|||||||
matches = generic_filter(filters, matches)
|
matches = generic_filter(filters, matches)
|
||||||
return matches
|
return matches
|
||||||
|
|
||||||
|
def copy_snapshot(self, source_snapshot_id, source_region, description=None):
|
||||||
|
source_snapshot = ec2_backends[source_region].describe_snapshots(
|
||||||
|
snapshot_ids=[source_snapshot_id])[0]
|
||||||
|
snapshot_id = random_snapshot_id()
|
||||||
|
snapshot = Snapshot(self, snapshot_id, volume=source_snapshot.volume,
|
||||||
|
description=description, encrypted=source_snapshot.encrypted)
|
||||||
|
self.snapshots[snapshot_id] = snapshot
|
||||||
|
return snapshot
|
||||||
|
|
||||||
def get_snapshot(self, snapshot_id):
|
def get_snapshot(self, snapshot_id):
|
||||||
snapshot = self.snapshots.get(snapshot_id, None)
|
snapshot = self.snapshots.get(snapshot_id, None)
|
||||||
if not snapshot:
|
if not snapshot:
|
||||||
|
@ -16,9 +16,14 @@ class ElasticBlockStore(BaseResponse):
|
|||||||
return template.render(attachment=attachment)
|
return template.render(attachment=attachment)
|
||||||
|
|
||||||
def copy_snapshot(self):
|
def copy_snapshot(self):
|
||||||
|
source_snapshot_id = self._get_param('SourceSnapshotId')
|
||||||
|
source_region = self._get_param('SourceRegion')
|
||||||
|
description = self._get_param('Description')
|
||||||
if self.is_not_dryrun('CopySnapshot'):
|
if self.is_not_dryrun('CopySnapshot'):
|
||||||
raise NotImplementedError(
|
snapshot = self.ec2_backend.copy_snapshot(
|
||||||
'ElasticBlockStore.copy_snapshot is not yet implemented')
|
source_snapshot_id, source_region, description)
|
||||||
|
template = self.response_template(COPY_SNAPSHOT_RESPONSE)
|
||||||
|
return template.render(snapshot=snapshot)
|
||||||
|
|
||||||
def create_snapshot(self):
|
def create_snapshot(self):
|
||||||
volume_id = self._get_param('VolumeId')
|
volume_id = self._get_param('VolumeId')
|
||||||
@ -248,6 +253,11 @@ CREATE_SNAPSHOT_RESPONSE = """<CreateSnapshotResponse xmlns="http://ec2.amazonaw
|
|||||||
</tagSet>
|
</tagSet>
|
||||||
</CreateSnapshotResponse>"""
|
</CreateSnapshotResponse>"""
|
||||||
|
|
||||||
|
COPY_SNAPSHOT_RESPONSE = """<CopySnapshotResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
|
||||||
|
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||||
|
<snapshotId>{{ snapshot.id }}</snapshotId>
|
||||||
|
</CopySnapshotResponse>"""
|
||||||
|
|
||||||
DESCRIBE_SNAPSHOTS_RESPONSE = """<DescribeSnapshotsResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
DESCRIBE_SNAPSHOTS_RESPONSE = """<DescribeSnapshotsResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
||||||
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||||
<snapshotSet>
|
<snapshotSet>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user