github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/ims/v2/images/CreateImageFromECS.go (about) 1 package images 2 3 import ( 4 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/internal/build" 6 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" 7 "github.com/opentelekomcloud/gophertelekomcloud/openstack/ims/v1/others" 8 ) 9 10 type CreateImageFromECSOpts struct { 11 // Specifies the name of the system disk image. For detailed description, see Image Attributes. 12 Name string `json:"name,omitempty"` 13 // Specifies the image description. For detailed description, see Image Attributes. The value contains a maximum of 1024 characters and consists of only letters and digits. Carriage returns and angle brackets (< >) are not allowed. This parameter is left blank by default. 14 Description string `json:"description,omitempty"` 15 // Specifies the ID of the ECS used to create the image. 16 // 17 // To obtain the ECS ID, perform the following operations: 18 // 19 // Log in to management console. 20 // Under Computing, click Elastic Cloud Server. 21 // In the ECS list, click the name of the ECS and view its ID. 22 InstanceId string `json:"instance_id,omitempty"` 23 // Specifies the data disk information to be converted. This parameter is mandatory when the data disk of an ECS is used to create a private data disk image. For details, see Table 1. 24 // 25 // If the ECS data disk is not used to create a data disk image, the parameter is empty by default. 26 // 27 // NOTE: 28 // When you create a data disk image using a data disk, if other parameters (such as name, description, and tags) in this table have values, the system uses the value of data_images. You cannot specify instance_id. 29 DataImages []ECSDataImage `json:"data_images,omitempty"` 30 // Specifies tags of the image. This parameter is left blank by default. 31 // 32 // Use either tags or image_tags. 33 Tags []string `json:"tags,omitempty"` 34 // Specifies tags of the image. This parameter is left blank by default. 35 // 36 // Use either tags or image_tags. 37 ImageTags []tags.ResourceTag `json:"image_tags,omitempty"` 38 // Specifies the maximum memory of the image in the unit of MB. 39 MaxRam int `json:"max_ram,omitempty"` 40 // Specifies the minimum memory of the image in the unit of MB. The default value is 0, indicating that the memory is not restricted. 41 MinRam int `json:"min_ram,omitempty"` 42 } 43 44 type ECSDataImage struct { 45 // Specifies the name of a data disk image. 46 Name string `json:"name" required:"true"` 47 // Specifies the data disk ID. 48 VolumeId string `json:"volume_id" required:"true"` 49 // Specifies the data disk description. 50 Description string `json:"description,omitempty"` 51 // Specifies the data disk image tag. 52 Tags []string `json:"tags,omitempty"` 53 } 54 55 // CreateImageFromECS This API is used to create a private image. The following methods are supported: 56 // 57 // Create a system or data disk image from an ECS. 58 // Create a system disk image from an external image file uploaded to an OBS bucket. 59 // Create a system disk image from a data disk. 60 // The API is an asynchronous one. If it is successfully called, the cloud service system receives the request. However, you need to use the asynchronous job query API to query the image creation status. For details, see Asynchronous Job Query. 61 // 62 // You cannot export public images (such as Windows, SUSE Linux, Red Hat Linux, Oracle Linux, and Ubuntu) or private images created using these public images. 63 func CreateImageFromECS(client *golangsdk.ServiceClient, opts CreateImageFromECSOpts) (*string, error) { 64 b, err := build.RequestBody(opts, "") 65 if err != nil { 66 return nil, err 67 } 68 69 return cloudImages(client, b) 70 } 71 72 func cloudImages(client *golangsdk.ServiceClient, b *build.Body) (*string, error) { 73 // POST /v2/cloudimages/action 74 raw, err := client.Post(client.ServiceURL("cloudimages", "action"), b, nil, &golangsdk.RequestOpts{ 75 OkCodes: []int{200}, 76 }) 77 return others.ExtractJobId(err, raw) 78 }