Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 1 | package volumeattach |
| 2 | |
| 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" |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 6 | ) |
| 7 | |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 8 | // VolumeAttachment controls the attachment of a volume to an instance. |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 9 | type VolumeAttachment struct { |
| 10 | // ID is a unique id of the attachment |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 11 | ID string `json:"id"` |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 12 | |
| 13 | // Device is what device the volume is attached as |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 14 | Device string `json:"device"` |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 15 | |
| 16 | // VolumeID is the ID of the attached volume |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 17 | VolumeID string `json:"volumeId"` |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 18 | |
| 19 | // ServerID is the ID of the instance that has the volume attached |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 20 | ServerID string `json:"serverId"` |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 21 | } |
| 22 | |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 23 | // VolumeAttachmentPage stores a single, only page of VolumeAttachments |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 24 | // results from a List call. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 25 | type VolumeAttachmentPage struct { |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 26 | pagination.SinglePageBase |
| 27 | } |
| 28 | |
| 29 | // IsEmpty determines whether or not a VolumeAttachmentsPage is empty. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 30 | func (page VolumeAttachmentPage) IsEmpty() (bool, error) { |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 31 | va, err := ExtractVolumeAttachments(page) |
| 32 | return len(va) == 0, err |
| 33 | } |
| 34 | |
| 35 | // ExtractVolumeAttachments interprets a page of results as a slice of |
| 36 | // VolumeAttachments. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 37 | func ExtractVolumeAttachments(r pagination.Page) ([]VolumeAttachment, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 38 | var s struct { |
| 39 | VolumeAttachments []VolumeAttachment `json:"volumeAttachments"` |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 40 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 41 | err := (r.(VolumeAttachmentPage)).ExtractInto(&s) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 42 | return s.VolumeAttachments, err |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 45 | // VolumeAttachmentResult is the result from a volume attachment operation. |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 46 | type VolumeAttachmentResult struct { |
| 47 | gophercloud.Result |
| 48 | } |
| 49 | |
| 50 | // Extract is a method that attempts to interpret any VolumeAttachment resource |
| 51 | // response as a VolumeAttachment struct. |
| 52 | func (r VolumeAttachmentResult) Extract() (*VolumeAttachment, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 53 | var s struct { |
| 54 | VolumeAttachment *VolumeAttachment `json:"volumeAttachment"` |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 55 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 56 | err := r.ExtractInto(&s) |
| 57 | return s.VolumeAttachment, err |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | // CreateResult is the response from a Create operation. Call its Extract method to interpret it |
| 61 | // as a VolumeAttachment. |
| 62 | type CreateResult struct { |
| 63 | VolumeAttachmentResult |
| 64 | } |
| 65 | |
| 66 | // GetResult is the response from a Get operation. Call its Extract method to interpret it |
| 67 | // as a VolumeAttachment. |
| 68 | type GetResult struct { |
| 69 | VolumeAttachmentResult |
| 70 | } |
| 71 | |
| 72 | // DeleteResult is the response from a Delete operation. Call its Extract method to determine if |
| 73 | // the call succeeded or failed. |
| 74 | type DeleteResult struct { |
| 75 | gophercloud.ErrResult |
| 76 | } |