Skip to content

Commit c8b819a

Browse files
committed
ore/aws: add helper to get AWS snapshot size
Add `FindSnapshotDiskSizeGiB` to retrieve the volume size for a given snapshot ID, to be used when a snapshot is provided for AMI creation.
1 parent 8f58c28 commit c8b819a

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

mantle/cmd/ore/aws/upload.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func runUpload(cmd *cobra.Command, args []string) error {
157157
os.Exit(2)
158158
}
159159

160+
var err error
160161
if uploadDiskSizeInspect {
161162
imageInfo, err := util.GetImageInfo(uploadFile)
162163
if err != nil {
@@ -172,8 +173,15 @@ func runUpload(cmd *cobra.Command, args []string) error {
172173
}
173174
}
174175

176+
if uploadSourceSnapshot != "" {
177+
uploadDiskSizeGiB, err = API.FindSnapshotDiskSizeGiB(uploadSourceSnapshot)
178+
if err != nil {
179+
fmt.Fprintf(os.Stderr, "Unable to query size of disk from snapshot: %v\n", err)
180+
os.Exit(1)
181+
}
182+
}
183+
175184
var s3URL *url.URL
176-
var err error
177185
if uploadSourceObject != "" {
178186
s3URL, err = url.Parse(uploadSourceObject)
179187
if err != nil {

mantle/platform/api/aws/images.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,3 +852,18 @@ func getImageSnapshotID(image *ec2.Image) (string, error) {
852852
// and it's just a sorta eventual consistency thing
853853
return "", fmt.Errorf("no backing block device for %v", image.ImageId)
854854
}
855+
856+
func (a *API) FindSnapshotDiskSizeGiB(snapshotID string) (uint, error) {
857+
result, err := a.ec2.DescribeSnapshots(&ec2.DescribeSnapshotsInput{
858+
SnapshotIds: []*string{&snapshotID},
859+
})
860+
if err != nil {
861+
return 0, fmt.Errorf("failed to describe snapshot: %v", err)
862+
}
863+
864+
if len(result.Snapshots) == 0 {
865+
return 0, fmt.Errorf("no snapshot found with ID %s", snapshotID)
866+
}
867+
868+
return uint(aws.Int64Value(result.Snapshots[0].VolumeSize)), nil
869+
}

src/cosalib/aws.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ def aws_run_ore(build, args):
157157
'--billing-product-code', f"{args.winli_billing_product}"
158158
])
159159
else:
160-
ore_args.extend([
161-
'--disk-size-inspect'
162-
])
160+
ore_args.extend(['--disk-size-inspect'])
163161
winli_name = ""
164162
winli_description = ""
165163
buildmeta_key = "amis"

0 commit comments

Comments
 (0)