Samuel A. Falvo II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 1 | package gophercloud |
| 2 | |
Samuel A. Falvo II | 0a6e45a | 2013-07-11 17:00:41 -0700 | [diff] [blame] | 3 | import ( |
| 4 | "github.com/racker/perigee" |
| 5 | ) |
| 6 | |
| 7 | // See the CloudImagesProvider interface for details. |
| 8 | func (gsp *genericServersProvider) ListImages() ([]Image, error) { |
| 9 | var is []Image |
Samuel A. Falvo II | 7bd1fba | 2013-07-16 17:30:43 -0700 | [diff] [blame] | 10 | |
Samuel A. Falvo II | 9e64f6b | 2013-07-16 14:26:50 -0700 | [diff] [blame] | 11 | err := gsp.context.WithReauth(gsp.access, func() error { |
Samuel A. Falvo II | 9b23b34 | 2013-07-30 11:58:16 -0700 | [diff] [blame] | 12 | url := gsp.endpoint + "/images/detail" |
Samuel A. Falvo II | 9e64f6b | 2013-07-16 14:26:50 -0700 | [diff] [blame] | 13 | 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 II | 0a6e45a | 2013-07-11 17:00:41 -0700 | [diff] [blame] | 20 | }) |
| 21 | return is, err |
| 22 | } |
| 23 | |
Mark Peek | 0dbb368 | 2013-08-24 19:04:48 -0700 | [diff] [blame] | 24 | func (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 Peek | 12a81e6 | 2013-08-27 08:15:57 -0700 | [diff] [blame] | 40 | func (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 II | bc0d54a | 2013-07-08 14:45:21 -0700 | [diff] [blame] | 54 | // 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. |
| 57 | type ImageLink struct { |
| 58 | Id string `json:"id"` |
| 59 | Links []Link `json:"links"` |
| 60 | } |
Samuel A. Falvo II | 0a6e45a | 2013-07-11 17:00:41 -0700 | [diff] [blame] | 61 | |
| 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 | // |
| 95 | type 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 | } |