@@ -110,6 +110,15 @@ type exportCustomerImage struct {
110
110
OVFPackagePrefix string `json:"ovfPackagePrefix"`
111
111
}
112
112
113
+ // Request body when importing a customer image from an OVF package.
114
+ type importCustomerImage struct {
115
+ OVFPackageManifest string `json:"ovfPackage"`
116
+ ImageName string `json:"name"`
117
+ ImageDescription string `json:"description"`
118
+ DatacenterID string `json:"datacenterId"`
119
+ GuestOSCustomization bool `json:"guestOsCustomization"`
120
+ }
121
+
113
122
// GetCustomerImage retrieves a specific customer image by Id.
114
123
func (client * Client ) GetCustomerImage (id string ) (image * CustomerImage , err error ) {
115
124
organizationID , err := client .getOrganizationID ()
@@ -243,7 +252,61 @@ func (client *Client) ListCustomerImagesInDatacenter(dataCenterID string, paging
243
252
return
244
253
}
245
254
246
- // ExportCustomerImage exports the specified customer image as an OVF package.
255
+ // ImportCustomerImage imports the specified customer image from an OVF package.
256
+ //
257
+ // The OVF package can be uploaded via FTPS (call GetDatacenter to determine the FTPS end-point for the target datacenter).
258
+ //
259
+ // The image's status will be ResourceStatusPendingAdd while the import is in progress, then ResourceStatusNormal once the export is complete.
260
+ func (client * Client ) ImportCustomerImage (imageName string , imageDescription string , preventGuestOSCustomization bool , ovfPackagePrefix string , datacenterID string ) (importID string , err error ) {
261
+ organizationID , err := client .getOrganizationID ()
262
+ if err != nil {
263
+ return "" , err
264
+ }
265
+
266
+ requestURI := fmt .Sprintf ("%s/image/importImage" ,
267
+ url .QueryEscape (organizationID ),
268
+ )
269
+ request , err := client .newRequestV24 (requestURI , http .MethodPost , & importCustomerImage {
270
+ ImageName : imageName ,
271
+ ImageDescription : imageDescription ,
272
+ DatacenterID : datacenterID ,
273
+ OVFPackageManifest : ovfPackagePrefix + ".mf" ,
274
+ GuestOSCustomization : ! preventGuestOSCustomization ,
275
+ })
276
+ if err != nil {
277
+ return "" , err
278
+ }
279
+ responseBody , statusCode , err := client .executeRequest (request )
280
+ if err != nil {
281
+ return "" , err
282
+ }
283
+
284
+ apiResponse , err := readAPIResponseAsJSON (responseBody , statusCode )
285
+ if err != nil {
286
+ return "" , err
287
+ }
288
+
289
+ if apiResponse .ResponseCode != ResponseCodeInProgress {
290
+ return "" , fmt .Errorf ("Request to import customer image '%s' in datacenter '%s' from OFV package '%s' failed with status code %d (%s): %s" ,
291
+ imageName ,
292
+ datacenterID ,
293
+ ovfPackagePrefix ,
294
+ statusCode ,
295
+ apiResponse .ResponseCode ,
296
+ apiResponse .Message ,
297
+ )
298
+ }
299
+
300
+ // Expected: "info" { "name": "imageId", "value": "the-Id-of-new-customer-image" }
301
+ imageIDMessage := apiResponse .GetFieldMessage ("imageId" )
302
+ if imageIDMessage == nil {
303
+ return "" , apiResponse .ToError ("Received an unexpected response (missing 'imageId') with status code %d (%s): %s" , statusCode , apiResponse .ResponseCode , apiResponse .Message )
304
+ }
305
+
306
+ return * imageIDMessage , nil
307
+ }
308
+
309
+ // ExportCustomerImage exports the specified customer image to an OVF package.
247
310
//
248
311
// The OVF package can then be downloaded via FTPS.
249
312
//
0 commit comments