snapshots

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2024 License: Apache-2.0 Imports: 4 Imported by: 49

Documentation

Overview

Package snapshots provides information and interaction with snapshots in the OpenStack Block Storage service. A snapshot is a point in time copy of the data contained in an external storage volume, and can be controlled programmatically.

Example to list Snapshots

allPages, err := snapshots.List(client, snapshots.ListOpts{}).AllPages()
if err != nil{
	panic(err)
}
snapshots, err := snapshots.ExtractSnapshots(allPages)
if err != nil{
	panic(err)
}
for _,s := range snapshots{
	fmt.Println(s)
}

Example to get a Snapshot

snapshotID := "4a584cae-e4ce-429b-9154-d4c9eb8fda4c"
snapshot, err := snapshots.Get(client, snapshotID).Extract()
if err != nil{
	panic(err)
}
fmt.Println(snapshot)

Example to create a Snapshot

snapshot, err := snapshots.Create(client, snapshots.CreateOpts{
	Name:"snapshot_001",
	VolumeID:"5aa119a8-d25b-45a7-8d1b-88e127885635",
}).Extract()
if err != nil{
	panic(err)
}
fmt.Println(snapshot)

Example to delete a Snapshot

snapshotID := "4a584cae-e4ce-429b-9154-d4c9eb8fda4c"
err := snapshots.Delete(client, snapshotID).ExtractErr()
if err != nil{
	panic(err)
}

Example to update a Snapshot

snapshotID := "4a584cae-e4ce-429b-9154-d4c9eb8fda4c"
snapshot, err = snapshots.Update(client, snapshotID, snapshots.UpdateOpts{
	Name: "snapshot_002",
	Description:"description_002",
}).Extract()
if err != nil{
	panic(err)
}
fmt.Println(snapshot)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

List returns Snapshots optionally limited by the conditions provided in ListOpts.

func WaitForStatus

func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error

WaitForStatus will continually poll the resource, checking for a particular status. It will do this for the amount of seconds defined.

Types

type CreateOpts

type CreateOpts struct {
	VolumeID    string            `json:"volume_id" required:"true"`
	Force       bool              `json:"force,omitempty"`
	Name        string            `json:"name,omitempty"`
	Description string            `json:"description,omitempty"`
	Metadata    map[string]string `json:"metadata,omitempty"`
}

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.

func (CreateOpts) ToSnapshotCreateMap

func (opts CreateOpts) ToSnapshotCreateMap() (map[string]interface{}, error)

ToSnapshotCreateMap assembles a request body based on the contents of a CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToSnapshotCreateMap() (map[string]interface{}, error)
}

CreateOptsBuilder allows extensions to add additional parameters to the Create request.

type CreateResult

type CreateResult struct {
	// contains filtered or unexported fields
}

CreateResult contains the response body and error from a Create request.

func Create

func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

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 (CreateResult) Extract

func (r CreateResult) Extract() (*Snapshot, error)

Extract will get the Snapshot object out of the commonResult object.

type DeleteResult

type DeleteResult struct {
	gophercloud.ErrResult
}

DeleteResult contains the response body and error from a Delete request.

func Delete

func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult)

Delete will delete the existing Snapshot with the provided ID.

type ForceDeleteResult added in v1.6.0

type ForceDeleteResult struct {
	gophercloud.ErrResult
}

ForceDeleteResult contains the response error from a ForceDelete request.

func ForceDelete added in v1.6.0

func ForceDelete(client *gophercloud.ServiceClient, id string) (r ForceDeleteResult)

ForceDelete will delete the existing snapshot in any state. ForceDeleteResult contains only the error. To extract it, call the ExtractErr method on the ForceDeleteResult.

type GetResult

type GetResult struct {
	// contains filtered or unexported fields
}

GetResult contains the response body and error from a Get request.

func Get

func Get(client *gophercloud.ServiceClient, id string) (r GetResult)

Get retrieves the Snapshot with the provided ID. To extract the Snapshot object from the response, call the Extract method on the GetResult.

func (GetResult) Extract

func (r GetResult) Extract() (*Snapshot, error)

Extract will get the Snapshot object out of the commonResult object.

type ListOpts

type ListOpts struct {
	// AllTenants will retrieve snapshots of all tenants/projects.
	AllTenants bool `q:"all_tenants"`

	// Name will filter by the specified snapshot name.
	Name string `q:"name"`

	// Status will filter by the specified status.
	Status string `q:"status"`

	// TenantID will filter by a specific tenant/project ID.
	// Setting AllTenants is required to use this.
	TenantID string `q:"project_id"`

	// VolumeID will filter by a specified volume ID.
	VolumeID string `q:"volume_id"`

	// Comma-separated list of sort keys and optional sort directions in the
	// form of <key>[:<direction>].
	Sort string `q:"sort"`

	// Requests a page size of items.
	Limit int `q:"limit"`

	// Used in conjunction with limit to return a slice of items.
	Offset int `q:"offset"`

	// The ID of the last-seen item.
	Marker string `q:"marker"`
}

ListOpts holds options for listing Snapshots. It is passed to the snapshots.List function.

func (ListOpts) ToSnapshotListQuery

func (opts ListOpts) ToSnapshotListQuery() (string, error)

ToSnapshotListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToSnapshotListQuery() (string, error)
}

ListOptsBuilder allows extensions to add additional parameters to the List request.

type ResetStatusOpts added in v1.6.0

type ResetStatusOpts struct {
	// Status is a snapshot status to reset to.
	Status string `json:"status"`
}

ResetStatusOpts contains options for resetting a Snapshot status. For more information about these parameters, please, refer to the Block Storage API V3, Snapshot Actions, ResetStatus snapshot documentation.

func (ResetStatusOpts) ToSnapshotResetStatusMap added in v1.6.0

func (opts ResetStatusOpts) ToSnapshotResetStatusMap() (map[string]interface{}, error)

ToSnapshotResetStatusMap assembles a request body based on the contents of a ResetStatusOpts.

type ResetStatusOptsBuilder added in v1.6.0

type ResetStatusOptsBuilder interface {
	ToSnapshotResetStatusMap() (map[string]interface{}, error)
}

ResetStatusOptsBuilder allows extensions to add additional parameters to the ResetStatus request.

type ResetStatusResult added in v1.6.0

type ResetStatusResult struct {
	gophercloud.ErrResult
}

ResetStatusResult contains the response error from a ResetStatus request.

func ResetStatus added in v1.6.0

func ResetStatus(client *gophercloud.ServiceClient, id string, opts ResetStatusOptsBuilder) (r ResetStatusResult)

ResetStatus will reset the existing snapshot status. ResetStatusResult contains only the error. To extract it, call the ExtractErr method on the ResetStatusResult.

type Snapshot

type Snapshot struct {
	// Unique identifier.
	ID string `json:"id"`

	// Date created.
	CreatedAt time.Time `json:"-"`

	// Date updated.
	UpdatedAt time.Time `json:"-"`

	// Display name.
	Name string `json:"name"`

	// Display description.
	Description string `json:"description"`

	// ID of the Volume from which this Snapshot was created.
	VolumeID string `json:"volume_id"`

	// Currect status of the Snapshot.
	Status string `json:"status"`

	// Size of the Snapshot, in GB.
	Size int `json:"size"`

	// User-defined key-value pairs.
	Metadata map[string]string `json:"metadata"`
}

Snapshot contains all the information associated with a Cinder Snapshot.

func ExtractSnapshots

func ExtractSnapshots(r pagination.Page) ([]Snapshot, error)

ExtractSnapshots extracts and returns Snapshots. It is used while iterating over a snapshots.List call.

func (*Snapshot) UnmarshalJSON

func (r *Snapshot) UnmarshalJSON(b []byte) error

UnmarshalJSON converts our JSON API response into our snapshot struct

type SnapshotPage

type SnapshotPage struct {
	pagination.LinkedPageBase
}

SnapshotPage is a pagination.Pager that is returned from a call to the List function.

func (SnapshotPage) IsEmpty

func (r SnapshotPage) IsEmpty() (bool, error)

IsEmpty returns true if a SnapshotPage contains no Snapshots.

func (SnapshotPage) NextPageURL

func (r SnapshotPage) NextPageURL() (string, error)

NextPageURL uses the response's embedded link reference to navigate to the next page of results.

type UpdateMetadataOpts

type UpdateMetadataOpts struct {
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

UpdateMetadataOpts 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.

func (UpdateMetadataOpts) ToSnapshotUpdateMetadataMap

func (opts UpdateMetadataOpts) ToSnapshotUpdateMetadataMap() (map[string]interface{}, error)

ToSnapshotUpdateMetadataMap assembles a request body based on the contents of an UpdateMetadataOpts.

type UpdateMetadataOptsBuilder

type UpdateMetadataOptsBuilder interface {
	ToSnapshotUpdateMetadataMap() (map[string]interface{}, error)
}

UpdateMetadataOptsBuilder allows extensions to add additional parameters to the Update request.

type UpdateMetadataResult

type UpdateMetadataResult struct {
	// contains filtered or unexported fields
}

UpdateMetadataResult contains the response body and error from an UpdateMetadata request.

func UpdateMetadata

UpdateMetadata will update the Snapshot with provided information. To extract the updated Snapshot from the response, call the ExtractMetadata method on the UpdateMetadataResult.

func (UpdateMetadataResult) Extract

func (r UpdateMetadataResult) Extract() (*Snapshot, error)

Extract will get the Snapshot object out of the commonResult object.

func (UpdateMetadataResult) ExtractMetadata

func (r UpdateMetadataResult) ExtractMetadata() (map[string]interface{}, error)

ExtractMetadata returns the metadata from a response from snapshots.UpdateMetadata.

type UpdateOpts added in v0.15.0

type UpdateOpts struct {
	Name        *string `json:"name,omitempty"`
	Description *string `json:"description,omitempty"`
}

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.

func (UpdateOpts) ToSnapshotUpdateMap added in v0.15.0

func (opts UpdateOpts) ToSnapshotUpdateMap() (map[string]interface{}, error)

ToSnapshotUpdateMap assembles a request body based on the contents of an UpdateOpts.

type UpdateOptsBuilder added in v0.15.0

type UpdateOptsBuilder interface {
	ToSnapshotUpdateMap() (map[string]interface{}, error)
}

UpdateOptsBuilder allows extensions to add additional parameters to the Update request.

type UpdateResult added in v0.15.0

type UpdateResult struct {
	// contains filtered or unexported fields
}

UpdateResult contains the response body and error from an Update request.

func Update added in v0.15.0

func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult)

Update will update the Snapshot with provided information. To extract the updated Snapshot from the response, call the Extract method on the UpdateResult.

func (UpdateResult) Extract added in v0.15.0

func (r UpdateResult) Extract() (*Snapshot, error)

Extract will get the Snapshot object out of the commonResult object.

type UpdateStatusOpts added in v1.6.0

type UpdateStatusOpts struct {
	// Status is a snapshot status to update to.
	Status string `json:"status"`
	// A progress percentage value for snapshot build progress.
	Progress string `json:"progress,omitempty"`
}

UpdateStatusOpts contains options for resetting a Snapshot status. For more information about these parameters, please, refer to the Block Storage API V3, Snapshot Actions, UpdateStatus snapshot documentation.

func (UpdateStatusOpts) ToSnapshotUpdateStatusMap added in v1.6.0

func (opts UpdateStatusOpts) ToSnapshotUpdateStatusMap() (map[string]interface{}, error)

ToSnapshotUpdateStatusMap assembles a request body based on the contents of a UpdateStatusOpts.

type UpdateStatusOptsBuilder added in v1.6.0

type UpdateStatusOptsBuilder interface {
	ToSnapshotUpdateStatusMap() (map[string]interface{}, error)
}

UpdateStatusOptsBuilder allows extensions to add additional parameters to the UpdateStatus request.

type UpdateStatusResult added in v1.6.0

type UpdateStatusResult struct {
	gophercloud.ErrResult
}

UpdateStatusResult contains the response error from an UpdateStatus request.

func UpdateStatus added in v1.6.0

UpdateStatus will reset the existing snapshot status. UpdateStatusResult contains only the error. To extract it, call the ExtractErr method on the UpdateStatusResult.

Directories

Path Synopsis
Package testing for snapshots_v3
Package testing for snapshots_v3

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL