blob: 1208e1014207eb615ac5fbc2a0c692c6ddb5b6a7 [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
60/*
61THESE BELONG IN EXTENSIONS:
62// ReplicationDriverData contains data about the replication driver.
63ReplicationDriverData string `json:"os-volume-replication:driver_data"`
64// ReplicationExtendedStatus contains extended status about replication.
65ReplicationExtendedStatus string `json:"os-volume-replication:extended_status"`
66// TenantID is the id of the project that owns the volume.
67TenantID 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.
71type VolumePage struct {
72 pagination.SinglePageBase
73}
74
75// IsEmpty returns true if a ListResult contains no Volumes.
76func (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.
82func 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
90type commonResult struct {
91 gophercloud.Result
92}
93
94// Extract will get the Volume object out of the commonResult object.
95func (r commonResult) Extract() (*Volume, error) {
96 var s struct {
97 Volume *Volume `json:"volume"`
98 }
jrperritt410c1052016-11-08 15:24:07 -060099 err := r.Result.ExtractInto(&s)
jrperritt9b7b9e62016-07-11 22:30:50 -0500100 return s.Volume, err
feiskyda546142015-09-17 12:28:23 +0800101}
102
jrperritt7dc49462016-11-08 15:09:33 -0600103func (r commonResult) ExtractInto(v interface{}) error {
jrperritt2e4415e2016-11-08 16:59:29 -0600104 return r.Result.ExtractIntoStructPtr(v, "volume")
105}
jrperritt410c1052016-11-08 15:24:07 -0600106
jrperritt2e4415e2016-11-08 16:59:29 -0600107func ExtractVolumesInto(r pagination.Page, v interface{}) error {
108 return r.(VolumePage).Result.ExtractIntoSlicePtr(v, "volumes")
jrperritt7dc49462016-11-08 15:09:33 -0600109}
110
feiskyda546142015-09-17 12:28:23 +0800111// CreateResult contains the response body and error from a Create request.
112type CreateResult struct {
113 commonResult
114}
115
116// GetResult contains the response body and error from a Get request.
117type GetResult struct {
118 commonResult
119}
120
feiskyda546142015-09-17 12:28:23 +0800121// UpdateResult contains the response body and error from an Update request.
122type UpdateResult struct {
123 commonResult
124}
125
jrperritt9b7b9e62016-07-11 22:30:50 -0500126// DeleteResult contains the response body and error from a Delete request.
127type DeleteResult struct {
128 gophercloud.ErrResult
feiskyda546142015-09-17 12:28:23 +0800129}