Jon Perritt | ee6074f | 2014-04-30 18:42:32 -0500 | [diff] [blame] | 1 | package volumes |
| 2 | |
| 3 | import ( |
| 4 | "github.com/racker/perigee" |
| 5 | blockstorage "github.com/rackspace/gophercloud/openstack/blockstorage/v1" |
| 6 | ) |
| 7 | |
| 8 | func 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 Perritt | 3baca06 | 2014-04-30 23:33:04 -0500 | [diff] [blame] | 14 | url := c.GetVolumesURL() |
Jon Perritt | ee6074f | 2014-04-30 18:42:32 -0500 | [diff] [blame] | 15 | _, err = perigee.Request("POST", url, perigee.Options{ |
Jon Perritt | e77b9b2 | 2014-05-01 13:11:12 -0500 | [diff] [blame] | 16 | Results: &struct { |
| 17 | Volume *Volume `json:"volume"` |
| 18 | }{&v}, |
Jon Perritt | ee6074f | 2014-04-30 18:42:32 -0500 | [diff] [blame] | 19 | ReqBody: map[string]interface{}{ |
| 20 | "volume": opts, |
| 21 | }, |
| 22 | MoreHeaders: h, |
| 23 | }) |
| 24 | return v, err |
| 25 | } |
Jon Perritt | e77b9b2 | 2014-05-01 13:11:12 -0500 | [diff] [blame] | 26 | |
Jon Perritt | 94963ad | 2014-05-05 12:14:39 -0500 | [diff] [blame^] | 27 | func 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 Perritt | 70dd47d | 2014-05-01 13:51:53 -0500 | [diff] [blame] | 48 | func 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 Perritt | e77b9b2 | 2014-05-01 13:11:12 -0500 | [diff] [blame] | 64 | func 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 | } |