Skip to content

Commit 04de405

Browse files
committed
mantle/aws: rework AWS Windows LI image creation
partially revert and rework d3688be, 0791319, a1f8d97. and 1834b07. Rework the aws-winli creation logic to use `aws ec2 register-image --billing-product` to create the AMI with the Windows License Included billing code metadata. This simplifies the creation logic and removes the need for swapping the root volume of an instance. Instead, add a `imageupload-aws` and ore argument `--winli-billing-product` to set the billing product code during image creation. Setting billing product codes is limited to approved AWS accounts, so this will only be used to create the RHCOS aws-winli image.
1 parent 89a63a5 commit 04de405

File tree

5 files changed

+55
-517
lines changed

5 files changed

+55
-517
lines changed

mantle/cmd/ore/aws/upload.go

Lines changed: 42 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,28 @@ After a successful run, the final line of output will be a line of JSON describi
4747
SilenceUsage: true,
4848
}
4949

50-
uploadSourceObject string
51-
uploadBucket string
52-
uploadImageName string
53-
uploadImageArchitecture string
54-
uploadFile string
55-
uploadDiskSizeGiB uint
56-
uploadDiskSizeInspect bool
57-
uploadDeleteObject bool
58-
uploadForce bool
59-
uploadSourceSnapshot string
60-
uploadObjectFormat aws.EC2ImageFormat
61-
uploadAMIName string
62-
uploadAMIDescription string
63-
uploadPublic bool
64-
uploadGrantUsers []string
65-
uploadGrantUsersSnapshot []string
66-
uploadTags []string
67-
uploadIMDSv2Only bool
68-
uploadVolumeType string
69-
uploadX86BootMode string
70-
uploadCreateWinLIAMI bool
71-
uploadWinLIwindowsServerAMI string
72-
uploadWinLIInstanceType string
50+
uploadSourceObject string
51+
uploadBucket string
52+
uploadImageName string
53+
uploadImageArchitecture string
54+
uploadFile string
55+
uploadDiskSizeGiB uint
56+
uploadDiskSizeInspect bool
57+
uploadDeleteObject bool
58+
uploadForce bool
59+
uploadSourceSnapshot string
60+
uploadObjectFormat aws.EC2ImageFormat
61+
uploadAMIName string
62+
uploadAMIDescription string
63+
uploadPublic bool
64+
uploadGrantUsers []string
65+
uploadGrantUsersSnapshot []string
66+
uploadTags []string
67+
uploadIMDSv2Only bool
68+
uploadVolumeType string
69+
uploadX86BootMode string
70+
uploadCreateWinLIAMI bool
71+
uploadWinLIBillingProduct string
7372
)
7473

7574
func init() {
@@ -95,8 +94,7 @@ func init() {
9594
cmdUpload.Flags().StringVar(&uploadVolumeType, "volume-type", "gp3", "EBS volume type (gp3, gp2, io1, st1, sc1, standard, etc.)")
9695
cmdUpload.Flags().StringVar(&uploadX86BootMode, "x86-boot-mode", "uefi-preferred", "Set boot mode (uefi-preferred, uefi)")
9796
cmdUpload.Flags().BoolVar(&uploadCreateWinLIAMI, "winli", false, "Create a Windows LI AMI")
98-
cmdUpload.Flags().StringVar(&uploadWinLIwindowsServerAMI, "windows-ami", "", "Windows Server AMI used to create a Windows LI AMI")
99-
cmdUpload.Flags().StringVar(&uploadWinLIInstanceType, "winli-instance-type", "t2.large", "ec2 instance type used to create a Windows LI AMI")
97+
cmdUpload.Flags().StringVar(&uploadWinLIBillingProduct, "winli-billing-product", "", "Windows billing product code used to create a Windows LI AMI")
10098
}
10199

102100
func defaultBucketNameForRegion(region string) string {
@@ -140,10 +138,18 @@ func runUpload(cmd *cobra.Command, args []string) error {
140138
fmt.Fprintf(os.Stderr, "Unrecognized args in aws upload cmd: %v\n", args)
141139
os.Exit(2)
142140
}
141+
if uploadSourceObject != "" && uploadSourceSnapshot != "" {
142+
fmt.Fprintf(os.Stderr, "At most one of --source-object and --source-snapshot may be specified.\n")
143+
os.Exit(2)
144+
}
143145
if uploadDiskSizeInspect && (uploadSourceObject != "" || uploadSourceSnapshot != "") {
144146
fmt.Fprintf(os.Stderr, "--disk-size-inspect cannot be used with --source-object or --source-snapshot.\n")
145147
os.Exit(2)
146148
}
149+
if uploadFile == "" && !uploadCreateWinLIAMI {
150+
fmt.Fprintf(os.Stderr, "specify --file\n")
151+
os.Exit(2)
152+
}
147153
if uploadImageName == "" {
148154
fmt.Fprintf(os.Stderr, "unknown image name; specify --name\n")
149155
os.Exit(2)
@@ -152,24 +158,13 @@ func runUpload(cmd *cobra.Command, args []string) error {
152158
fmt.Fprintf(os.Stderr, "unknown AMI name; specify --ami-name\n")
153159
os.Exit(2)
154160
}
155-
if uploadCreateWinLIAMI {
156-
if uploadWinLIwindowsServerAMI == "" {
157-
fmt.Fprintf(os.Stderr, "--windows-ami must be provided with --winli\n")
158-
os.Exit(2)
159-
}
160-
if uploadSourceSnapshot == "" {
161-
fmt.Fprintf(os.Stderr, "--source-snapshot must be provided with --winli\n")
162-
os.Exit(2)
163-
}
164-
} else {
165-
if uploadSourceObject != "" && uploadSourceSnapshot != "" {
166-
fmt.Fprintf(os.Stderr, "At most one of --source-object and --source-snapshot may be specified.\n")
167-
os.Exit(2)
168-
}
169-
if uploadFile == "" {
170-
fmt.Fprintf(os.Stderr, "specify --file\n")
171-
os.Exit(2)
172-
}
161+
if uploadWinLIBillingProduct != "" && !uploadCreateWinLIAMI {
162+
fmt.Fprintf(os.Stderr, "--winli-billing-product can only be used with --winli\n")
163+
os.Exit(2)
164+
}
165+
if uploadCreateWinLIAMI && uploadSourceSnapshot == "" {
166+
fmt.Fprintf(os.Stderr, "unknown source snapshot; specify --source-snapshot\n")
167+
os.Exit(2)
173168
}
174169

175170
var err error
@@ -270,20 +265,10 @@ func runUpload(cmd *cobra.Command, args []string) error {
270265
}
271266
}
272267

273-
// create AMIs and grant permissions
274-
var amiID string
275-
if uploadWinLIwindowsServerAMI == "" {
276-
amiID, err = API.CreateHVMImage(sourceSnapshot, uploadDiskSizeGiB, uploadAMIName, uploadAMIDescription, uploadImageArchitecture, uploadVolumeType, uploadIMDSv2Only, uploadX86BootMode)
277-
if err != nil {
278-
fmt.Fprintf(os.Stderr, "unable to create HVM image: %v\n", err)
279-
os.Exit(1)
280-
}
281-
} else {
282-
amiID, sourceSnapshot, err = API.CreateWinLiImage(sourceSnapshot, uploadAMIName, uploadAMIDescription, uploadImageArchitecture, uploadWinLIwindowsServerAMI, uploadWinLIInstanceType, uploadVolumeType)
283-
if err != nil {
284-
fmt.Fprintf(os.Stderr, "unable to create WinLI image: %v\n", err)
285-
os.Exit(1)
286-
}
268+
amiID, err = API.CreateHVMImage(sourceSnapshot, uploadDiskSizeGiB, uploadAMIName, uploadAMIDescription, uploadImageArchitecture, uploadVolumeType, uploadIMDSv2Only, uploadX86BootMode, uploadWinLIBillingProduct)
269+
if err != nil {
270+
fmt.Fprintf(os.Stderr, "unable to create HVM image: %v\n", err)
271+
os.Exit(1)
287272
}
288273

289274
if len(uploadGrantUsers) > 0 {

0 commit comments

Comments
 (0)