blob: 62e73985b3a2cbabafc4deb807dceb71e2877b20 [file] [log] [blame]
Joe Topjian520307e2015-02-07 05:22:12 +00001package volumeattach
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Joe Topjian520307e2015-02-07 05:22:12 +00006)
7
Jon Perritt12395212016-02-24 10:41:17 -06008// VolumeAttachment controls the attachment of a volume to an instance.
Joe Topjian520307e2015-02-07 05:22:12 +00009type VolumeAttachment struct {
10 // ID is a unique id of the attachment
Jon Perritt12395212016-02-24 10:41:17 -060011 ID string `json:"id"`
Joe Topjian520307e2015-02-07 05:22:12 +000012
13 // Device is what device the volume is attached as
Jon Perritt12395212016-02-24 10:41:17 -060014 Device string `json:"device"`
Joe Topjian520307e2015-02-07 05:22:12 +000015
16 // VolumeID is the ID of the attached volume
Jon Perritt12395212016-02-24 10:41:17 -060017 VolumeID string `json:"volumeId"`
Joe Topjian520307e2015-02-07 05:22:12 +000018
19 // ServerID is the ID of the instance that has the volume attached
Jon Perritt12395212016-02-24 10:41:17 -060020 ServerID string `json:"serverId"`
Joe Topjian520307e2015-02-07 05:22:12 +000021}
22
23// VolumeAttachmentsPage stores a single, only page of VolumeAttachments
24// results from a List call.
25type VolumeAttachmentsPage struct {
26 pagination.SinglePageBase
27}
28
29// IsEmpty determines whether or not a VolumeAttachmentsPage is empty.
30func (page VolumeAttachmentsPage) IsEmpty() (bool, error) {
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.
37func ExtractVolumeAttachments(page pagination.Page) ([]VolumeAttachment, error) {
Jon Perritt12395212016-02-24 10:41:17 -060038 r := page.(VolumeAttachmentsPage)
39 var s struct {
40 VolumeAttachments []VolumeAttachment `json:"volumeAttachments"`
Joe Topjian520307e2015-02-07 05:22:12 +000041 }
Jon Perritt12395212016-02-24 10:41:17 -060042 err := r.ExtractInto(&s)
43 return s.VolumeAttachments, err
Joe Topjian520307e2015-02-07 05:22:12 +000044}
45
46type 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.
52func (r VolumeAttachmentResult) Extract() (*VolumeAttachment, error) {
Jon Perritt12395212016-02-24 10:41:17 -060053 var s struct {
54 VolumeAttachment *VolumeAttachment `json:"volumeAttachment"`
Joe Topjian520307e2015-02-07 05:22:12 +000055 }
Jon Perritt12395212016-02-24 10:41:17 -060056 err := r.ExtractInto(&s)
57 return s.VolumeAttachment, err
Joe Topjian520307e2015-02-07 05:22:12 +000058}
59
60// CreateResult is the response from a Create operation. Call its Extract method to interpret it
61// as a VolumeAttachment.
62type 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.
68type 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.
74type DeleteResult struct {
75 gophercloud.ErrResult
76}