Jamie Hannaford | dfc1be7 | 2014-10-20 18:58:20 +0200 | [diff] [blame^] | 1 | package volumes |
| 2 | |
| 3 | import ( |
| 4 | "github.com/rackspace/gophercloud" |
| 5 | os "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes" |
| 6 | "github.com/rackspace/gophercloud/pagination" |
| 7 | ) |
| 8 | |
| 9 | // CreateOpts contains options for creating a Volume. This object is passed to |
| 10 | // the volumes.Create function. For more information about these parameters, |
| 11 | // see the Volume object. |
| 12 | type CreateOpts struct { |
| 13 | os.CreateOpts |
| 14 | } |
| 15 | |
| 16 | // Create will create a new Volume based on the values in CreateOpts. To extract |
| 17 | // the Volume object from the response, call the Extract method on the |
| 18 | // CreateResult. |
| 19 | func Create(client *gophercloud.ServiceClient, opts os.CreateOptsBuilder) CreateResult { |
| 20 | return CreateResult{os.Create(client, opts)} |
| 21 | } |
| 22 | |
| 23 | // Delete will delete the existing Volume with the provided ID. |
| 24 | func Delete(client *gophercloud.ServiceClient, id string) error { |
| 25 | return os.Delete(client, id) |
| 26 | } |
| 27 | |
| 28 | // Get retrieves the Volume with the provided ID. To extract the Volume object |
| 29 | // from the response, call the Extract method on the GetResult. |
| 30 | func Get(client *gophercloud.ServiceClient, id string) GetResult { |
| 31 | return GetResult{os.Get(client, id)} |
| 32 | } |
| 33 | |
| 34 | // List returns volumes optionally limited by the conditions provided in ListOpts. |
| 35 | func List(client *gophercloud.ServiceClient) pagination.Pager { |
| 36 | return os.List(client, os.ListOpts{}) |
| 37 | } |
| 38 | |
| 39 | // UpdateOpts contain options for updating an existing Volume. This object is passed |
| 40 | // to the volumes.Update function. For more information about the parameters, see |
| 41 | // the Volume object. |
| 42 | type UpdateOpts struct { |
| 43 | // OPTIONAL |
| 44 | Name string |
| 45 | // OPTIONAL |
| 46 | Description string |
| 47 | } |
| 48 | |
| 49 | // ToVolumeUpdateMap assembles a request body based on the contents of an |
| 50 | // UpdateOpts. |
| 51 | func (opts UpdateOpts) ToVolumeUpdateMap() (map[string]interface{}, error) { |
| 52 | v := make(map[string]interface{}) |
| 53 | |
| 54 | if opts.Description != "" { |
| 55 | v["display_description"] = opts.Description |
| 56 | } |
| 57 | if opts.Name != "" { |
| 58 | v["display_name"] = opts.Name |
| 59 | } |
| 60 | |
| 61 | return map[string]interface{}{"volume": v}, nil |
| 62 | } |
| 63 | |
| 64 | // Update will update the Volume with provided information. To extract the updated |
| 65 | // Volume from the response, call the Extract method on the UpdateResult. |
| 66 | func Update(client *gophercloud.ServiceClient, id string, opts os.UpdateOptsBuilder) UpdateResult { |
| 67 | return UpdateResult{os.Update(client, id, opts)} |
| 68 | } |