Skip to content
Open
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
15 changes: 14 additions & 1 deletion cloudimg/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def get_image_by_filters(self, filters):
images = rsp['Images']

if not images:
log.debug("No images returned for the filters %s", filters)
return None
elif len(images) > 1:
amis = [x['ImageId'] for x in images]
Expand Down Expand Up @@ -276,6 +277,7 @@ def get_image_from_ami_catalog(self, image_id):
images = rsp["Images"]

if not images:
log.debug("No image with ID %s found.", image_id)
return None

return self.ec2.Image(images[0]["ImageId"])
Expand All @@ -291,6 +293,7 @@ def get_image_by_name(self, name):
An EC2 Image if found; None otherwise
"""
if not name:
log.debug("Name not provided to search for the image.")
return None

filters = [
Expand All @@ -313,6 +316,7 @@ def get_image_by_tags(self, tags):
An EC2 Image if found; None otherwise
"""
if not tags:
log.debug("Tags not provided to search for the image.")
return None

filters = [
Expand All @@ -336,6 +340,7 @@ def get_image_by_id(self, image_id):
An EC2 Image if found; None otherwise
"""
if not image_id:
log.debug("Image ID not provided to search for the image.")
return None

filters = [
Expand All @@ -358,6 +363,7 @@ def get_snapshot_by_name(self, name):
An EC2 Snapshot if found; None otherwise
"""
if not name:
log.debug("Name not provided to search for the snapshot.")
return None

rsp = self.ec2.meta.client.describe_snapshots(
Expand All @@ -371,6 +377,7 @@ def get_snapshot_by_name(self, name):
snapshots = rsp['Snapshots']

if not snapshots:
log.debug("No snapshot found with name %s.", name)
return None
elif len(snapshots) > 1:
snaps = [x['SnapshotId'] for x in snapshots]
Expand All @@ -392,6 +399,7 @@ def get_snapshot_by_id(self, snapshot_id):
An EC2 Snapshot if found; None otherwise
"""
if not snapshot_id:
log.debug("ID not provided to search for the snapshot.")
return None

rsp = self.ec2.meta.client.describe_snapshots(
Expand All @@ -405,6 +413,7 @@ def get_snapshot_by_id(self, snapshot_id):
snapshots = rsp['Snapshots']

if not snapshots:
log.debug("No snapshot found with ID %s.", snapshot_id)
return None

return self.ec2.Snapshot(snapshots[0]['SnapshotId'])
Expand Down Expand Up @@ -595,9 +604,13 @@ def add_tags(tag_parameter_name, extra_kwargs):
extra_kwargs.update({"tags": new_tags})

log.info('Searching for image: %s', metadata.image_name)
merged_ami_tags = {
**(metadata.tags or {}),
**(metadata.ami_tags or {}),
}
image = (
self.get_image_by_name(metadata.image_name) or
self.get_image_by_tags(metadata.tags)
self.get_image_by_tags(merged_ami_tags)
)

if not image:
Expand Down