feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 1 | package volumes |
| 2 | |
| 3 | import ( |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 6 | ) |
| 7 | |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 8 | type Attachment struct { |
Joe Topjian | 81036a7 | 2016-08-06 13:21:39 -0600 | [diff] [blame] | 9 | AttachedAt gophercloud.JSONRFC3339MilliNoZ `json:"attached_at"` |
| 10 | AttachmentID string `json:"attachment_id"` |
| 11 | Device string `json:"device"` |
| 12 | HostName string `json:"host_name"` |
| 13 | ID string `json:"id"` |
| 14 | ServerID string `json:"server_id"` |
| 15 | VolumeID string `json:"volume_id"` |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 16 | } |
| 17 | |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 18 | // Volume contains all the information associated with an OpenStack Volume. |
| 19 | type Volume struct { |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 20 | // Unique identifier for the volume. |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 21 | ID string `json:"id"` |
| 22 | // Current status of the volume. |
| 23 | Status string `json:"status"` |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 24 | // Size of the volume in GB. |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 25 | Size int `json:"size"` |
| 26 | // AvailabilityZone is which availability zone the volume is in. |
| 27 | AvailabilityZone string `json:"availability_zone"` |
| 28 | // The date when this volume was created. |
| 29 | CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"` |
| 30 | // The date when this volume was last updated |
| 31 | UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"` |
| 32 | // Instances onto which the volume is attached. |
| 33 | Attachments []Attachment `json:"attachments"` |
| 34 | // Human-readable display name for the volume. |
| 35 | Name string `json:"name"` |
| 36 | // Human-readable description for the volume. |
| 37 | Description string `json:"description"` |
| 38 | // The type of volume to create, either SATA or SSD. |
| 39 | VolumeType string `json:"volume_type"` |
| 40 | // The ID of the snapshot from which the volume was created |
| 41 | SnapshotID string `json:"snapshot_id"` |
| 42 | // The ID of another block storage volume from which the current volume was created |
| 43 | SourceVolID string `json:"source_volid"` |
| 44 | // Arbitrary key-value pairs defined by the user. |
| 45 | Metadata map[string]string `json:"metadata"` |
feisky | cf0c7fe | 2015-11-05 22:06:17 +0800 | [diff] [blame] | 46 | // UserID is the id of the user who created the volume. |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 47 | UserID string `json:"user_id"` |
| 48 | // Indicates whether this is a bootable volume. |
| 49 | Bootable string `json:"bootable"` |
| 50 | // Encrypted denotes if the volume is encrypted. |
| 51 | Encrypted bool `json:"encrypted"` |
| 52 | // ReplicationStatus is the status of replication. |
| 53 | ReplicationStatus string `json:"replication_status"` |
| 54 | // ConsistencyGroupID is the consistency group ID. |
| 55 | ConsistencyGroupID string `json:"consistencygroup_id"` |
| 56 | // Multiattach denotes if the volume is multi-attach capable. |
| 57 | Multiattach bool `json:"multiattach"` |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | THESE BELONG IN EXTENSIONS: |
| 62 | // ReplicationDriverData contains data about the replication driver. |
| 63 | ReplicationDriverData string `json:"os-volume-replication:driver_data"` |
| 64 | // ReplicationExtendedStatus contains extended status about replication. |
| 65 | ReplicationExtendedStatus string `json:"os-volume-replication:extended_status"` |
| 66 | // TenantID is the id of the project that owns the volume. |
| 67 | TenantID string `json:"os-vol-tenant-attr:tenant_id"` |
| 68 | */ |
| 69 | |
| 70 | // VolumePage is a pagination.pager that is returned from a call to the List function. |
| 71 | type VolumePage struct { |
| 72 | pagination.SinglePageBase |
| 73 | } |
| 74 | |
| 75 | // IsEmpty returns true if a ListResult contains no Volumes. |
| 76 | func (r VolumePage) IsEmpty() (bool, error) { |
| 77 | volumes, err := ExtractVolumes(r) |
| 78 | return len(volumes) == 0, err |
| 79 | } |
| 80 | |
| 81 | // ExtractVolumes extracts and returns Volumes. It is used while iterating over a volumes.List call. |
| 82 | func ExtractVolumes(r pagination.Page) ([]Volume, error) { |
| 83 | var s struct { |
| 84 | Volumes []Volume `json:"volumes"` |
| 85 | } |
| 86 | err := (r.(VolumePage)).ExtractInto(&s) |
| 87 | return s.Volumes, err |
| 88 | } |
| 89 | |
| 90 | type commonResult struct { |
| 91 | gophercloud.Result |
| 92 | } |
| 93 | |
| 94 | // Extract will get the Volume object out of the commonResult object. |
| 95 | func (r commonResult) Extract() (*Volume, error) { |
| 96 | var s struct { |
| 97 | Volume *Volume `json:"volume"` |
| 98 | } |
jrperritt | 410c105 | 2016-11-08 15:24:07 -0600 | [diff] [blame] | 99 | err := r.Result.ExtractInto(&s) |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 100 | return s.Volume, err |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 101 | } |
| 102 | |
jrperritt | 7dc4946 | 2016-11-08 15:09:33 -0600 | [diff] [blame] | 103 | func (r commonResult) ExtractInto(v interface{}) error { |
jrperritt | 2e4415e | 2016-11-08 16:59:29 -0600 | [diff] [blame^] | 104 | return r.Result.ExtractIntoStructPtr(v, "volume") |
| 105 | } |
jrperritt | 410c105 | 2016-11-08 15:24:07 -0600 | [diff] [blame] | 106 | |
jrperritt | 2e4415e | 2016-11-08 16:59:29 -0600 | [diff] [blame^] | 107 | func ExtractVolumesInto(r pagination.Page, v interface{}) error { |
| 108 | return r.(VolumePage).Result.ExtractIntoSlicePtr(v, "volumes") |
jrperritt | 7dc4946 | 2016-11-08 15:09:33 -0600 | [diff] [blame] | 109 | } |
| 110 | |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 111 | // CreateResult contains the response body and error from a Create request. |
| 112 | type CreateResult struct { |
| 113 | commonResult |
| 114 | } |
| 115 | |
| 116 | // GetResult contains the response body and error from a Get request. |
| 117 | type GetResult struct { |
| 118 | commonResult |
| 119 | } |
| 120 | |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 121 | // UpdateResult contains the response body and error from an Update request. |
| 122 | type UpdateResult struct { |
| 123 | commonResult |
| 124 | } |
| 125 | |
jrperritt | 9b7b9e6 | 2016-07-11 22:30:50 -0500 | [diff] [blame] | 126 | // DeleteResult contains the response body and error from a Delete request. |
| 127 | type DeleteResult struct { |
| 128 | gophercloud.ErrResult |
feisky | da54614 | 2015-09-17 12:28:23 +0800 | [diff] [blame] | 129 | } |