blob: 41fbf5c5294f3268c3ae7fdd21a7c037fac83452 [file] [log] [blame]
feiskyda546142015-09-17 12:28:23 +08001package volumes
2
3import (
jrperritt9b7b9e62016-07-11 22:30:50 -05004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
feiskyda546142015-09-17 12:28:23 +08006)
7
jrperritt9b7b9e62016-07-11 22:30:50 -05008type Attachment struct {
Joe Topjian81036a72016-08-06 13:21:39 -06009 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"`
jrperritt9b7b9e62016-07-11 22:30:50 -050016}
17
feiskyda546142015-09-17 12:28:23 +080018// Volume contains all the information associated with an OpenStack Volume.
19type Volume struct {
feiskyda546142015-09-17 12:28:23 +080020 // Unique identifier for the volume.
jrperritt9b7b9e62016-07-11 22:30:50 -050021 ID string `json:"id"`
22 // Current status of the volume.
23 Status string `json:"status"`
feiskyda546142015-09-17 12:28:23 +080024 // Size of the volume in GB.
jrperritt9b7b9e62016-07-11 22:30:50 -050025 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"`
feiskycf0c7fe2015-11-05 22:06:17 +080046 // UserID is the id of the user who created the volume.
jrperritt9b7b9e62016-07-11 22:30:50 -050047 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
jrperritt9b7b9e62016-07-11 22:30:50 -050060// VolumePage is a pagination.pager that is returned from a call to the List function.
61type VolumePage struct {
62 pagination.SinglePageBase
63}
64
65// IsEmpty returns true if a ListResult contains no Volumes.
66func (r VolumePage) IsEmpty() (bool, error) {
67 volumes, err := ExtractVolumes(r)
68 return len(volumes) == 0, err
69}
70
71// ExtractVolumes extracts and returns Volumes. It is used while iterating over a volumes.List call.
72func ExtractVolumes(r pagination.Page) ([]Volume, error) {
jrperritt8f364f72016-11-09 13:09:15 -060073 var s []Volume
74 err := ExtractVolumesInto(r, &s)
75 return s, err
jrperritt9b7b9e62016-07-11 22:30:50 -050076}
77
78type commonResult struct {
79 gophercloud.Result
80}
81
82// Extract will get the Volume object out of the commonResult object.
83func (r commonResult) Extract() (*Volume, error) {
jrperritt8f364f72016-11-09 13:09:15 -060084 var s Volume
85 err := r.ExtractInto(&s)
86 return &s, err
feiskyda546142015-09-17 12:28:23 +080087}
88
jrperritt7dc49462016-11-08 15:09:33 -060089func (r commonResult) ExtractInto(v interface{}) error {
jrperritt2e4415e2016-11-08 16:59:29 -060090 return r.Result.ExtractIntoStructPtr(v, "volume")
91}
jrperritt410c1052016-11-08 15:24:07 -060092
jrperritt2e4415e2016-11-08 16:59:29 -060093func ExtractVolumesInto(r pagination.Page, v interface{}) error {
94 return r.(VolumePage).Result.ExtractIntoSlicePtr(v, "volumes")
jrperritt7dc49462016-11-08 15:09:33 -060095}
96
feiskyda546142015-09-17 12:28:23 +080097// CreateResult contains the response body and error from a Create request.
98type CreateResult struct {
99 commonResult
100}
101
102// GetResult contains the response body and error from a Get request.
103type GetResult struct {
104 commonResult
105}
106
feiskyda546142015-09-17 12:28:23 +0800107// UpdateResult contains the response body and error from an Update request.
108type UpdateResult struct {
109 commonResult
110}
111
jrperritt9b7b9e62016-07-11 22:30:50 -0500112// DeleteResult contains the response body and error from a Delete request.
113type DeleteResult struct {
114 gophercloud.ErrResult
feiskyda546142015-09-17 12:28:23 +0800115}