1
// goose/glance - Go package to interact with OpenStack Image Service (Glance) API.
2
// See http://docs.openstack.org/api/openstack-image-service/2.0/content/.
10
"gopkg.in/goose.v1/client"
11
"gopkg.in/goose.v1/errors"
12
goosehttp "gopkg.in/goose.v1/http"
18
apiImagesDetail = "/images/detail"
21
// Client provides a means to access the OpenStack Image Service.
26
// New creates a new Client.
27
func New(client client.Client) *Client {
28
return &Client{client}
31
// Link describes a link to an image in OpenStack.
38
// Image describes an OpenStack image.
45
// ListImages lists IDs, names, and links for available images.
46
func (c *Client) ListImages() ([]Image, error) {
50
requestData := goosehttp.RequestData{RespValue: &resp, ExpectedStatus: []int{http.StatusOK}}
51
err := c.client.SendRequest(client.GET, "compute", apiImages, &requestData)
53
return nil, errors.Newf(err, "failed to get list of images")
55
return resp.Images, nil
58
// ImageMetadata describes metadata of an image
59
type ImageMetadata struct {
61
State string `json:"image_state"`
62
Location string `json:"image_location"`
63
KernelId interface{} `json:"kernel_id"`
64
ProjectId interface{} `json:"project_id"`
65
RAMDiskId interface{} `json:"ramdisk_id"`
66
OwnerId interface{} `json:"owner_id"`
69
// ImageDetail describes extended information about an image.
70
type ImageDetail struct {
77
MinimumRAM int `json:"minRam"`
78
MinimumDisk int `json:"minDisk"`
80
Metadata ImageMetadata
83
// ListImageDetails lists all details for available images.
84
func (c *Client) ListImagesDetail() ([]ImageDetail, error) {
88
requestData := goosehttp.RequestData{RespValue: &resp}
89
err := c.client.SendRequest(client.GET, "compute", apiImagesDetail, &requestData)
91
return nil, errors.Newf(err, "failed to get list of image details")
93
return resp.Images, nil
96
// GetImageDetail lists details of the specified image.
97
func (c *Client) GetImageDetail(imageId string) (*ImageDetail, error) {
101
url := fmt.Sprintf("%s/%s", apiImages, imageId)
102
requestData := goosehttp.RequestData{RespValue: &resp}
103
err := c.client.SendRequest(client.GET, "compute", url, &requestData)
105
return nil, errors.Newf(err, "failed to get details of imageId: %s", imageId)
107
return &resp.Image, nil