@@ -47,29 +47,28 @@ After a successful run, the final line of output will be a line of JSON describi
47
47
SilenceUsage : true ,
48
48
}
49
49
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
+ uploadBillingProductCode string
73
72
)
74
73
75
74
func init () {
@@ -94,9 +93,7 @@ func init() {
94
93
cmdUpload .Flags ().BoolVar (& uploadIMDSv2Only , "imdsv2-only" , false , "enable IMDSv2-only support" )
95
94
cmdUpload .Flags ().StringVar (& uploadVolumeType , "volume-type" , "gp3" , "EBS volume type (gp3, gp2, io1, st1, sc1, standard, etc.)" )
96
95
cmdUpload .Flags ().StringVar (& uploadX86BootMode , "x86-boot-mode" , "uefi-preferred" , "Set boot mode (uefi-preferred, uefi)" )
97
- 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" )
96
+ cmdUpload .Flags ().StringVar (& uploadBillingProductCode , "billing-product-code" , "" , "set billing product code" )
100
97
}
101
98
102
99
func defaultBucketNameForRegion (region string ) string {
@@ -140,10 +137,18 @@ func runUpload(cmd *cobra.Command, args []string) error {
140
137
fmt .Fprintf (os .Stderr , "Unrecognized args in aws upload cmd: %v\n " , args )
141
138
os .Exit (2 )
142
139
}
140
+ if uploadSourceObject != "" && uploadSourceSnapshot != "" {
141
+ fmt .Fprintf (os .Stderr , "At most one of --source-object and --source-snapshot may be specified.\n " )
142
+ os .Exit (2 )
143
+ }
143
144
if uploadDiskSizeInspect && (uploadSourceObject != "" || uploadSourceSnapshot != "" ) {
144
145
fmt .Fprintf (os .Stderr , "--disk-size-inspect cannot be used with --source-object or --source-snapshot.\n " )
145
146
os .Exit (2 )
146
147
}
148
+ if uploadFile == "" {
149
+ fmt .Fprintf (os .Stderr , "specify --file\n " )
150
+ os .Exit (2 )
151
+ }
147
152
if uploadImageName == "" {
148
153
fmt .Fprintf (os .Stderr , "unknown image name; specify --name\n " )
149
154
os .Exit (2 )
@@ -152,28 +157,24 @@ func runUpload(cmd *cobra.Command, args []string) error {
152
157
fmt .Fprintf (os .Stderr , "unknown AMI name; specify --ami-name\n " )
153
158
os .Exit (2 )
154
159
}
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 )
160
+
161
+ if uploadDiskSizeInspect {
162
+ imageInfo , err := util .GetImageInfo (uploadFile )
163
+ if err != nil {
164
+ fmt .Fprintf (os .Stderr , "Unable to query size of disk: %v\n " , err )
165
+ os .Exit (1 )
168
166
}
169
- if uploadFile == "" {
170
- fmt .Fprintf (os .Stderr , "specify --file\n " )
171
- os .Exit (2 )
167
+ plog .Debugf ("Image size: %v\n " , imageInfo .VirtualSize )
168
+ const GiB = 1024 * 1024 * 1024
169
+ uploadDiskSizeGiB = uint (imageInfo .VirtualSize / GiB )
170
+ // Round up if there's leftover
171
+ if imageInfo .VirtualSize % GiB > 0 {
172
+ uploadDiskSizeGiB += 1
172
173
}
173
174
}
174
175
175
- var err error
176
176
var s3URL * url.URL
177
+ var err error
177
178
if uploadSourceObject != "" {
178
179
s3URL , err = url .Parse (uploadSourceObject )
179
180
if err != nil {
@@ -191,21 +192,6 @@ func runUpload(cmd *cobra.Command, args []string) error {
191
192
s3BucketName := s3URL .Host
192
193
s3ObjectPath := strings .TrimPrefix (s3URL .Path , "/" )
193
194
194
- if uploadDiskSizeInspect {
195
- imageInfo , err := util .GetImageInfo (uploadFile )
196
- if err != nil {
197
- fmt .Fprintf (os .Stderr , "Unable to query size of disk: %v\n " , err )
198
- os .Exit (1 )
199
- }
200
- plog .Debugf ("Image size: %v\n " , imageInfo .VirtualSize )
201
- const GiB = 1024 * 1024 * 1024
202
- uploadDiskSizeGiB = uint (imageInfo .VirtualSize / GiB )
203
- // Round up if there's leftover
204
- if imageInfo .VirtualSize % GiB > 0 {
205
- uploadDiskSizeGiB += 1
206
- }
207
- }
208
-
209
195
if uploadForce {
210
196
err := API .RemoveImage (uploadAMIName )
211
197
if err != nil {
@@ -275,20 +261,10 @@ func runUpload(cmd *cobra.Command, args []string) error {
275
261
}
276
262
}
277
263
278
- // create AMIs and grant permissions
279
- var amiID string
280
- if uploadWinLIwindowsServerAMI == "" {
281
- amiID , err = API .CreateHVMImage (sourceSnapshot , uploadDiskSizeGiB , uploadAMIName , uploadAMIDescription , uploadImageArchitecture , uploadVolumeType , uploadIMDSv2Only , uploadX86BootMode )
282
- if err != nil {
283
- fmt .Fprintf (os .Stderr , "unable to create HVM image: %v\n " , err )
284
- os .Exit (1 )
285
- }
286
- } else {
287
- amiID , sourceSnapshot , err = API .CreateWinLiImage (sourceSnapshot , uploadAMIName , uploadAMIDescription , uploadImageArchitecture , uploadWinLIwindowsServerAMI , uploadWinLIInstanceType , uploadVolumeType )
288
- if err != nil {
289
- fmt .Fprintf (os .Stderr , "unable to create WinLI image: %v\n " , err )
290
- os .Exit (1 )
291
- }
264
+ amiID , err = API .CreateHVMImage (sourceSnapshot , uploadDiskSizeGiB , uploadAMIName , uploadAMIDescription , uploadImageArchitecture , uploadVolumeType , uploadIMDSv2Only , uploadX86BootMode , uploadBillingProductCode )
265
+ if err != nil {
266
+ fmt .Fprintf (os .Stderr , "unable to create HVM image: %v\n " , err )
267
+ os .Exit (1 )
292
268
}
293
269
294
270
if len (uploadGrantUsers ) > 0 {
0 commit comments