blob: c8810925f2f2f9de3867eb9dc1a677dffb52be30 [file] [log] [blame]
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -08001package images
2
3import "github.com/mitchellh/mapstructure"
4
5// Image is used for JSON (un)marshalling.
6// It provides a description of an OS image.
7//
8// The Id field contains the image's unique identifier.
9// For example, this identifier will be useful for specifying which operating system to install on a new server instance.
10//
11// The MinDisk and MinRam fields specify the minimum resources a server must provide to be able to install the image.
12//
13// The Name field provides a human-readable moniker for the OS image.
14//
15// The Progress and Status fields indicate image-creation status.
16// Any usable image will have 100% progress.
17//
18// The Updated field indicates the last time this image was changed.
19type Image struct {
Samuel A. Falvo IIe246ac02014-02-13 23:20:09 -080020 Created string
21 Id string
22 MinDisk int
23 MinRam int
24 Name string
25 Progress int
26 Status string
27 Updated string
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -080028}
29
30func GetImages(lr ListResults) ([]Image, error) {
31 ia, ok := lr["images"]
32 if !ok {
33 return nil, ErrNotImplemented
34 }
35 ims := ia.([]interface{})
36
37 images := make([]Image, len(ims))
38 for i, im := range ims {
39 imageObj := im.(map[string]interface{})
40 err := mapstructure.Decode(imageObj, &images[i])
41 if err != nil {
42 return images, err
43 }
44 }
45 return images, nil
46}
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070047
48func GetImage(ir ImageResults) (Image, error) {
49 image := Image{}
50 err := mapstructure.Decode(ir, &image)
51 return image, err
52}