backups

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2021 License: Apache-2.0 Imports: 4 Imported by: 10

Documentation

Overview

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

Example to List Backups

listOpts := backups.ListOpts{
	VolumeID: "uuid",
}

allPages, err := backups.List(client, listOpts).AllPages()
if err != nil {
	panic(err)
}

allBackups, err := backups.ExtractBackups(allPages)
if err != nil {
	panic(err)
}

for _, backup := range allBackups {
	fmt.Println(backup)
}

Example to Create a Backup

createOpts := backups.CreateOpts{
	VolumeID: "uuid",
	Name:     "my-backup",
}

backup, err := backups.Create(client, createOpts).Extract()
if err != nil {
	panic(err)
}

fmt.Println(backup)

Example to Update a Backup

updateOpts := backups.UpdateOpts{
	Name: "new-name",
}

backup, err := backups.Update(client, "uuid", updateOpts).Extract()
if err != nil {
	panic(err)
}

fmt.Println(backup)

Example to Restore a Backup to a Volume

options := backups.RestoreOpts{
	VolumeID: "1234",
	Name:     "vol-001",
}

restore, err := backups.RestoreFromBackup(client, "uuid", options).Extract()
if err != nil {
	panic(err)
}

fmt.Println(restore)

Example to Delete a Backup

err := backups.Delete(client, "uuid").ExtractErr()
if err != nil {
	panic(err)
}

Example to Export a Backup

export, err := backups.Export(client, "uuid").Extract()
if err != nil {
	panic(err)
}

fmt.Println(export)

Example to Import a Backup

status := "available"
availabilityZone := "region1b"
host := "cinder-backup-host1"
serviceMetadata := "volume_cf9bc6fa-c5bc-41f6-bc4e-6e76c0bea959/20200311192855/az_regionb_backup_b87bb1e5-0d4e-445e-a548-5ae742562bac"
size := 1
objectCount := 2
container := "my-test-backup"
service := "cinder.backup.drivers.swift.SwiftBackupDriver"
backupURL, _ := json.Marshal(backups.ImportBackup{
	ID:               "d32019d3-bc6e-4319-9c1d-6722fc136a22",
	Status:           &status,
	AvailabilityZone: &availabilityZone,
	VolumeID:         "cf9bc6fa-c5bc-41f6-bc4e-6e76c0bea959",
	UpdatedAt:        time.Date(2020, 3, 11, 19, 29, 8, 0, time.UTC),
	Host:             &host,
	UserID:           "93514e04-a026-4f60-8176-395c859501dd",
	ServiceMetadata:  &serviceMetadata,
	Size:             &size,
	ObjectCount:      &objectCount,
	Container:        &container,
	Service:          &service,
	CreatedAt:        time.Date(2020, 3, 11, 19, 25, 24, 0, time.UTC),
	DataTimestamp:    time.Date(2020, 3, 11, 19, 25, 24, 0, time.UTC),
	ProjectID:        "14f1c1f5d12b4755b94edef78ff8b325",
})

options := backups.ImportOpts{
	BackupService: "cinder.backup.drivers.swift.SwiftBackupDriver",
	BackupURL:     backupURL,
}

backup, err := backups.Import(client, options).Extract()
if err != nil {
	panic(err)
}

fmt.Println(backup)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractBackupsInto

func ExtractBackupsInto(r pagination.Page, v interface{}) error

func List

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

func ListDetail added in v0.16.0

ListDetail returns more detailed information about Backups optionally limited by the conditions provided in ListDetailOpts.

Types

type Backup

type Backup struct {
	// ID is the Unique identifier of the backup.
	ID string `json:"id"`

	// CreatedAt is the date the backup was created.
	CreatedAt time.Time `json:"-"`

	// UpdatedAt is the date the backup was updated.
	UpdatedAt time.Time `json:"-"`

	// Name is the display name of the backup.
	Name string `json:"name"`

	// Description is the description of the backup.
	Description string `json:"description"`

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

	// SnapshotID is the ID of the snapshot from which this backup was created.
	SnapshotID string `json:"snapshot_id"`

	// Status is the status of the backup.
	Status string `json:"status"`

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

	// Object Count is the number of objects in the backup.
	ObjectCount int `json:"object_count"`

	// Container is the container where the backup is stored.
	Container string `json:"container"`

	// HasDependentBackups is whether there are other backups
	// depending on this backup.
	HasDependentBackups bool `json:"has_dependent_backups"`

	// FailReason has the reason for the backup failure.
	FailReason string `json:"fail_reason"`

	// IsIncremental is whether this is an incremental backup.
	IsIncremental bool `json:"is_incremental"`

	// DataTimestamp is the time when the data on the volume was first saved.
	DataTimestamp time.Time `json:"-"`

	// ProjectID is the ID of the project that owns the backup. This is
	// an admin-only field.
	ProjectID string `json:"os-backup-project-attr:project_id"`

	// Metadata is metadata about the backup.
	// This requires microversion 3.43 or later.
	Metadata *map[string]string `json:"metadata"`

	// AvailabilityZone is the Availability Zone of the backup.
	// This requires microversion 3.51 or later.
	AvailabilityZone *string `json:"availability_zone"`
}

Backup contains all the information associated with a Cinder Backup.

func ExtractBackups

func ExtractBackups(r pagination.Page) ([]Backup, error)

ExtractBackups extracts and returns Backups. It is used while iterating over a backups.List call.

func (*Backup) UnmarshalJSON

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

UnmarshalJSON converts our JSON API response into our backup struct

type BackupPage

type BackupPage struct {
	pagination.LinkedPageBase
}

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

func (BackupPage) IsEmpty

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

IsEmpty returns true if a BackupPage contains no Backups.

func (BackupPage) NextPageURL

func (page BackupPage) NextPageURL() (string, error)

type BackupRecord added in v0.10.0

type BackupRecord struct {
	// The service used to perform the backup.
	BackupService string `json:"backup_service"`

	// An identifier string to locate the backup.
	BackupURL []byte `json:"backup_url"`
}

BackupRecord contains an information about a backup backend storage.

type CreateOpts

type CreateOpts struct {
	// VolumeID is the ID of the volume to create the backup from.
	VolumeID string `json:"volume_id" required:"true"`

	// Force will force the creation of a backup regardless of the
	//volume's status.
	Force bool `json:"force,omitempty"`

	// Name is the name of the backup.
	Name string `json:"name,omitempty"`

	// Description is the description of the backup.
	Description string `json:"description,omitempty"`

	// Metadata is metadata for the backup.
	// Requires microversion 3.43 or later.
	Metadata map[string]string `json:"metadata,omitempty"`

	// Container is a container to store the backup.
	Container string `json:"container,omitempty"`

	// Incremental is whether the backup should be incremental or not.
	Incremental bool `json:"incremental,omitempty"`

	// SnapshotID is the ID of a snapshot to backup.
	SnapshotID string `json:"snapshot_id,omitempty"`

	// AvailabilityZone is an availability zone to locate the volume or snapshot.
	// Requires microversion 3.51 or later.
	AvailabilityZone string `json:"availability_zone,omitempty"`
}

CreateOpts contains options for creating a Backup. This object is passed to the backups.Create function. For more information about these parameters, see the Backup object.

func (CreateOpts) ToBackupCreateMap

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

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

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToBackupCreateMap() (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 Backup based on the values in CreateOpts. To extract the Backup object from the response, call the Extract method on the CreateResult.

func (CreateResult) Extract

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

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

func (CreateResult) ExtractInto

func (r CreateResult) ExtractInto(v interface{}) error

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 Backup with the provided ID.

type ExportResult added in v0.10.0

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

ExportResult contains the response body and error from an export request.

func Export added in v0.10.0

func Export(client *gophercloud.ServiceClient, id string) (r ExportResult)

Export will export a Backup information. To extract the Backup export record object from the response, call the Extract method on the ExportResult.

func (ExportResult) Extract added in v0.10.0

func (r ExportResult) Extract() (*BackupRecord, error)

Extract will get the Backup record object out of the ExportResult object.

func (ExportResult) ExtractInto added in v0.10.0

func (r ExportResult) ExtractInto(v interface{}) error

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 Backup with the provided ID. To extract the Backup object from the response, call the Extract method on the GetResult.

func (GetResult) Extract

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

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

func (GetResult) ExtractInto

func (r GetResult) ExtractInto(v interface{}) error

type ImportBackup added in v0.10.0

type ImportBackup struct {
	ID                  string            `json:"id"`
	CreatedAt           time.Time         `json:"-"`
	UpdatedAt           time.Time         `json:"-"`
	VolumeID            string            `json:"volume_id"`
	SnapshotID          *string           `json:"snapshot_id"`
	Status              *string           `json:"status"`
	Size                *int              `json:"size"`
	ObjectCount         *int              `json:"object_count"`
	Container           *string           `json:"container"`
	ServiceMetadata     *string           `json:"service_metadata"`
	Service             *string           `json:"service"`
	Host                *string           `json:"host"`
	UserID              string            `json:"user_id"`
	DeletedAt           time.Time         `json:"-"`
	DataTimestamp       time.Time         `json:"-"`
	TempSnapshotID      *string           `json:"temp_snapshot_id"`
	TempVolumeID        *string           `json:"temp_volume_id"`
	RestoreVolumeID     *string           `json:"restore_volume_id"`
	NumDependentBackups *int              `json:"num_dependent_backups"`
	EncryptionKeyID     *string           `json:"encryption_key_id"`
	ParentID            *string           `json:"parent_id"`
	Deleted             bool              `json:"deleted"`
	DisplayName         *string           `json:"display_name"`
	DisplayDescription  *string           `json:"display_description"`
	DriverInfo          interface{}       `json:"driver_info"`
	FailReason          *string           `json:"fail_reason"`
	ProjectID           string            `json:"project_id"`
	Metadata            map[string]string `json:"metadata"`
	AvailabilityZone    *string           `json:"availability_zone"`
}

ImportBackup contains all the information to import a Cinder Backup.

func (ImportBackup) MarshalJSON added in v0.10.0

func (r ImportBackup) MarshalJSON() ([]byte, error)

MarshalJSON converts our struct request into JSON backup import request

func (*ImportBackup) UnmarshalJSON added in v0.10.0

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

UnmarshalJSON converts our JSON API response into our backup struct

type ImportOpts added in v0.10.0

type ImportOpts BackupRecord

ImportOpts contains options for importing a Backup. This object is passed to the backups.ImportBackup function.

func (ImportOpts) ToBackupImportMap added in v0.10.0

func (opts ImportOpts) ToBackupImportMap() (map[string]interface{}, error)

ToBackupImportMap assembles a request body based on the contents of a ImportOpts.

type ImportResponse added in v0.10.0

type ImportResponse struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

ImportResponse struct contains the response of the Backup Import action.

type ImportResult added in v0.10.0

type ImportResult struct {
	gophercloud.Result
}

ImportResult contains the response body and error from an import request.

func Import added in v0.10.0

func Import(client *gophercloud.ServiceClient, opts ImportOpts) (r ImportResult)

Import will import a Backup data to a backup based on the values in ImportOpts. To extract the Backup object from the response, call the Extract method on the ImportResult.

func (ImportResult) Extract added in v0.10.0

func (r ImportResult) Extract() (*ImportResponse, error)

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

func (ImportResult) ExtractInto added in v0.10.0

func (r ImportResult) ExtractInto(v interface{}) error

type ListDetailOpts added in v0.16.0

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

	// 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"`

	// True to include `count` in the API response, supported from version 3.45
	WithCount bool `q:"with_count"`
}

func (ListDetailOpts) ToBackupListDetailQuery added in v0.16.0

func (opts ListDetailOpts) ToBackupListDetailQuery() (string, error)

ToBackupListDetailQuery formats a ListDetailOpts into a query string.

type ListDetailOptsBuilder added in v0.16.0

type ListDetailOptsBuilder interface {
	ToBackupListDetailQuery() (string, error)
}

ListDetailOptsBuilder allows extensions to add additional parameters to the ListDetail request.

type ListOpts

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

	// Name will filter by the specified backup name.
	// This does not work in later microversions.
	Name string `q:"name"`

	// Status will filter by the specified status.
	// This does not work in later microversions.
	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.
	// This does not work in later microversions.
	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"`
}

func (ListOpts) ToBackupListQuery

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

ToBackupListQuery formats a ListOpts into a query string.

type ListOptsBuilder

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

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

type Restore added in v0.9.0

type Restore struct {
	// BackupID is the Unique identifier of the backup.
	BackupID string `json:"backup_id"`

	// VolumeID is the Unique identifier of the volume.
	VolumeID string `json:"volume_id"`

	// Name is the name of the volume, where the backup was restored to.
	VolumeName string `json:"volume_name"`
}

Restore contains all the information associated with a Cinder Backup restore response.

type RestoreOpts added in v0.9.0

type RestoreOpts struct {
	// VolumeID is the ID of the existing volume to restore the backup to.
	VolumeID string `json:"volume_id,omitempty"`

	// Name is the name of the new volume to restore the backup to.
	Name string `json:"name,omitempty"`
}

RestoreOpts contains options for restoring a Backup. This object is passed to the backups.RestoreFromBackup function.

func (RestoreOpts) ToRestoreMap added in v0.9.0

func (opts RestoreOpts) ToRestoreMap() (map[string]interface{}, error)

ToRestoreMap assembles a request body based on the contents of a RestoreOpts.

type RestoreResult added in v0.9.0

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

RestoreResult contains the response body and error from a restore request.

func RestoreFromBackup added in v0.9.0

func RestoreFromBackup(client *gophercloud.ServiceClient, id string, opts RestoreOpts) (r RestoreResult)

RestoreFromBackup will restore a Backup to a volume based on the values in RestoreOpts. To extract the Restore object from the response, call the Extract method on the RestoreResult.

func (RestoreResult) Extract added in v0.9.0

func (r RestoreResult) Extract() (*Restore, error)

Extract will get the Backup restore object out of the RestoreResult object.

func (RestoreResult) ExtractInto added in v0.9.0

func (r RestoreResult) ExtractInto(v interface{}) error

type UpdateOpts

type UpdateOpts struct {
	// Name is the name of the backup.
	Name *string `json:"name,omitempty"`

	// Description is the description of the backup.
	Description *string `json:"description,omitempty"`

	// Metadata is metadata for the backup.
	// Requires microversion 3.43 or later.
	Metadata map[string]string `json:"metadata,omitempty"`
}

UpdateOpts contain options for updating an existing Backup.

func (UpdateOpts) ToBackupUpdateMap

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

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

type UpdateOptsBuilder

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

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

type UpdateResult

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

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

func Update

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

Update will update the Backup with provided information. To extract the updated Backup from the response, call the Extract method on the UpdateResult. Requires microversion 3.9 or later.

func (UpdateResult) Extract

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

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

func (UpdateResult) ExtractInto

func (r UpdateResult) ExtractInto(v interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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