blob: e2232fab5591bb71560098a393a415a66c11592a [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"`
jrperritt9b7b9e62016-07-11 22:30:50 -050066*/
67
68// VolumePage is a pagination.pager that is returned from a call to the List function.
69type VolumePage struct {
70 pagination.SinglePageBase
71}
72
73// IsEmpty returns true if a ListResult contains no Volumes.
74func (r VolumePage) IsEmpty() (bool, error) {
75 volumes, err := ExtractVolumes(r)
76 return len(volumes) == 0, err
77}
78
79// ExtractVolumes extracts and returns Volumes. It is used while iterating over a volumes.List call.
80func ExtractVolumes(r pagination.Page) ([]Volume, error) {
jrperritt8f364f72016-11-09 13:09:15 -060081 var s []Volume
82 err := ExtractVolumesInto(r, &s)
83 return s, err
jrperritt9b7b9e62016-07-11 22:30:50 -050084}
85
86type commonResult struct {
87 gophercloud.Result
88}
89
90// Extract will get the Volume object out of the commonResult object.
91func (r commonResult) Extract() (*Volume, error) {
jrperritt8f364f72016-11-09 13:09:15 -060092 var s Volume
93 err := r.ExtractInto(&s)
94 return &s, err
feiskyda546142015-09-17 12:28:23 +080095}
96
jrperritt7dc49462016-11-08 15:09:33 -060097func (r commonResult) ExtractInto(v interface{}) error {
jrperritt2e4415e2016-11-08 16:59:29 -060098 return r.Result.ExtractIntoStructPtr(v, "volume")
99}
jrperritt410c1052016-11-08 15:24:07 -0600100
jrperritt2e4415e2016-11-08 16:59:29 -0600101func ExtractVolumesInto(r pagination.Page, v interface{}) error {
102 return r.(VolumePage).Result.ExtractIntoSlicePtr(v, "volumes")
jrperritt7dc49462016-11-08 15:09:33 -0600103}
104
feiskyda546142015-09-17 12:28:23 +0800105// CreateResult contains the response body and error from a Create request.
106type CreateResult struct {
107 commonResult
108}
109
110// GetResult contains the response body and error from a Get request.
111type GetResult struct {
112 commonResult
113}
114
feiskyda546142015-09-17 12:28:23 +0800115// UpdateResult contains the response body and error from an Update request.
116type UpdateResult struct {
117 commonResult
118}
119
jrperritt9b7b9e62016-07-11 22:30:50 -0500120// DeleteResult contains the response body and error from a Delete request.
121type DeleteResult struct {
122 gophercloud.ErrResult
feiskyda546142015-09-17 12:28:23 +0800123}