blob: 7ce5139519c764f4375a71a022847bc758263887 [file] [log] [blame]
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -08001package images
2
3import (
Ash Wilson9ccf9b62014-09-17 10:07:52 -04004 "github.com/rackspace/gophercloud"
5 "github.com/rackspace/gophercloud/pagination"
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -08006)
7
Jon Perritt04851d32014-10-14 02:07:13 -05008// ListOptsBuilder allows extensions to add additional parameters to the
9// List request.
10type ListOptsBuilder interface {
Jon Perritt26780d52014-10-14 11:35:58 -050011 ToImageListQuery() (string, error)
Jon Perritt04851d32014-10-14 02:07:13 -050012}
13
Jon Perrittef168e62014-10-08 11:14:05 -050014// ListOpts contain options for limiting the number of Images returned from a call to ListDetail.
15type ListOpts struct {
16 // When the image last changed status (in date-time format).
17 ChangesSince string `q:"changes-since"`
18 // The number of Images to return.
19 Limit int `q:"limit"`
20 // UUID of the Image at which to set a marker.
21 Marker string `q:"marker"`
22 // The name of the Image.
Joe Topjian661a3c82015-02-11 03:56:12 +000023 Name string `q:"name"`
Jon Perrittef168e62014-10-08 11:14:05 -050024 // The name of the Server (in URL format).
25 Server string `q:"server"`
26 // The current status of the Image.
27 Status string `q:"status"`
28 // The value of the type of image (e.g. BASE, SERVER, ALL)
29 Type string `q:"type"`
30}
31
Jon Perritt26780d52014-10-14 11:35:58 -050032// ToImageListQuery formats a ListOpts into a query string.
33func (opts ListOpts) ToImageListQuery() (string, error) {
Jon Perritt04851d32014-10-14 02:07:13 -050034 q, err := gophercloud.BuildQueryString(opts)
35 if err != nil {
36 return "", err
37 }
38 return q.String(), nil
39}
40
Jon Perrittef168e62014-10-08 11:14:05 -050041// ListDetail enumerates the available images.
Jon Perritt04851d32014-10-14 02:07:13 -050042func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
Jon Perrittef168e62014-10-08 11:14:05 -050043 url := listDetailURL(client)
44 if opts != nil {
Jon Perritt26780d52014-10-14 11:35:58 -050045 query, err := opts.ToImageListQuery()
Jon Perrittef168e62014-10-08 11:14:05 -050046 if err != nil {
47 return pagination.Pager{Err: err}
48 }
Jon Perritt04851d32014-10-14 02:07:13 -050049 url += query
Jon Perrittef168e62014-10-08 11:14:05 -050050 }
51
Ash Wilsonb8b16f82014-10-20 10:19:49 -040052 createPage := func(r pagination.PageResult) pagination.Page {
53 return ImagePage{pagination.LinkedPageBase{PageResult: r}}
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -080054 }
55
Jon Perrittef168e62014-10-08 11:14:05 -050056 return pagination.NewPager(client, url, createPage)
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -080057}
Ash Wilson7ddf0362014-09-17 10:59:09 -040058
59// Get acquires additional detail about a specific image by ID.
Alex Gaynora6d5f9f2014-10-27 10:52:32 -070060// Use ExtractImage() to interpret the result as an openstack Image.
Ash Wilsond2f87032014-09-25 11:34:41 -040061func Get(client *gophercloud.ServiceClient, id string) GetResult {
Ash Wilson7ddf0362014-09-17 10:59:09 -040062 var result GetResult
Jamie Hannaford6a3a78f2015-03-24 14:56:12 +010063 _, result.Err = client.Get(getURL(client, id), &result.Body, nil)
Ash Wilsond2f87032014-09-25 11:34:41 -040064 return result
Ash Wilson7ddf0362014-09-17 10:59:09 -040065}
Jesse Nelsonab02e572015-04-14 16:28:21 -070066
67// Delete deletes the specified image ID.
68func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
69 var result DeleteResult
Jesse Nelson8c1e0372015-04-16 10:54:40 -070070 _, result.Err = client.Delete(deleteURL(client, id), nil)
Jesse Nelsonab02e572015-04-14 16:28:21 -070071 return result
72}