Add ability to create EBS volumes from snapshots. Closes #447.
This commit is contained in:
parent
d3e4c2c4b5
commit
cddf139bbc
3 changed files with 39 additions and 8 deletions
|
|
@ -1388,12 +1388,13 @@ class VolumeAttachment(object):
|
|||
|
||||
|
||||
class Volume(TaggedEC2Resource):
|
||||
def __init__(self, ec2_backend, volume_id, size, zone):
|
||||
def __init__(self, ec2_backend, volume_id, size, zone, snapshot_id=None):
|
||||
self.id = volume_id
|
||||
self.size = size
|
||||
self.zone = zone
|
||||
self.create_time = utc_date_and_time()
|
||||
self.attachment = None
|
||||
self.snapshot_id = snapshot_id
|
||||
self.ec2_backend = ec2_backend
|
||||
|
||||
@classmethod
|
||||
|
|
@ -1436,10 +1437,14 @@ class EBSBackend(object):
|
|||
self.snapshots = {}
|
||||
super(EBSBackend, self).__init__()
|
||||
|
||||
def create_volume(self, size, zone_name):
|
||||
def create_volume(self, size, zone_name, snapshot_id=None):
|
||||
volume_id = random_volume_id()
|
||||
zone = self.get_zone_by_name(zone_name)
|
||||
volume = Volume(self, volume_id, size, zone)
|
||||
if snapshot_id:
|
||||
snapshot = self.get_snapshot(snapshot_id)
|
||||
if size is None:
|
||||
size = snapshot.volume.size
|
||||
volume = Volume(self, volume_id, size, zone, snapshot_id)
|
||||
self.volumes[volume_id] = volume
|
||||
return volume
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue