blob: c4a72c2fe5544b7ed117f7667567c35870f057f7 [file] [log] [blame]
Jon Perrittee6074f2014-04-30 18:42:32 -05001package volumes
2
3import (
4 "github.com/racker/perigee"
5 blockstorage "github.com/rackspace/gophercloud/openstack/blockstorage/v1"
6)
7
8func Create(c *blockstorage.Client, opts CreateOpts) (Volume, error) {
9 var v Volume
10 h, err := c.GetHeaders()
11 if err != nil {
12 return v, err
13 }
Jon Perritt3baca062014-04-30 23:33:04 -050014 url := c.GetVolumesURL()
Jon Perrittee6074f2014-04-30 18:42:32 -050015 _, err = perigee.Request("POST", url, perigee.Options{
Jon Perritte77b9b22014-05-01 13:11:12 -050016 Results: &struct {
17 Volume *Volume `json:"volume"`
18 }{&v},
Jon Perrittee6074f2014-04-30 18:42:32 -050019 ReqBody: map[string]interface{}{
20 "volume": opts,
21 },
22 MoreHeaders: h,
23 })
24 return v, err
25}
Jon Perritte77b9b22014-05-01 13:11:12 -050026
Jon Perritt94963ad2014-05-05 12:14:39 -050027func List(c *blockstorage.Client, opts ListOpts) ([]Volume, error) {
28 var v []Volume
29 var url string
30 h, err := c.GetHeaders()
31 if err != nil {
32 return v, err
33 }
34 if full := opts["full"]; full {
35 url = c.GetVolumesURL()
36 } else {
37 url = c.GetVolumeURL("detail")
38 }
39 _, err = perigee.Request("GET", url, perigee.Options{
40 Results: &struct {
41 Volume *[]Volume `json:"volumes"`
42 }{&v},
43 MoreHeaders: h,
44 })
45 return v, err
46}
47
Jon Perritt70dd47d2014-05-01 13:51:53 -050048func Get(c *blockstorage.Client, opts GetOpts) (Volume, error) {
49 var v Volume
50 h, err := c.GetHeaders()
51 if err != nil {
52 return v, err
53 }
54 url := c.GetVolumeURL(opts["id"])
55 _, err = perigee.Request("GET", url, perigee.Options{
56 Results: &struct {
57 Volume *Volume `json:"volume"`
58 }{&v},
59 MoreHeaders: h,
60 })
61 return v, err
62}
63
Jon Perritte77b9b22014-05-01 13:11:12 -050064func Delete(c *blockstorage.Client, opts DeleteOpts) error {
65 h, err := c.GetHeaders()
66 if err != nil {
67 return err
68 }
69 url := c.GetVolumeURL(opts["id"])
70 _, err = perigee.Request("DELETE", url, perigee.Options{
71 MoreHeaders: h,
72 })
73 return err
74}