blob: 09d1ba640ca6703b19a65d9956c7fd5f29c49e5d [file] [log] [blame]
Jon Perrittee6074f2014-04-30 18:42:32 -05001package volumes
2
Jon Perrittd1d6a742014-09-17 01:10:59 -05003import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Jon Perrittd1d6a742014-09-17 01:10:59 -05006)
7
Jon Perritt42b3a2a2014-10-02 23:06:07 -05008// Volume contains all the information associated with an OpenStack Volume.
Jon Perritte77b9b22014-05-01 13:11:12 -05009type Volume struct {
Jamie Hannafordc35ae762014-10-20 18:42:53 +020010 // Current status of the volume.
Jon Perritt12395212016-02-24 10:41:17 -060011 Status string `json:"status"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020012
13 // Human-readable display name for the volume.
Jon Perritt12395212016-02-24 10:41:17 -060014 Name string `json:"display_name"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020015
16 // Instances onto which the volume is attached.
Jon Perritt12395212016-02-24 10:41:17 -060017 Attachments []map[string]interface{} `json:"attachments"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020018
19 // This parameter is no longer used.
Jon Perritt12395212016-02-24 10:41:17 -060020 AvailabilityZone string `json:"availability_zone"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020021
22 // Indicates whether this is a bootable volume.
Jon Perritt12395212016-02-24 10:41:17 -060023 Bootable string `json:"bootable"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020024
25 // The date when this volume was created.
Jon Perritt12395212016-02-24 10:41:17 -060026 CreatedAt gophercloud.JSONRFC3339Milli `json:"created_at"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020027
28 // Human-readable description for the volume.
Jon Perritt12395212016-02-24 10:41:17 -060029 Description string `json:"display_description"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020030
31 // The type of volume to create, either SATA or SSD.
Jon Perritt12395212016-02-24 10:41:17 -060032 VolumeType string `json:"volume_type"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020033
34 // The ID of the snapshot from which the volume was created
Jon Perritt12395212016-02-24 10:41:17 -060035 SnapshotID string `json:"snapshot_id"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020036
37 // The ID of another block storage volume from which the current volume was created
Jon Perritt12395212016-02-24 10:41:17 -060038 SourceVolID string `json:"source_volid"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020039
40 // Arbitrary key-value pairs defined by the user.
Jon Perritt12395212016-02-24 10:41:17 -060041 Metadata map[string]string `json:"metadata"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020042
43 // Unique identifier for the volume.
Jon Perritt12395212016-02-24 10:41:17 -060044 ID string `json:"id"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020045
46 // Size of the volume in GB.
Jon Perritt12395212016-02-24 10:41:17 -060047 Size int `json:"size"`
Jon Perrittee6074f2014-04-30 18:42:32 -050048}
Jon Perrittd1d6a742014-09-17 01:10:59 -050049
Jon Perritt42b3a2a2014-10-02 23:06:07 -050050// CreateResult contains the response body and error from a Create request.
51type CreateResult struct {
52 commonResult
53}
54
55// GetResult contains the response body and error from a Get request.
56type GetResult struct {
57 commonResult
58}
59
Jamie Hannafordce9f9082014-10-27 11:27:12 +010060// DeleteResult contains the response body and error from a Delete request.
61type DeleteResult struct {
Jon Perrittba2395e2014-10-27 15:23:21 -050062 gophercloud.ErrResult
Jamie Hannafordce9f9082014-10-27 11:27:12 +010063}
64
Jon Perritt12395212016-02-24 10:41:17 -060065// VolumePage is a pagination.pager that is returned from a call to the List function.
66type VolumePage struct {
Jon Perritte03b35c2014-09-17 18:15:34 -050067 pagination.SinglePageBase
68}
69
Jon Perritt12395212016-02-24 10:41:17 -060070// IsEmpty returns true if a VolumePage contains no Volumes.
71func (r VolumePage) IsEmpty() (bool, error) {
Jon Perritte03b35c2014-09-17 18:15:34 -050072 volumes, err := ExtractVolumes(r)
Jon Perritt12395212016-02-24 10:41:17 -060073 return len(volumes) == 0, err
Jon Perrittd1d6a742014-09-17 01:10:59 -050074}
75
Jon Perritt42b3a2a2014-10-02 23:06:07 -050076// ExtractVolumes extracts and returns Volumes. It is used while iterating over a volumes.List call.
Jon Perritt31b66462016-02-25 22:25:30 -060077func ExtractVolumes(r pagination.Page) ([]Volume, error) {
Jon Perritt12395212016-02-24 10:41:17 -060078 var s struct {
Jon Perrittd1d6a742014-09-17 01:10:59 -050079 Volumes []Volume `json:"volumes"`
80 }
Jon Perritt31b66462016-02-25 22:25:30 -060081 err := (r.(VolumePage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -060082 return s.Volumes, err
Jon Perrittd1d6a742014-09-17 01:10:59 -050083}
Jon Perritt9b2bf7d2014-09-18 18:47:51 -050084
Jon Perritt42b3a2a2014-10-02 23:06:07 -050085// UpdateResult contains the response body and error from an Update request.
86type UpdateResult struct {
87 commonResult
88}
89
Jon Perritt6d5561b2014-10-01 21:42:15 -050090type commonResult struct {
Ash Wilsonf548aad2014-10-20 08:35:34 -040091 gophercloud.Result
Jon Perritt03cb46d2014-09-22 20:46:20 -050092}
Jon Perritt9b2bf7d2014-09-18 18:47:51 -050093
Jon Perritt42b3a2a2014-10-02 23:06:07 -050094// Extract will get the Volume object out of the commonResult object.
Jon Perritt6d5561b2014-10-01 21:42:15 -050095func (r commonResult) Extract() (*Volume, error) {
Jon Perritt12395212016-02-24 10:41:17 -060096 var s struct {
Jon Perritt9b2bf7d2014-09-18 18:47:51 -050097 Volume *Volume `json:"volume"`
98 }
Jon Perritt12395212016-02-24 10:41:17 -060099 err := r.ExtractInto(&s)
100 return s.Volume, err
Jon Perritt9b2bf7d2014-09-18 18:47:51 -0500101}