github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/evs/v3/volumes/requests.go (about) 1 package volumes 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 ) 6 7 // CreateOptsBuilder allows extensions to add additional parameters to the 8 // Create request. 9 type CreateOptsBuilder interface { 10 ToVolumeCreateMap() (map[string]interface{}, error) 11 } 12 13 // CreateOpts contains options for creating a Volume. This object is passed to 14 // the volumes.Create function. For more information about these parameters, 15 // see the Volume object. 16 type CreateOpts struct { 17 // The availability zone 18 AvailabilityZone string `json:"availability_zone" required:"true"` 19 // The associated volume type 20 VolumeType string `json:"volume_type" required:"true"` 21 // The volume name 22 Name string `json:"name,omitempty"` 23 // The volume description 24 Description string `json:"description,omitempty"` 25 // The size of the volume, in GB 26 Size int `json:"size,omitempty"` 27 // The number to be created in a batch 28 Count int `json:"count,omitempty"` 29 // The backup_id 30 BackupID string `json:"backup_id,omitempty"` 31 // the ID of the existing volume snapshot 32 SnapshotID string `json:"snapshot_id,omitempty"` 33 // the ID of the image in IMS 34 ImageRef string `json:"imageRef,omitempty"` 35 // This field is no longer used. Use multiattach. 36 Shareable string `json:"shareable,omitempty"` 37 // Shared disk 38 Multiattach bool `json:"multiattach,omitempty"` 39 // One or more metadata key and value pairs to associate with the volume 40 Metadata map[string]string `json:"metadata,omitempty"` 41 // One or more tag key and value pairs to associate with the volume 42 Tags map[string]string `json:"tags,omitempty"` 43 // the enterprise project id 44 EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` 45 } 46 47 // ToVolumeCreateMap assembles a request body based on the contents of a 48 // CreateOpts. 49 func (opts CreateOpts) ToVolumeCreateMap() (map[string]interface{}, error) { 50 return golangsdk.BuildRequestBody(opts, "volume") 51 } 52 53 // Create will create a new Volume based on the values in CreateOpts. 54 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r JobResult) { 55 b, err := opts.ToVolumeCreateMap() 56 if err != nil { 57 r.Err = err 58 return 59 } 60 _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ 61 OkCodes: []int{200}, 62 }) 63 return 64 } 65 66 // Get retrieves the Volume with the provided ID. To extract the Volume object 67 // from the response, call the Extract method on the GetResult. 68 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 69 _, r.Err = client.Get(getURL(client, id), &r.Body, nil) 70 return 71 }