Skip to content

Commit c465db4

Browse files
committed
Fixes order of operations when searching a container
1 parent 6f50b89 commit c465db4

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

cloudimg/aws.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,18 @@ def create_container(self, name, prop_delay=60):
486486
time.sleep(prop_delay)
487487

488488
return container
489+
490+
def ensure_container_exists(self, container_name):
491+
"""
492+
Ensures that a container exists in AWS. If it doesn't exist it will
493+
try to create it.
494+
495+
Args:
496+
container_name (str): The container to check for
497+
"""
498+
container = self.get_container_by_name(container_name)
499+
if not container:
500+
container = self.create_container(container_name)
489501

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

512-
# Get or create the container
513-
container = self.get_container_by_name(container_name)
514-
if not container:
515-
container = self.create_container(container_name)
524+
self.ensure_container_exists(container_name)
516525

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

599608
if not snapshot:
609+
self.ensure_container_exists(metadata.container)
600610
log.info('Snapshot does not exist: %s', metadata.snapshot_name)
601611
log.info('Searching for object: %s/%s',
602612
metadata.container, metadata.object_name)

0 commit comments

Comments
 (0)