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