/
image.go
67 lines (55 loc) · 1.76 KB
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package spinup
import (
"encoding/json"
log "github.com/sirupsen/logrus"
)
// Image is a server image
type Image struct {
Architecture string `json:"architecture,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
CreatedBy string `json:"created_by,omitempty"`
Description string `json:"description,omitempty"`
ID string `json:"id"`
Name string `json:"name,omitempty"`
ServerName string `json:"server_name,omitempty"`
State string `json:"state,omitempty"`
Status string `json:"status,omitempty"`
Volumes ImageVolumes `json:"volumes,omitempty"`
Offering *Offering `json:"offering,omitempty"`
}
// Images is a list of server images
type Images []*Image
// GetEndpoint gets the endpoint UR for an image list
func (i *Images) GetEndpoint(params map[string]string) string {
return BaseURL + SpaceURI + "/" + params["space"] + "/images"
}
type ImageVolumes map[string]*ImageVolume
type ImageVolume struct {
DeleteOnTermination bool `json:"delete_on_termination"`
Encrypted bool `json:"encrypted"`
ID string `json:"snapshot_id,omitempty"`
Size int `json:"volume_size,omitempty"`
Type string `json:"volume_type,omitempty"`
}
func (iv *ImageVolumes) UnmarshalJSON(b []byte) error {
if *iv == nil {
*iv = ImageVolumes{}
}
imageVolumes := *iv
var volMap map[string]json.RawMessage
if err := json.Unmarshal(b, &volMap); err != nil {
return err
}
for k, v := range volMap {
if string(v) == "[]" {
log.Debugf("skipping empty volume %s", k)
continue
}
vol := ImageVolume{}
if err := json.Unmarshal(v, &vol); err != nil {
return err
}
imageVolumes[k] = &vol
}
return nil
}