blob: a03777a893864309d57573d30abb418a69fee556 [file] [log] [blame]
Jon Perrittee6074f2014-04-30 18:42:32 -05001package volumes
2
Jon Perrittd1d6a742014-09-17 01:10:59 -05003import (
Krzysztof Szukiełojć3f41d082017-05-07 14:43:06 +02004 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02005 "gerrit.mcp.mirantis.net/debian/gophercloud.git/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 // Human-readable display name for the volume.
Jon Perritt12395212016-02-24 10:41:17 -060013 Name string `json:"display_name"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020014 // Instances onto which the volume is attached.
Jon Perritt12395212016-02-24 10:41:17 -060015 Attachments []map[string]interface{} `json:"attachments"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020016 // This parameter is no longer used.
Jon Perritt12395212016-02-24 10:41:17 -060017 AvailabilityZone string `json:"availability_zone"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020018 // Indicates whether this is a bootable volume.
Jon Perritt12395212016-02-24 10:41:17 -060019 Bootable string `json:"bootable"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020020 // The date when this volume was created.
Joe Topjian8c592a42016-07-26 01:30:02 +000021 CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020022 // Human-readable description for the volume.
Jon Perritt12395212016-02-24 10:41:17 -060023 Description string `json:"display_description"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020024 // The type of volume to create, either SATA or SSD.
Jon Perritt12395212016-02-24 10:41:17 -060025 VolumeType string `json:"volume_type"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020026 // The ID of the snapshot from which the volume was created
Jon Perritt12395212016-02-24 10:41:17 -060027 SnapshotID string `json:"snapshot_id"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020028 // The ID of another block storage volume from which the current volume was created
Jon Perritt12395212016-02-24 10:41:17 -060029 SourceVolID string `json:"source_volid"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020030 // Arbitrary key-value pairs defined by the user.
Jon Perritt12395212016-02-24 10:41:17 -060031 Metadata map[string]string `json:"metadata"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020032 // Unique identifier for the volume.
Jon Perritt12395212016-02-24 10:41:17 -060033 ID string `json:"id"`
Jamie Hannafordc35ae762014-10-20 18:42:53 +020034 // Size of the volume in GB.
Jon Perritt12395212016-02-24 10:41:17 -060035 Size int `json:"size"`
Jon Perrittee6074f2014-04-30 18:42:32 -050036}
Jon Perrittd1d6a742014-09-17 01:10:59 -050037
Jon Perritt42b3a2a2014-10-02 23:06:07 -050038// CreateResult contains the response body and error from a Create request.
39type CreateResult struct {
40 commonResult
41}
42
43// GetResult contains the response body and error from a Get request.
44type GetResult struct {
45 commonResult
46}
47
Jamie Hannafordce9f9082014-10-27 11:27:12 +010048// DeleteResult contains the response body and error from a Delete request.
49type DeleteResult struct {
Jon Perrittba2395e2014-10-27 15:23:21 -050050 gophercloud.ErrResult
Jamie Hannafordce9f9082014-10-27 11:27:12 +010051}
52
Jon Perritt12395212016-02-24 10:41:17 -060053// VolumePage is a pagination.pager that is returned from a call to the List function.
54type VolumePage struct {
Jon Perritte03b35c2014-09-17 18:15:34 -050055 pagination.SinglePageBase
56}
57
Jon Perritt12395212016-02-24 10:41:17 -060058// IsEmpty returns true if a VolumePage contains no Volumes.
59func (r VolumePage) IsEmpty() (bool, error) {
Jon Perritte03b35c2014-09-17 18:15:34 -050060 volumes, err := ExtractVolumes(r)
Jon Perritt12395212016-02-24 10:41:17 -060061 return len(volumes) == 0, err
Jon Perrittd1d6a742014-09-17 01:10:59 -050062}
63
Jon Perritt42b3a2a2014-10-02 23:06:07 -050064// ExtractVolumes extracts and returns Volumes. It is used while iterating over a volumes.List call.
Jon Perritt31b66462016-02-25 22:25:30 -060065func ExtractVolumes(r pagination.Page) ([]Volume, error) {
Jon Perritt12395212016-02-24 10:41:17 -060066 var s struct {
Jon Perrittd1d6a742014-09-17 01:10:59 -050067 Volumes []Volume `json:"volumes"`
68 }
Jon Perritt31b66462016-02-25 22:25:30 -060069 err := (r.(VolumePage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -060070 return s.Volumes, err
Jon Perrittd1d6a742014-09-17 01:10:59 -050071}
Jon Perritt9b2bf7d2014-09-18 18:47:51 -050072
Jon Perritt42b3a2a2014-10-02 23:06:07 -050073// UpdateResult contains the response body and error from an Update request.
74type UpdateResult struct {
75 commonResult
76}
77
Jon Perritt6d5561b2014-10-01 21:42:15 -050078type commonResult struct {
Ash Wilsonf548aad2014-10-20 08:35:34 -040079 gophercloud.Result
Jon Perritt03cb46d2014-09-22 20:46:20 -050080}
Jon Perritt9b2bf7d2014-09-18 18:47:51 -050081
Jon Perritt42b3a2a2014-10-02 23:06:07 -050082// Extract will get the Volume object out of the commonResult object.
Jon Perritt6d5561b2014-10-01 21:42:15 -050083func (r commonResult) Extract() (*Volume, error) {
Jon Perritt12395212016-02-24 10:41:17 -060084 var s struct {
Jon Perritt9b2bf7d2014-09-18 18:47:51 -050085 Volume *Volume `json:"volume"`
86 }
Jon Perritt12395212016-02-24 10:41:17 -060087 err := r.ExtractInto(&s)
88 return s.Volume, err
Jon Perritt9b2bf7d2014-09-18 18:47:51 -050089}