github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/images/results.go (about) 1 package images 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // GetResult is the response from a Get operation. Call its Extract method to 9 // interpret it as an Image. 10 type GetResult struct { 11 gophercloud.Result 12 } 13 14 // DeleteResult is the result from a Delete operation. Call its ExtractErr 15 // method to determine if the call succeeded or failed. 16 type DeleteResult struct { 17 gophercloud.ErrResult 18 } 19 20 // Extract interprets a GetResult as an Image. 21 func (r GetResult) Extract() (*Image, error) { 22 var s struct { 23 Image *Image `json:"image"` 24 } 25 err := r.ExtractInto(&s) 26 return s.Image, err 27 } 28 29 // Image represents an Image returned by the Compute API. 30 type Image struct { 31 // ID is the unique ID of an image. 32 ID string 33 34 // Created is the date when the image was created. 35 Created string 36 37 // MinDisk is the minimum amount of disk a flavor must have to be able 38 // to create a server based on the image, measured in GB. 39 MinDisk int 40 41 // MinRAM is the minimum amount of RAM a flavor must have to be able 42 // to create a server based on the image, measured in MB. 43 MinRAM int 44 45 // Name provides a human-readable moniker for the OS image. 46 Name string 47 48 // The Progress and Status fields indicate image-creation status. 49 Progress int 50 51 // Status is the current status of the image. 52 Status string 53 54 // Update is the date when the image was updated. 55 Updated string 56 57 // Metadata provides free-form key/value pairs that further describe the 58 // image. 59 Metadata map[string]interface{} 60 } 61 62 // ImagePage contains a single page of all Images returne from a ListDetail 63 // operation. Use ExtractImages to convert it into a slice of usable structs. 64 type ImagePage struct { 65 pagination.LinkedPageBase 66 } 67 68 // IsEmpty returns true if an ImagePage contains no Image results. 69 func (page ImagePage) IsEmpty() (bool, error) { 70 if page.StatusCode == 204 { 71 return true, nil 72 } 73 74 images, err := ExtractImages(page) 75 return len(images) == 0, err 76 } 77 78 // NextPageURL uses the response's embedded link reference to navigate to the 79 // next page of results. 80 func (page ImagePage) NextPageURL() (string, error) { 81 var s struct { 82 Links []gophercloud.Link `json:"images_links"` 83 } 84 err := page.ExtractInto(&s) 85 if err != nil { 86 return "", err 87 } 88 return gophercloud.ExtractNextURL(s.Links) 89 } 90 91 // ExtractImages converts a page of List results into a slice of usable Image 92 // structs. 93 func ExtractImages(r pagination.Page) ([]Image, error) { 94 var s struct { 95 Images []Image `json:"images"` 96 } 97 err := (r.(ImagePage)).ExtractInto(&s) 98 return s.Images, err 99 }