Skip to content

Commit

Permalink
AWS: Add a warning when the snapshot returns >1
Browse files Browse the repository at this point in the history
The AWSService method `get_snapshot`by_name` expects the result
to be unique, as it will blindly return the first element of the list.

This commit adds a warning to log the case which the filter didn't
 return a list of single snapshot.
  • Loading branch information
JAVGan committed Nov 11, 2024
1 parent 3fd0a81 commit 683c82d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cloudimg/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ def get_snapshot_by_name(self, name):

if not snapshots:
return None
elif len(snapshots) > 1:
snaps = [x['SnapshotId'] for x in snapshots]
log.warning(
"Filtered more than one snapshot: %s",
", ".join(snaps),
)

return self.ec2.Snapshot(snapshots[0]['SnapshotId'])

Expand Down

0 comments on commit 683c82d

Please sign in to comment.