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