github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/images/requests.go (about)

     1  package images
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // ListOptsBuilder allows extensions to add additional parameters to the
     9  // ListDetail request.
    10  type ListOptsBuilder interface {
    11  	ToImageListQuery() (string, error)
    12  }
    13  
    14  // ListOpts contain options filtering Images returned from a call to ListDetail.
    15  type ListOpts struct {
    16  	// ChangesSince filters Images based on the last changed status (in date-time
    17  	// format).
    18  	ChangesSince string `q:"changes-since"`
    19  
    20  	// Limit limits the number of Images to return.
    21  	Limit int `q:"limit"`
    22  
    23  	// Mark is an Image UUID at which to set a marker.
    24  	Marker string `q:"marker"`
    25  
    26  	// Name is the name of the Image.
    27  	Name string `q:"name"`
    28  
    29  	// Server is the name of the Server (in URL format).
    30  	Server string `q:"server"`
    31  
    32  	// Status is the current status of the Image.
    33  	Status string `q:"status"`
    34  
    35  	// Type is the type of image (e.g. BASE, SERVER, ALL).
    36  	Type string `q:"type"`
    37  }
    38  
    39  // ToImageListQuery formats a ListOpts into a query string.
    40  func (opts ListOpts) ToImageListQuery() (string, error) {
    41  	q, err := gophercloud.BuildQueryString(opts)
    42  	return q.String(), err
    43  }
    44  
    45  // ListDetail enumerates the available images.
    46  func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    47  	url := listDetailURL(client)
    48  	if opts != nil {
    49  		query, err := opts.ToImageListQuery()
    50  		if err != nil {
    51  			return pagination.Pager{Err: err}
    52  		}
    53  		url += query
    54  	}
    55  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    56  		return ImagePage{pagination.LinkedPageBase{PageResult: r}}
    57  	})
    58  }
    59  
    60  // Get returns data about a specific image by its ID.
    61  func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
    62  	resp, err := client.Get(getURL(client, id), &r.Body, nil)
    63  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    64  	return
    65  }
    66  
    67  // Delete deletes the specified image ID.
    68  func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
    69  	resp, err := client.Delete(deleteURL(client, id), nil)
    70  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    71  	return
    72  }