github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/volumeattach/results.go (about) 1 package volumeattach 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // VolumeAttachment contains attachment information between a volume 9 // and server. 10 type VolumeAttachment struct { 11 // ID is a unique id of the attachment. 12 ID string `json:"id"` 13 14 // Device is what device the volume is attached as. 15 Device string `json:"device"` 16 17 // VolumeID is the ID of the attached volume. 18 VolumeID string `json:"volumeId"` 19 20 // ServerID is the ID of the instance that has the volume attached. 21 ServerID string `json:"serverId"` 22 23 // Tag is a device role tag that can be applied to a volume when attaching 24 // it to the VM. Requires 2.70 microversion 25 Tag *string `json:"tag"` 26 27 // DeleteOnTermination specifies whether or not to delete the volume when the server 28 // is destroyed. Requires 2.79 microversion 29 DeleteOnTermination *bool `json:"delete_on_termination"` 30 } 31 32 // VolumeAttachmentPage stores a single page all of VolumeAttachment 33 // results from a List call. 34 type VolumeAttachmentPage struct { 35 pagination.SinglePageBase 36 } 37 38 // IsEmpty determines whether or not a VolumeAttachmentPage is empty. 39 func (page VolumeAttachmentPage) IsEmpty() (bool, error) { 40 if page.StatusCode == 204 { 41 return true, nil 42 } 43 44 va, err := ExtractVolumeAttachments(page) 45 return len(va) == 0, err 46 } 47 48 // ExtractVolumeAttachments interprets a page of results as a slice of 49 // VolumeAttachment. 50 func ExtractVolumeAttachments(r pagination.Page) ([]VolumeAttachment, error) { 51 var s struct { 52 VolumeAttachments []VolumeAttachment `json:"volumeAttachments"` 53 } 54 err := (r.(VolumeAttachmentPage)).ExtractInto(&s) 55 return s.VolumeAttachments, err 56 } 57 58 // VolumeAttachmentResult is the result from a volume attachment operation. 59 type VolumeAttachmentResult struct { 60 gophercloud.Result 61 } 62 63 // Extract is a method that attempts to interpret any VolumeAttachment resource 64 // response as a VolumeAttachment struct. 65 func (r VolumeAttachmentResult) Extract() (*VolumeAttachment, error) { 66 var s struct { 67 VolumeAttachment *VolumeAttachment `json:"volumeAttachment"` 68 } 69 err := r.ExtractInto(&s) 70 return s.VolumeAttachment, err 71 } 72 73 // CreateResult is the response from a Create operation. Call its Extract method 74 // to interpret it as a VolumeAttachment. 75 type CreateResult struct { 76 VolumeAttachmentResult 77 } 78 79 // GetResult is the response from a Get operation. Call its Extract method to 80 // interpret it as a VolumeAttachment. 81 type GetResult struct { 82 VolumeAttachmentResult 83 } 84 85 // DeleteResult is the response from a Delete operation. Call its ExtractErr 86 // method to determine if the call succeeded or failed. 87 type DeleteResult struct { 88 gophercloud.ErrResult 89 }