Jon Perritt | 687c7d0 | 2014-05-05 18:44:54 -0500 | [diff] [blame] | 1 | package snapshots |
| 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) (Snapshot, error) { |
| 9 | var ss Snapshot |
| 10 | h, err := c.GetHeaders() |
| 11 | if err != nil { |
| 12 | return ss, err |
| 13 | } |
| 14 | url := c.GetSnapshotsURL() |
| 15 | _, err = perigee.Request("POST", url, perigee.Options{ |
| 16 | Results: &struct { |
| 17 | Snapshot *Snapshot `json:"snapshot"` |
| 18 | }{&ss}, |
| 19 | ReqBody: map[string]interface{}{ |
| 20 | "snapshot": opts, |
| 21 | }, |
| 22 | MoreHeaders: h, |
| 23 | }) |
| 24 | return ss, err |
| 25 | } |
Jon Perritt | 982c86d | 2014-05-05 21:13:54 -0500 | [diff] [blame] | 26 | |
Jon Perritt | 60c3b2e | 2014-05-27 18:38:33 -0500 | [diff] [blame] | 27 | func List(c *blockstorage.Client, opts ListOpts) ([]Snapshot, error) { |
| 28 | var ss []Snapshot |
| 29 | var url string |
| 30 | h, err := c.GetHeaders() |
| 31 | if err != nil { |
| 32 | return ss, err |
| 33 | } |
| 34 | if full := opts.Full; full { |
| 35 | url = c.GetSnapshotsURL() |
| 36 | } else { |
| 37 | url = c.GetSnapshotURL("detail") |
| 38 | } |
| 39 | _, err = perigee.Request("GET", url, perigee.Options{ |
| 40 | Results: &struct { |
| 41 | Snapshot *[]Snapshot `json:"snapshots"` |
| 42 | }{&ss}, |
| 43 | MoreHeaders: h, |
| 44 | }) |
| 45 | return ss, err |
| 46 | } |
| 47 | |
Jon Perritt | e3af81d | 2014-05-06 14:52:28 -0500 | [diff] [blame] | 48 | func Get(c *blockstorage.Client, opts GetOpts) (Snapshot, error) { |
| 49 | var ss Snapshot |
| 50 | h, err := c.GetHeaders() |
| 51 | if err != nil { |
| 52 | return ss, err |
| 53 | } |
| 54 | url := c.GetSnapshotURL(opts["id"]) |
| 55 | _, err = perigee.Request("GET", url, perigee.Options{ |
| 56 | Results: &struct { |
| 57 | Snapshot *Snapshot `json:"snapshot"` |
| 58 | }{&ss}, |
| 59 | MoreHeaders: h, |
| 60 | }) |
| 61 | return ss, err |
| 62 | } |
| 63 | |
Jon Perritt | 982c86d | 2014-05-05 21:13:54 -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.GetSnapshotURL(opts["id"]) |
| 70 | _, err = perigee.Request("DELETE", url, perigee.Options{ |
| 71 | MoreHeaders: h, |
| 72 | }) |
| 73 | return err |
| 74 | } |