Jon Perritt | ee6074f | 2014-04-30 18:42:32 -0500 | [diff] [blame] | 1 | package volumes |
| 2 | |
Jon Perritt | d1d6a74 | 2014-09-17 01:10:59 -0500 | [diff] [blame] | 3 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Jon Perritt | d1d6a74 | 2014-09-17 01:10:59 -0500 | [diff] [blame] | 6 | ) |
| 7 | |
Jon Perritt | 42b3a2a | 2014-10-02 23:06:07 -0500 | [diff] [blame] | 8 | // Volume contains all the information associated with an OpenStack Volume. |
Jon Perritt | e77b9b2 | 2014-05-01 13:11:12 -0500 | [diff] [blame] | 9 | type Volume struct { |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 10 | // Current status of the volume. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 11 | Status string `json:"status"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 12 | |
| 13 | // Human-readable display name for the volume. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 14 | Name string `json:"display_name"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 15 | |
| 16 | // Instances onto which the volume is attached. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 17 | Attachments []map[string]interface{} `json:"attachments"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 18 | |
| 19 | // This parameter is no longer used. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 20 | AvailabilityZone string `json:"availability_zone"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 21 | |
| 22 | // Indicates whether this is a bootable volume. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 23 | Bootable string `json:"bootable"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 24 | |
| 25 | // The date when this volume was created. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 26 | CreatedAt gophercloud.JSONRFC3339Milli `json:"created_at"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 27 | |
| 28 | // Human-readable description for the volume. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 29 | Description string `json:"display_description"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 30 | |
| 31 | // The type of volume to create, either SATA or SSD. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 32 | VolumeType string `json:"volume_type"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 33 | |
| 34 | // The ID of the snapshot from which the volume was created |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 35 | SnapshotID string `json:"snapshot_id"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 36 | |
| 37 | // The ID of another block storage volume from which the current volume was created |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 38 | SourceVolID string `json:"source_volid"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 39 | |
| 40 | // Arbitrary key-value pairs defined by the user. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 41 | Metadata map[string]string `json:"metadata"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 42 | |
| 43 | // Unique identifier for the volume. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 44 | ID string `json:"id"` |
Jamie Hannaford | c35ae76 | 2014-10-20 18:42:53 +0200 | [diff] [blame] | 45 | |
| 46 | // Size of the volume in GB. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 47 | Size int `json:"size"` |
Jon Perritt | ee6074f | 2014-04-30 18:42:32 -0500 | [diff] [blame] | 48 | } |
Jon Perritt | d1d6a74 | 2014-09-17 01:10:59 -0500 | [diff] [blame] | 49 | |
Jon Perritt | 42b3a2a | 2014-10-02 23:06:07 -0500 | [diff] [blame] | 50 | // CreateResult contains the response body and error from a Create request. |
| 51 | type CreateResult struct { |
| 52 | commonResult |
| 53 | } |
| 54 | |
| 55 | // GetResult contains the response body and error from a Get request. |
| 56 | type GetResult struct { |
| 57 | commonResult |
| 58 | } |
| 59 | |
Jamie Hannaford | ce9f908 | 2014-10-27 11:27:12 +0100 | [diff] [blame] | 60 | // DeleteResult contains the response body and error from a Delete request. |
| 61 | type DeleteResult struct { |
Jon Perritt | ba2395e | 2014-10-27 15:23:21 -0500 | [diff] [blame] | 62 | gophercloud.ErrResult |
Jamie Hannaford | ce9f908 | 2014-10-27 11:27:12 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 65 | // VolumePage is a pagination.pager that is returned from a call to the List function. |
| 66 | type VolumePage struct { |
Jon Perritt | e03b35c | 2014-09-17 18:15:34 -0500 | [diff] [blame] | 67 | pagination.SinglePageBase |
| 68 | } |
| 69 | |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 70 | // IsEmpty returns true if a VolumePage contains no Volumes. |
| 71 | func (r VolumePage) IsEmpty() (bool, error) { |
Jon Perritt | e03b35c | 2014-09-17 18:15:34 -0500 | [diff] [blame] | 72 | volumes, err := ExtractVolumes(r) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 73 | return len(volumes) == 0, err |
Jon Perritt | d1d6a74 | 2014-09-17 01:10:59 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Jon Perritt | 42b3a2a | 2014-10-02 23:06:07 -0500 | [diff] [blame] | 76 | // ExtractVolumes extracts and returns Volumes. It is used while iterating over a volumes.List call. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 77 | func ExtractVolumes(r pagination.Page) ([]Volume, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 78 | var s struct { |
Jon Perritt | d1d6a74 | 2014-09-17 01:10:59 -0500 | [diff] [blame] | 79 | Volumes []Volume `json:"volumes"` |
| 80 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 81 | err := (r.(VolumePage)).ExtractInto(&s) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 82 | return s.Volumes, err |
Jon Perritt | d1d6a74 | 2014-09-17 01:10:59 -0500 | [diff] [blame] | 83 | } |
Jon Perritt | 9b2bf7d | 2014-09-18 18:47:51 -0500 | [diff] [blame] | 84 | |
Jon Perritt | 42b3a2a | 2014-10-02 23:06:07 -0500 | [diff] [blame] | 85 | // UpdateResult contains the response body and error from an Update request. |
| 86 | type UpdateResult struct { |
| 87 | commonResult |
| 88 | } |
| 89 | |
Jon Perritt | 6d5561b | 2014-10-01 21:42:15 -0500 | [diff] [blame] | 90 | type commonResult struct { |
Ash Wilson | f548aad | 2014-10-20 08:35:34 -0400 | [diff] [blame] | 91 | gophercloud.Result |
Jon Perritt | 03cb46d | 2014-09-22 20:46:20 -0500 | [diff] [blame] | 92 | } |
Jon Perritt | 9b2bf7d | 2014-09-18 18:47:51 -0500 | [diff] [blame] | 93 | |
Jon Perritt | 42b3a2a | 2014-10-02 23:06:07 -0500 | [diff] [blame] | 94 | // Extract will get the Volume object out of the commonResult object. |
Jon Perritt | 6d5561b | 2014-10-01 21:42:15 -0500 | [diff] [blame] | 95 | func (r commonResult) Extract() (*Volume, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 96 | var s struct { |
Jon Perritt | 9b2bf7d | 2014-09-18 18:47:51 -0500 | [diff] [blame] | 97 | Volume *Volume `json:"volume"` |
| 98 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 99 | err := r.ExtractInto(&s) |
| 100 | return s.Volume, err |
Jon Perritt | 9b2bf7d | 2014-09-18 18:47:51 -0500 | [diff] [blame] | 101 | } |