diff --git a/cloudimg/aws.py b/cloudimg/aws.py index d8db352..2a06cd5 100644 --- a/cloudimg/aws.py +++ b/cloudimg/aws.py @@ -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] @@ -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"]) @@ -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 = [ @@ -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 = [ @@ -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 = [ @@ -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( @@ -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] @@ -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( @@ -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']) @@ -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: