blob: 2eef0cdbc8c60d4f63be060fcc96051a9b512cd5 [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
45type VolumeAttachmentResult struct {
46 gophercloud.Result
47}
48
49// Extract is a method that attempts to interpret any VolumeAttachment resource
50// response as a VolumeAttachment struct.
51func (r VolumeAttachmentResult) Extract() (*VolumeAttachment, error) {
Jon Perritt12395212016-02-24 10:41:17 -060052 var s struct {
53 VolumeAttachment *VolumeAttachment `json:"volumeAttachment"`
Joe Topjian520307e2015-02-07 05:22:12 +000054 }
Jon Perritt12395212016-02-24 10:41:17 -060055 err := r.ExtractInto(&s)
56 return s.VolumeAttachment, err
Joe Topjian520307e2015-02-07 05:22:12 +000057}
58
59// CreateResult is the response from a Create operation. Call its Extract method to interpret it
60// as a VolumeAttachment.
61type CreateResult struct {
62 VolumeAttachmentResult
63}
64
65// GetResult is the response from a Get operation. Call its Extract method to interpret it
66// as a VolumeAttachment.
67type GetResult struct {
68 VolumeAttachmentResult
69}
70
71// DeleteResult is the response from a Delete operation. Call its Extract method to determine if
72// the call succeeded or failed.
73type DeleteResult struct {
74 gophercloud.ErrResult
75}