blob: a23e0bbb67d0cd07e8736b620a53479654256c5d [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
Mark Peek12a81e62013-08-27 08:15:57 -070040func (gsp *genericServersProvider) DeleteImageById(id string) error {
41 err := gsp.context.WithReauth(gsp.access, func() error {
42 url := gsp.endpoint + "/images/" + id
43 _, err := perigee.Request("DELETE", url, perigee.Options{
44 CustomClient: gsp.context.httpClient,
45 MoreHeaders: map[string]string{
46 "X-Auth-Token": gsp.access.AuthToken(),
47 },
48 })
49 return err
50 })
51 return err
52}
53
Samuel A. Falvo IIbc0d54a2013-07-08 14:45:21 -070054// ImageLink provides a reference to a image by either ID or by direct URL.
55// Some services use just the ID, others use just the URL.
56// This structure provides a common means of expressing both in a single field.
57type ImageLink struct {
58 Id string `json:"id"`
59 Links []Link `json:"links"`
60}
Samuel A. Falvo II0a6e45a2013-07-11 17:00:41 -070061
62// Image is used for JSON (un)marshalling.
63// It provides a description of an OS image.
64//
65// The Id field contains the image's unique identifier.
66// For example, this identifier will be useful for specifying which operating system to install on a new server instance.
67//
68// The MinDisk and MinRam fields specify the minimum resources a server must provide to be able to install the image.
69//
70// The Name field provides a human-readable moniker for the OS image.
71//
72// The Progress and Status fields indicate image-creation status.
73// Any usable image will have 100% progress.
74//
75// The Updated field indicates the last time this image was changed.
76//
77// OsDcfDiskConfig indicates the server's boot volume configuration.
78// Valid values are:
79// AUTO
80// ----
81// The server is built with a single partition the size of the target flavor disk.
82// The file system is automatically adjusted to fit the entire partition.
83// This keeps things simple and automated.
84// AUTO is valid only for images and servers with a single partition that use the EXT3 file system.
85// This is the default setting for applicable Rackspace base images.
86//
87// MANUAL
88// ------
89// The server is built using whatever partition scheme and file system is in the source image.
90// If the target flavor disk is larger,
91// the remaining disk space is left unpartitioned.
92// This enables images to have non-EXT3 file systems, multiple partitions, and so on,
93// and enables you to manage the disk configuration.
94//
95type Image struct {
96 Created string `json:"created"`
97 Id string `json:"id"`
98 Links []Link `json:"links"`
99 MinDisk int `json:"minDisk"`
100 MinRam int `json:"minRam"`
101 Name string `json:"name"`
102 Progress int `json:"progress"`
103 Status string `json:"status"`
104 Updated string `json:"updated"`
105 OsDcfDiskConfig string `json:"OS-DCF:diskConfig"`
106}