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