block storage v1 comments
diff --git a/openstack/blockstorage/v1/snapshots/requests.go b/openstack/blockstorage/v1/snapshots/requests.go
index 7dcbc46..0e4e8f8 100644
--- a/openstack/blockstorage/v1/snapshots/requests.go
+++ b/openstack/blockstorage/v1/snapshots/requests.go
@@ -8,14 +8,20 @@
"github.com/racker/perigee"
)
+// CreateOpts contains options for creating a Snapshot. This object is passed to
+// the snapshots.Create function. For more information about these parameters,
+// see the Snapshot object.
type CreateOpts struct {
- Description string
- Force bool
- Metadata map[string]interface{}
- Name string
- VolumeID string
+ Description string // OPTIONAL
+ Force bool // OPTIONAL
+ Metadata map[string]interface{} // OPTIONAL
+ Name string // OPTIONAL
+ VolumeID string // REQUIRED
}
+// Create will create a new Snapshot based on the values in CreateOpts. To extract
+// the Snapshot object from the response, call the Extract method on the
+// CreateResult.
func Create(client *gophercloud.ServiceClient, opts *CreateOpts) CreateResult {
type snapshot struct {
Description *string `json:"display_description,omitempty"`
@@ -49,6 +55,7 @@
return res
}
+// Delete will delete the existing Snapshot with the provided ID.
func Delete(client *gophercloud.ServiceClient, id string) error {
_, err := perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
@@ -57,6 +64,8 @@
return err
}
+// Get retrieves the Snapshot with the provided ID. To extract the Snapshot object
+// from the response, call the Extract method on the GetResult.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var res GetResult
_, res.Err = perigee.Request("GET", getURL(client, id), perigee.Options{
@@ -67,12 +76,15 @@
return res
}
+// ListOpts hold options for listing Snapshots. It is passed to the
+// snapshots.List function.
type ListOpts struct {
Name string `q:"display_name"`
Status string `q:"status"`
VolumeID string `q:"volume_id"`
}
+// List returns Snapshots optionally limited by the conditions provided in ListOpts.
func List(client *gophercloud.ServiceClient, opts *ListOpts) pagination.Pager {
url := listURL(client)
if opts != nil {
@@ -89,11 +101,16 @@
return pagination.NewPager(client, url, createPage)
}
+// UpdateOpts contain options for updating an existing Snapshot. This object is
+// passed to the snapshots.Update function. For more information about the
+// parameters, see the Snapshot object.
type UpdateOpts struct {
Description string
Name string
}
+// Update will update the Snapshot with provided information. To extract the updated
+// Snapshot from the response, call the Extract method on the UpdateResult.
func Update(client *gophercloud.ServiceClient, id string, opts *UpdateOpts) UpdateResult {
type update struct {
Description *string `json:"display_description,omitempty"`
diff --git a/openstack/blockstorage/v1/snapshots/results.go b/openstack/blockstorage/v1/snapshots/results.go
index 363d6e2..3a27592 100644
--- a/openstack/blockstorage/v1/snapshots/results.go
+++ b/openstack/blockstorage/v1/snapshots/results.go
@@ -9,28 +9,39 @@
"github.com/mitchellh/mapstructure"
)
+// Snapshot contains all the information associated with an OpenStack Snapshot.
type Snapshot struct {
- Status string `mapstructure:"status"`
- Name string `mapstructure:"display_name"`
- Attachments []string `mapstructure:"attachments"`
- AvailabilityZone string `mapstructure:"availability_zone"`
- Bootable string `mapstructure:"bootable"`
- CreatedAt string `mapstructure:"created_at"`
- Description string `mapstructure:"display_discription"`
- VolumeType string `mapstructure:"volume_type"`
- SnapshotID string `mapstructure:"snapshot_id"`
- SourceVolID string `mapstructure:"source_volid"`
- Metadata map[string]string `mapstructure:"metadata"`
- ID string `mapstructure:"id"`
- Size int `mapstructure:"size"`
+ Status string `mapstructure:"status"` // currect status of the Snapshot
+ Name string `mapstructure:"display_name"` // display name
+ Attachments []string `mapstructure:"attachments"` // instances onto which the Snapshot is attached
+ AvailabilityZone string `mapstructure:"availability_zone"` // logical group
+ Bootable string `mapstructure:"bootable"` // is the Snapshot bootable
+ CreatedAt string `mapstructure:"created_at"` // date created
+ Description string `mapstructure:"display_discription"` // display description
+ VolumeType string `mapstructure:"volume_type"` // see VolumeType object for more information
+ SnapshotID string `mapstructure:"snapshot_id"` // ID of the Snapshot from which this Snapshot was created
+ SourceVolID string `mapstructure:"source_volid"` // ID of the Volume from which this Snapshot was created
+ Metadata map[string]string `mapstructure:"metadata"` // user-defined key-value pairs
+ ID string `mapstructure:"id"` // unique identifier
+ Size int `mapstructure:"size"` // size of the Snapshot, in GB
}
-// ListResult is a *http.Response that is returned from a call to the List function.
+// CreateResult contains the response body and error from a Create request.
+type CreateResult struct {
+ commonResult
+}
+
+// GetResult contains the response body and error from a Get request.
+type GetResult struct {
+ commonResult
+}
+
+// ListResult is a pagination.Pager that is returned from a call to the List function.
type ListResult struct {
pagination.SinglePageBase
}
-// IsEmpty returns true if a ListResult contains no container names.
+// IsEmpty returns true if a ListResult contains no Snapshots.
func (r ListResult) IsEmpty() (bool, error) {
volumes, err := ExtractSnapshots(r)
if err != nil {
@@ -39,7 +50,7 @@
return len(volumes) == 0, nil
}
-// ExtractSnapshots extracts and returns the Volumes from a 'List' request.
+// ExtractSnapshots extracts and returns Snapshots. It is used while iterating over a snapshots.List call.
func ExtractSnapshots(page pagination.Page) ([]Snapshot, error) {
var response struct {
Snapshots []Snapshot `json:"snapshots"`
@@ -49,11 +60,16 @@
return response.Snapshots, err
}
+// UpdateResult contains the response body and error from an Update request.
+type UpdateResult struct {
+ commonResult
+}
+
type commonResult struct {
gophercloud.CommonResult
}
-// Extract returns a pointer to the Snapshot from a commonResult.Resp.
+// Extract will get the Snapshot object out of the commonResult object.
func (r commonResult) Extract() (*Snapshot, error) {
if r.Err != nil {
return nil, r.Err
@@ -69,14 +85,3 @@
}
return res.Snapshot, nil
}
-
-type GetResult struct {
- commonResult
-}
-
-type CreateResult struct {
- commonResult
-}
-type UpdateResult struct {
- commonResult
-}
diff --git a/openstack/blockstorage/v1/volumes/requests.go b/openstack/blockstorage/v1/volumes/requests.go
index 7704012..f635968 100644
--- a/openstack/blockstorage/v1/volumes/requests.go
+++ b/openstack/blockstorage/v1/volumes/requests.go
@@ -1,22 +1,28 @@
package volumes
import (
- "github.com/racker/perigee"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack/utils"
"github.com/rackspace/gophercloud/pagination"
+
+ "github.com/racker/perigee"
)
+// CreateOpts contains options for creating a Volume. This object is passed to
+// the volumes.Create function. For more information about these parameters,
+// see the Volume object.
type CreateOpts struct {
- Availability string
- Description string
- Metadata map[string]string
- Name string
- Size int
- SnapshotID, SourceVolID, ImageID string
- VolumeType string
+ Availability string // OPTIONAL
+ Description string // OPTIONAL
+ Metadata map[string]string // OPTIONAL
+ Name string // OPTIONAL
+ Size int // REQUIRED
+ SnapshotID, SourceVolID, ImageID string // REQUIRED (one of them)
+ VolumeType string // OPTIONAL
}
+// Create will create a new Volume based on the values in CreateOpts. To extract
+// the Volume object from the response, call the Extract method on the CreateResult.
func Create(client *gophercloud.ServiceClient, opts *CreateOpts) CreateResult {
type volume struct {
@@ -58,25 +64,17 @@
return res
}
-// ListOpts holds options for listing volumes. It is passed to the volumes.List function.
-type ListOpts struct {
- // AllTenants is an admin-only option. Set it to true to see all tenant volumes.
- AllTenants bool
- // List only volumes that contain Metadata.
- Metadata map[string]string
- // List only volumes that have Name as the display name.
- Name string
- // List only volumes that have a status of Status.
- Status string
+// Delete will delete the existing Volume with the provided ID.
+func Delete(client *gophercloud.ServiceClient, id string) error {
+ _, err := perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
+ MoreHeaders: client.Provider.AuthenticatedHeaders(),
+ OkCodes: []int{202, 204},
+ })
+ return err
}
-func List(client *gophercloud.ServiceClient, opts *ListOpts) pagination.Pager {
- createPage := func(r pagination.LastHTTPResponse) pagination.Page {
- return ListResult{pagination.SinglePageBase(r)}
- }
- return pagination.NewPager(client, listURL(client), createPage)
-}
-
+// Get retrieves the Volume with the provided ID. To extract the Volume object from
+// the response, call the Extract method on the GetResult.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var res GetResult
_, res.Err = perigee.Request("GET", getURL(client, id), perigee.Options{
@@ -87,12 +85,34 @@
return res
}
-type UpdateOpts struct {
- Name string
- Description string
- Metadata map[string]string
+// ListOpts holds options for listing Volumes. It is passed to the volumes.List
+// function.
+type ListOpts struct {
+ AllTenants bool // admin-only option. Set it to true to see all tenant volumes.
+ Metadata map[string]string // List only volumes that contain Metadata.
+ Name string // List only volumes that have Name as the display name.
+ Status string // List only volumes that have a status of Status.
}
+// List returns Volumes optionally limited by the conditions provided in ListOpts.
+func List(client *gophercloud.ServiceClient, opts *ListOpts) pagination.Pager {
+ createPage := func(r pagination.LastHTTPResponse) pagination.Page {
+ return ListResult{pagination.SinglePageBase(r)}
+ }
+ return pagination.NewPager(client, listURL(client), createPage)
+}
+
+// UpdateOpts contain options for updating an existing Volume. This object is passed
+// to the volumes.Update function. For more information about the parameters, see
+// the Volume object.
+type UpdateOpts struct {
+ Name string // OPTIONAL
+ Description string // OPTIONAL
+ Metadata map[string]string // OPTIONAL
+}
+
+// Update will update the Volume with provided information. To extract the updated
+// Volume from the response, call the Extract method on the UpdateResult.
func Update(client *gophercloud.ServiceClient, id string, opts *UpdateOpts) UpdateResult {
type update struct {
Description *string `json:"display_description,omitempty"`
@@ -120,13 +140,4 @@
Results: &res.Resp,
})
return res
-
-}
-
-func Delete(client *gophercloud.ServiceClient, id string) error {
- _, err := perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
- MoreHeaders: client.Provider.AuthenticatedHeaders(),
- OkCodes: []int{202, 204},
- })
- return err
}
diff --git a/openstack/blockstorage/v1/volumes/results.go b/openstack/blockstorage/v1/volumes/results.go
index 7bf83a5..78c863f 100644
--- a/openstack/blockstorage/v1/volumes/results.go
+++ b/openstack/blockstorage/v1/volumes/results.go
@@ -9,28 +9,39 @@
"github.com/mitchellh/mapstructure"
)
+// Volume contains all the information associated with an OpenStack Volume.
type Volume struct {
- Status string `mapstructure:"status"`
- Name string `mapstructure:"display_name"`
- Attachments []string `mapstructure:"attachments"`
- AvailabilityZone string `mapstructure:"availability_zone"`
- Bootable string `mapstructure:"bootable"`
- CreatedAt string `mapstructure:"created_at"`
- Description string `mapstructure:"display_discription"`
- VolumeType string `mapstructure:"volume_type"`
- SnapshotID string `mapstructure:"snapshot_id"`
- SourceVolID string `mapstructure:"source_volid"`
- Metadata map[string]string `mapstructure:"metadata"`
- ID string `mapstructure:"id"`
- Size int `mapstructure:"size"`
+ Status string `mapstructure:"status"` // current status of the Volume
+ Name string `mapstructure:"display_name"` // display name
+ Attachments []string `mapstructure:"attachments"` // instances onto which the Volume is attached
+ AvailabilityZone string `mapstructure:"availability_zone"` // logical group
+ Bootable string `mapstructure:"bootable"` // is the volume bootable
+ CreatedAt string `mapstructure:"created_at"` // date created
+ Description string `mapstructure:"display_discription"` // display description
+ VolumeType string `mapstructure:"volume_type"` // see VolumeType object for more information
+ SnapshotID string `mapstructure:"snapshot_id"` // ID of the Snapshot from which the Volume was created
+ SourceVolID string `mapstructure:"source_volid"` // ID of the Volume from which the Volume was created
+ Metadata map[string]string `mapstructure:"metadata"` // user-defined key-value pairs
+ ID string `mapstructure:"id"` // unique identifier
+ Size int `mapstructure:"size"` // size of the Volume, in GB
}
-// ListResult is a *http.Response that is returned from a call to the List function.
+// CreateResult contains the response body and error from a Create request.
+type CreateResult struct {
+ commonResult
+}
+
+// GetResult contains the response body and error from a Get request.
+type GetResult struct {
+ commonResult
+}
+
+// ListResult is a pagination.pager that is returned from a call to the List function.
type ListResult struct {
pagination.SinglePageBase
}
-// IsEmpty returns true if a ListResult contains no container names.
+// IsEmpty returns true if a ListResult contains no Volumes.
func (r ListResult) IsEmpty() (bool, error) {
volumes, err := ExtractVolumes(r)
if err != nil {
@@ -39,7 +50,7 @@
return len(volumes) == 0, nil
}
-// ExtractVolumes extracts and returns the Volumes from a 'List' request.
+// ExtractVolumes extracts and returns Volumes. It is used while iterating over a volumes.List call.
func ExtractVolumes(page pagination.Page) ([]Volume, error) {
var response struct {
Volumes []Volume `json:"volumes"`
@@ -49,11 +60,16 @@
return response.Volumes, err
}
+// UpdateResult contains the response body and error from an Update request.
+type UpdateResult struct {
+ commonResult
+}
+
type commonResult struct {
gophercloud.CommonResult
}
-// ExtractVolume extracts and returns the Volume from a 'Get' request.
+// Extract will get the Volume object out of the commonResult object.
func (r commonResult) Extract() (*Volume, error) {
if r.Err != nil {
return nil, r.Err
@@ -69,14 +85,3 @@
}
return res.Volume, nil
}
-
-type GetResult struct {
- commonResult
-}
-
-type CreateResult struct {
- commonResult
-}
-type UpdateResult struct {
- commonResult
-}
diff --git a/openstack/blockstorage/v1/volumetypes/requests.go b/openstack/blockstorage/v1/volumetypes/requests.go
index 466d043..ab7e790 100644
--- a/openstack/blockstorage/v1/volumetypes/requests.go
+++ b/openstack/blockstorage/v1/volumetypes/requests.go
@@ -7,11 +7,16 @@
"github.com/rackspace/gophercloud/pagination"
)
+// CreateOpts are options for creating a volume type.
type CreateOpts struct {
+ // OPTIONAL. See VolumeType.
ExtraSpecs map[string]interface{}
- Name string
+ // OPTIONAL. See VolumeType.
+ Name string
}
+// Create will create a new volume, optionally wih CreateOpts. To extract the
+// created volume type object, call the Extract method on the CreateResult.
func Create(client *gophercloud.ServiceClient, opts *CreateOpts) CreateResult {
type volumeType struct {
ExtraSpecs map[string]interface{} `json:"extra_specs,omitempty"`
@@ -39,6 +44,7 @@
return res
}
+// Delete will delete the volume type with the provided ID.
func Delete(client *gophercloud.ServiceClient, id string) error {
_, err := perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
@@ -47,6 +53,8 @@
return err
}
+// Get will retrieve the volume type with the provided ID. To extract the volume
+// type from the result, call the Extract method on the GetResult.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var res GetResult
_, err := perigee.Request("GET", getURL(client, id), perigee.Options{
@@ -58,6 +66,7 @@
return res
}
+// List returns all volume types.
func List(client *gophercloud.ServiceClient) pagination.Pager {
createPage := func(r pagination.LastHTTPResponse) pagination.Page {
return ListResult{pagination.SinglePageBase(r)}
diff --git a/openstack/blockstorage/v1/volumetypes/results.go b/openstack/blockstorage/v1/volumetypes/results.go
index fa10ae7..8e5932a 100644
--- a/openstack/blockstorage/v1/volumetypes/results.go
+++ b/openstack/blockstorage/v1/volumetypes/results.go
@@ -8,18 +8,29 @@
"github.com/rackspace/gophercloud/pagination"
)
+// VolumeType contains all information associated with an OpenStack Volume Type.
type VolumeType struct {
- ExtraSpecs map[string]interface{} `json:"extra_specs" mapstructure:"extra_specs"`
- ID string `json:"id" mapstructure:"id"`
- Name string `json:"name" mapstructure:"name"`
+ ExtraSpecs map[string]interface{} `json:"extra_specs" mapstructure:"extra_specs"` // user-defined metadata
+ ID string `json:"id" mapstructure:"id"` // unique identifier
+ Name string `json:"name" mapstructure:"name"` // display name
}
-// ListResult is a *http.Response that is returned from a call to the List function.
+// CreateResult contains the response body and error from a Create request.
+type CreateResult struct {
+ commonResult
+}
+
+// GetResult contains the response body and error from a Get request.
+type GetResult struct {
+ commonResult
+}
+
+// ListResult is a pagination.Pager that is returned from a call to the List function.
type ListResult struct {
pagination.SinglePageBase
}
-// IsEmpty returns true if a ListResult contains no container names.
+// IsEmpty returns true if a ListResult contains no Volume Types.
func (r ListResult) IsEmpty() (bool, error) {
volumeTypes, err := ExtractVolumeTypes(r)
if err != nil {
@@ -28,7 +39,7 @@
return len(volumeTypes) == 0, nil
}
-// ExtractVolumeTypes extracts and returns the Volumes from a 'List' request.
+// ExtractVolumeTypes extracts and returns Volume Types.
func ExtractVolumeTypes(page pagination.Page) ([]VolumeType, error) {
var response struct {
VolumeTypes []VolumeType `mapstructure:"volume_types"`
@@ -42,6 +53,7 @@
gophercloud.CommonResult
}
+// Extract will get the Volume Type object out of the commonResult object.
func (r commonResult) Extract() (*VolumeType, error) {
if r.Err != nil {
return nil, r.Err
@@ -58,11 +70,3 @@
return res.VolumeType, nil
}
-
-type GetResult struct {
- commonResult
-}
-
-type CreateResult struct {
- commonResult
-}