blob: d8178c1e39b0e2492fc4c3baec29710e37e9cf71 [file] [log] [blame]
Jon Perrittdfff9972014-09-22 01:14:54 -05001package snapshots
2
Jon Perrittd7468632014-09-22 21:58:59 -05003import (
4 "fmt"
5
6 "github.com/mitchellh/mapstructure"
7)
8
Jon Perrittdfff9972014-09-22 01:14:54 -05009type Snapshot struct {
10 CreatedAt string
11 Description string
12 ID string
13 Metadata map[string]interface{}
14 Name string
15 Size int
16 Status string
17 VolumeID string
18}
Jon Perritt56d43b22014-09-22 20:47:11 -050019
Jon Perrittd7468632014-09-22 21:58:59 -050020type GetResult struct {
21 err error
22 r map[string]interface{}
23}
24
25func (gr GetResult) ExtractSnapshot() (*Snapshot, error) {
26 if gr.err != nil {
27 return nil, gr.err
28 }
29
30 var response struct {
31 Snapshot *Snapshot `json:"snapshot"`
32 }
33
34 err := mapstructure.Decode(gr.r, &response)
35 if err != nil {
36 return nil, fmt.Errorf("snapshots: Error decoding snapshot.GetResult: %v", err)
37 }
38 return response.Snapshot, nil
39}