blob: 61a336930bfc53afd5e6a5c073d2581d1ef168de [file] [log] [blame]
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -07001package gophercloud
2
Samuel A. Falvo II0a6e45a2013-07-11 17:00:41 -07003import (
4 "github.com/racker/perigee"
5)
6
7// See the CloudImagesProvider interface for details.
8func (gsp *genericServersProvider) ListImages() ([]Image, error) {
9 var is []Image
Samuel A. Falvo II7bd1fba2013-07-16 17:30:43 -070010
Samuel A. Falvo II9e64f6b2013-07-16 14:26:50 -070011 err := gsp.context.WithReauth(gsp.access, func() error {
Samuel A. Falvo II9b23b342013-07-30 11:58:16 -070012 url := gsp.endpoint + "/images/detail"
Samuel A. Falvo II9e64f6b2013-07-16 14:26:50 -070013 return perigee.Get(url, perigee.Options{
14 CustomClient: gsp.context.httpClient,
15 Results: &struct{ Images *[]Image }{&is},
16 MoreHeaders: map[string]string{
17 "X-Auth-Token": gsp.access.AuthToken(),
18 },
19 })
Samuel A. Falvo II0a6e45a2013-07-11 17:00:41 -070020 })
21 return is, err
22}
23
Mark Peek0dbb3682013-08-24 19:04:48 -070024func (gsp *genericServersProvider) ImageById(id string) (*Image, error) {
25 var is *Image
26
27 err := gsp.context.WithReauth(gsp.access, func() error {
28 url := gsp.endpoint + "/images/" + id
29 return perigee.Get(url, perigee.Options{
30 CustomClient: gsp.context.httpClient,
31 Results: &struct{ Image **Image }{&is},
32 MoreHeaders: map[string]string{
33 "X-Auth-Token": gsp.access.AuthToken(),
34 },
35 })
36 })
37 return is, err
38}
39
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -070040// ImageLink provides a reference to a image by either ID or by direct URL.
41// Some services use just the ID, others use just the URL.
42// This structure provides a common means of expressing both in a single field.
43type ImageLink struct {
44 Id string `json:"id"`
45 Links []Link `json:"links"`
46}
Samuel A. Falvo II0a6e45a2013-07-11 17:00:41 -070047
48// Image is used for JSON (un)marshalling.
49// It provides a description of an OS image.
50//
51// The Id field contains the image's unique identifier.
52// For example, this identifier will be useful for specifying which operating system to install on a new server instance.
53//
54// The MinDisk and MinRam fields specify the minimum resources a server must provide to be able to install the image.
55//
56// The Name field provides a human-readable moniker for the OS image.
57//
58// The Progress and Status fields indicate image-creation status.
59// Any usable image will have 100% progress.
60//
61// The Updated field indicates the last time this image was changed.
62//
63// OsDcfDiskConfig indicates the server's boot volume configuration.
64// Valid values are:
65// AUTO
66// ----
67// The server is built with a single partition the size of the target flavor disk.
68// The file system is automatically adjusted to fit the entire partition.
69// This keeps things simple and automated.
70// AUTO is valid only for images and servers with a single partition that use the EXT3 file system.
71// This is the default setting for applicable Rackspace base images.
72//
73// MANUAL
74// ------
75// The server is built using whatever partition scheme and file system is in the source image.
76// If the target flavor disk is larger,
77// the remaining disk space is left unpartitioned.
78// This enables images to have non-EXT3 file systems, multiple partitions, and so on,
79// and enables you to manage the disk configuration.
80//
81type Image struct {
82 Created string `json:"created"`
83 Id string `json:"id"`
84 Links []Link `json:"links"`
85 MinDisk int `json:"minDisk"`
86 MinRam int `json:"minRam"`
87 Name string `json:"name"`
88 Progress int `json:"progress"`
89 Status string `json:"status"`
90 Updated string `json:"updated"`
91 OsDcfDiskConfig string `json:"OS-DCF:diskConfig"`
92}