blob: 4372f2b85ff7155e15415b61f2fef9229a82eec2 [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
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.
12type 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.
19func 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.
24func 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.
30func 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.
35func 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.
42type 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.
51func (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.
66func Update(client *gophercloud.ServiceClient, id string, opts os.UpdateOptsBuilder) UpdateResult {
67 return UpdateResult{os.Update(client, id, opts)}
68}