Skip to content

Commit de10fe1

Browse files
committed
ore/aws/delete-image: Handle missing SnapshotID
Added a check for when the snapshotID is None by giving it the value of detectFromAMI. Then we aim to determine the snapshot by seeing if we have any associated with the AMI-ID. If nothing shows up, we define it as pruned
1 parent 3a76784 commit de10fe1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

mantle/cmd/ore/aws/delete-image.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ func runDeleteImage(cmd *cobra.Command, args []string) {
5757
}
5858

5959
if snapshotID != "" {
60+
if snapshotID == "detectFromAMI" && amiID != "" {
61+
// Let's try to extract the snapshotID from AMI
62+
snapshot, err := API.FindSnapshot(amiID)
63+
if err != nil {
64+
fmt.Fprintf(os.Stderr, "Warning: Encountered error when searching for snapshot for %s: %s. Continuing..\n", amiID, err)
65+
os.Exit(0)
66+
} else if snapshot == nil {
67+
fmt.Fprintf(os.Stdout, "No valid snapshot found for %s.\n", amiID)
68+
os.Exit(0)
69+
}
70+
snapshotID = snapshot.SnapshotID
71+
}
6072
err := API.RemoveBySnapshotTag(snapshotID, allowMissing)
6173
if err != nil {
6274
fmt.Fprintf(os.Stderr, "Could not delete %v: %v\n", snapshotID, err)

src/cmd-cloud-prune

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ def deregister_aws_amis(build, cloud_config, dry_run):
324324
for ami in amis:
325325
region_name = ami.get("name")
326326
ami_id = ami.get("hvm")
327-
snapshot_id = ami.get("snapshot")
327+
# If we are dealing with an old manifest where the snapshot ID isn't stored
328+
# then let's instruct ore to detect the snapshot ID from the AMI.
329+
snapshot_id = ami.get("snapshot", "detectFromAMI")
328330
if dry_run:
329331
print(f"Would delete {ami_id} and {snapshot_id} for {build.id}")
330332
continue

0 commit comments

Comments
 (0)