Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions cloudimg/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,18 @@ def create_container(self, name, prop_delay=60):

return container

def ensure_container_exists(self, container_name):
"""
Ensures that a container exists in AWS. If it doesn't exist it will
try to create it.

Args:
container_name (str): The container to check for
"""
container = self.get_container_by_name(container_name)
if not container:
container = self.create_container(container_name)

def upload_to_container(self, image_path, container_name, object_name,
chunk_size=CHUNK_SIZE, tags=None):
"""
Expand All @@ -509,10 +521,7 @@ def upload_to_container(self, image_path, container_name, object_name,
log.info('Uploading %s to container %s', image_path, container_name)
log.info('Uploading %s with name %s', image_path, object_name)

# Get or create the container
container = self.get_container_by_name(container_name)
if not container:
container = self.create_container(container_name)
self.ensure_container_exists(container_name)

if image_path.lower().startswith('http'):
# Stream the upload from a remote URL
Expand Down Expand Up @@ -597,6 +606,7 @@ def add_tags(tag_parameter_name, extra_kwargs):
snapshot = self.get_snapshot_by_name(metadata.snapshot_name)

if not snapshot:
self.ensure_container_exists(metadata.container)
log.info('Snapshot does not exist: %s', metadata.snapshot_name)
log.info('Searching for object: %s/%s',
metadata.container, metadata.object_name)
Expand Down