blob: 92008c5782a5afb3ee9f70df5902b5cf901c6eaf [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 Perritt60c3b2e2014-05-27 18:38:33 -050027func 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 Perritte3af81d2014-05-06 14:52:28 -050048func 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 Perritt982c86d2014-05-05 21:13:54 -050064func 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}