blob: 53faf5d3af24d55f758a2d803ef2d2da4595e35f [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
Jon Perritt31b66462016-02-25 22:25:30 -060023// VolumeAttachmentPage stores a single, only page of VolumeAttachments
Joe Topjian520307e2015-02-07 05:22:12 +000024// results from a List call.
Jon Perritt31b66462016-02-25 22:25:30 -060025type VolumeAttachmentPage struct {
Joe Topjian520307e2015-02-07 05:22:12 +000026 pagination.SinglePageBase
27}
28
29// IsEmpty determines whether or not a VolumeAttachmentsPage is empty.
Jon Perritt31b66462016-02-25 22:25:30 -060030func (page VolumeAttachmentPage) IsEmpty() (bool, error) {
Joe Topjian520307e2015-02-07 05:22:12 +000031 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 Perritt31b66462016-02-25 22:25:30 -060037func ExtractVolumeAttachments(r pagination.Page) ([]VolumeAttachment, error) {
Jon Perritt12395212016-02-24 10:41:17 -060038 var s struct {
39 VolumeAttachments []VolumeAttachment `json:"volumeAttachments"`
Joe Topjian520307e2015-02-07 05:22:12 +000040 }
Jon Perritt31b66462016-02-25 22:25:30 -060041 err := (r.(VolumeAttachmentPage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -060042 return s.VolumeAttachments, err
Joe Topjian520307e2015-02-07 05:22:12 +000043}
44
Jon Perritt3860b512016-03-29 12:01:48 -050045// VolumeAttachmentResult is the result from a volume attachment operation.
Joe Topjian520307e2015-02-07 05:22:12 +000046type 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}