Skip to content

Commit

Permalink
Added snapshot import functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Matous Mojzis committed Jan 28, 2020
1 parent 883a73d commit 79f4dc9
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 79f4dc9

Please sign in to comment.