blob: c4e838e50135d8d63168be434177866388defdc8 [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) {
33 casted := page.(ListResults).Body
34 var results []Image
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -080035
Ash Wilson9ccf9b62014-09-17 10:07:52 -040036 err := mapstructure.Decode(results, casted)
37 return results, err
Samuel A. Falvo II808bb632014-03-12 00:07:50 -070038}