Skip to content

Commit

Permalink
Merge pull request #440 from mmojzis/snapshot_import_functions
Browse files Browse the repository at this point in the history
[RFR]Added register_image method for EC2System
  • Loading branch information
mshriver authored Apr 27, 2020
2 parents 32e54b0 + d41fb13 commit 1952511
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions wrapanapi/systems/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,3 +1517,26 @@ def get_snapshot_id_if_import_completed(self, task_id):
return result.get("SnapshotId")
else:
return False

def create_image_from_snapshot(self, name, snapshot_id, architecture='x86_64', ena_support=True,
virtualization_type='hvm', device_name='/dev/sda1'):
try:
ami_id = self.ec2_connection.register_image(Name=name,
Architecture=architecture,
VirtualizationType=virtualization_type,
RootDeviceName=device_name,
EnaSupport=ena_support,
BlockDeviceMappings=[
{
'DeviceName': device_name,
'Ebs':
{
'SnapshotId': snapshot_id,
'DeleteOnTermination': True
}
}
])
return ami_id
except Exception:
self.logger.exception("Creation of image from snapshot '%s' failed.", snapshot_id)
return False

0 comments on commit 1952511

Please sign in to comment.