Samuel A. Falvo II | 17ae565 | 2014-02-12 20:47:43 -0800 | [diff] [blame] | 1 | package images |
| 2 | |
| 3 | import "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. |
| 19 | type Image struct { |
Samuel A. Falvo II | e246ac0 | 2014-02-13 23:20:09 -0800 | [diff] [blame] | 20 | 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 II | 17ae565 | 2014-02-12 20:47:43 -0800 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | func 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 II | 808bb63 | 2014-03-12 00:07:50 -0700 | [diff] [blame] | 47 | |
| 48 | func GetImage(ir ImageResults) (Image, error) { |
| 49 | image := Image{} |
| 50 | err := mapstructure.Decode(ir, &image) |
| 51 | return image, err |
| 52 | } |