github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/volumeattach/results.go (about) 1 package volumeattach 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/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 24 // VolumeAttachmentPage stores a single page all of VolumeAttachment 25 // results from a List call. 26 type VolumeAttachmentPage struct { 27 pagination.SinglePageBase 28 } 29 30 // IsEmpty determines whether or not a VolumeAttachmentPage is empty. 31 func (page VolumeAttachmentPage) IsEmpty() (bool, error) { 32 va, err := ExtractVolumeAttachments(page) 33 return len(va) == 0, err 34 } 35 36 // ExtractVolumeAttachments interprets a page of results as a slice of 37 // VolumeAttachment. 38 func ExtractVolumeAttachments(r pagination.Page) ([]VolumeAttachment, error) { 39 var s struct { 40 VolumeAttachments []VolumeAttachment `json:"volumeAttachments"` 41 } 42 err := (r.(VolumeAttachmentPage)).ExtractInto(&s) 43 return s.VolumeAttachments, err 44 } 45 46 // VolumeAttachmentResult is the result from a volume attachment operation. 47 type VolumeAttachmentResult struct { 48 golangsdk.Result 49 } 50 51 // Extract is a method that attempts to interpret any VolumeAttachment resource 52 // response as a VolumeAttachment struct. 53 func (r VolumeAttachmentResult) Extract() (*VolumeAttachment, error) { 54 var s struct { 55 VolumeAttachment *VolumeAttachment `json:"volumeAttachment"` 56 } 57 err := r.ExtractInto(&s) 58 return s.VolumeAttachment, err 59 } 60 61 // CreateResult is the response from a Create operation. Call its Extract method 62 // to interpret it as a VolumeAttachment. 63 type CreateResult struct { 64 VolumeAttachmentResult 65 } 66 67 // GetResult is the response from a Get operation. Call its Extract method to 68 // interpret it as a VolumeAttachment. 69 type GetResult struct { 70 VolumeAttachmentResult 71 } 72 73 // DeleteResult is the response from a Delete operation. Call its ExtractErr 74 // method to determine if the call succeeded or failed. 75 type DeleteResult struct { 76 golangsdk.ErrResult 77 }