Skip to content

Commit

Permalink
Merge pull request #434 from mmojzis/snapshot_import_functions
Browse files Browse the repository at this point in the history
[RFR]Added ec2 snapshot import functions
  • Loading branch information
mshriver authored Feb 5, 2020
2 parents 6d3ea5b + 79f4dc9 commit d968deb
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions wrapanapi/systems/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,3 +1471,39 @@ def set_sns_topic_target_for_all_cw_rules(self, topic_arn):
return True
except Exception:
return False

def import_snapshot(self, s3bucket, s3key, format="vhd", description=None):
self.logger.info(
" Importing snapshot %s from %s bucket with description %s in %s started successfully.",
s3key, s3bucket, description, format
)
try:
result = self.ec2_connection.import_snapshot(
DiskContainer={
'Description': description if description is not None else s3key,
'Format': format,
'UserBucket': {
'S3Bucket': s3bucket,
'S3Key': s3key
}
}
)
task_id = result.get("ImportTaskId")
return task_id

except Exception:
self.logger.exception("Import of snapshot '%s' failed.", s3key)
return False

def get_import_snapshot_task(self, task_id):
result = self.ec2_connection.describe_import_snapshot_tasks(ImportTaskIds=[task_id])
result_task = result.get("ImportSnapshotTasks")
return result_task[0]

def get_snapshot_id_if_import_completed(self, task_id):
result = self.get_import_snapshot_task(task_id).get('SnapshotTaskDetail')
result_status = result.get("Status")
if result_status == 'completed':
return result.get("SnapshotId")
else:
return False

0 comments on commit d968deb

Please sign in to comment.