blob: 778b9bf9ebbebbb4237150074b9f79711f383654 [file] [log] [blame]
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -08001package images
2
Ash Wilson9ccf9b62014-09-17 10:07:52 -04003import (
4 "github.com/mitchellh/mapstructure"
5 "github.com/rackspace/gophercloud/pagination"
6)
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -08007
8// Image is used for JSON (un)marshalling.
9// It provides a description of an OS image.
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -080010type Image struct {
Ash Wilson9ccf9b62014-09-17 10:07:52 -040011 // ID contains the image's unique identifier.
12 ID string
13
14 Created string
15
16 // MinDisk and MinRAM specify the minimum resources a server must provide to be able to install the image.
17 MinDisk int
18 MinRAM int
19
20 // Name provides a human-readable moniker for the OS image.
21 Name string
22
23 // The Progress and Status fields indicate image-creation status.
24 // Any usable image will have 100% progress.
Samuel A. Falvo IIe246ac02014-02-13 23:20:09 -080025 Progress int
26 Status string
Ash Wilson9ccf9b62014-09-17 10:07:52 -040027
28 Updated string
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -080029}
30
Ash Wilson9ccf9b62014-09-17 10:07:52 -040031// ExtractImages converts a page of List results into a slice of usable Image structs.
32func ExtractImages(page pagination.Page) ([]Image, error) {
Ash Wilsonfd043792014-09-17 10:40:17 -040033 casted := page.(ListPage).Body
Ash Wilsonfaf006d2014-09-24 17:10:58 -040034 var results struct {
35 Images []Image `mapstructure:"images"`
36 }
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -080037
Ash Wilsonfaf006d2014-09-24 17:10:58 -040038 err := mapstructure.Decode(casted, &results)
39 return results.Images, err
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070040}
Ash Wilson7ddf0362014-09-17 10:59:09 -040041
42// ExtractImage converts the result of a Get call into a more usable Image structure.
43func ExtractImage(result GetResult) (Image, error) {
44 var decoded Image
45 err := mapstructure.Decode(result, &decoded)
46 return decoded, err
47}