blob: 96864aee2cc68605144c8b4febb9e4acea857deb [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 {
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
feiskyda546142015-09-17 12:28:23 +080017// Volume contains all the information associated with an OpenStack Volume.
18type Volume struct {
feiskyda546142015-09-17 12:28:23 +080019 // Unique identifier for the volume.
jrperritt9b7b9e62016-07-11 22:30:50 -050020 ID string `json:"id"`
21 // Current status of the volume.
22 Status string `json:"status"`
feiskyda546142015-09-17 12:28:23 +080023 // Size of the volume in GB.
jrperritt9b7b9e62016-07-11 22:30:50 -050024 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"`
feiskycf0c7fe2015-11-05 22:06:17 +080045 // UserID is the id of the user who created the volume.
jrperritt9b7b9e62016-07-11 22:30:50 -050046 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/*
60THESE BELONG IN EXTENSIONS:
61// ReplicationDriverData contains data about the replication driver.
62ReplicationDriverData string `json:"os-volume-replication:driver_data"`
63// ReplicationExtendedStatus contains extended status about replication.
64ReplicationExtendedStatus string `json:"os-volume-replication:extended_status"`
65// TenantID is the id of the project that owns the volume.
66TenantID 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.
70type VolumePage struct {
71 pagination.SinglePageBase
72}
73
74// IsEmpty returns true if a ListResult contains no Volumes.
75func (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.
81func 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
89type commonResult struct {
90 gophercloud.Result
91}
92
93// Extract will get the Volume object out of the commonResult object.
94func (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
feiskyda546142015-09-17 12:28:23 +0800100}
101
102// CreateResult contains the response body and error from a Create request.
103type CreateResult struct {
104 commonResult
105}
106
107// GetResult contains the response body and error from a Get request.
108type GetResult struct {
109 commonResult
110}
111
feiskyda546142015-09-17 12:28:23 +0800112// UpdateResult contains the response body and error from an Update request.
113type UpdateResult struct {
114 commonResult
115}
116
jrperritt9b7b9e62016-07-11 22:30:50 -0500117// DeleteResult contains the response body and error from a Delete request.
118type DeleteResult struct {
119 gophercloud.ErrResult
feiskyda546142015-09-17 12:28:23 +0800120}