blob: 1fc3e276cb97bb51d21612429be4898374b9c7e4 [file] [log] [blame]
Jon Perritt687c7d02014-05-05 18:44:54 -05001package snapshots
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) (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 Perritt982c86d2014-05-05 21:13:54 -050026
Jon Perritte3af81d2014-05-06 14:52:28 -050027func Get(c *blockstorage.Client, opts GetOpts) (Snapshot, error) {
28 var ss Snapshot
29 h, err := c.GetHeaders()
30 if err != nil {
31 return ss, err
32 }
33 url := c.GetSnapshotURL(opts["id"])
34 _, err = perigee.Request("GET", url, perigee.Options{
35 Results: &struct {
36 Snapshot *Snapshot `json:"snapshot"`
37 }{&ss},
38 MoreHeaders: h,
39 })
40 return ss, err
41}
42
Jon Perritt982c86d2014-05-05 21:13:54 -050043func Delete(c *blockstorage.Client, opts DeleteOpts) error {
44 h, err := c.GetHeaders()
45 if err != nil {
46 return err
47 }
48 url := c.GetSnapshotURL(opts["id"])
49 _, err = perigee.Request("DELETE", url, perigee.Options{
50 MoreHeaders: h,
51 })
52 return err
53}