shares

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package shares enables management and retrieval of Shares VBS service.

Example to List Shares

listOpts := shares.ListOpts{}
allShares, err := shares.List(vbsClient, listOpts)
if err != nil {
	panic(err)
}

for _, share := range allShares {
	fmt.Printf("%+v\n", share)
}

Example to Get a Share

   getshare,err:=shares.Get(vbsClient, "6149e448-dcac-4691-96d9-041e09ef617f").ExtractShare()
   if err != nil {
         panic(err)
		}

   fmt.Println(getshare)

Example to Create a Share

createOpts := shares.CreateOpts{BackupID:"87566ed6-72cb-4053-aa6e-6f6216b3d507",
								ToProjectIDs:[]string{"91d687759aed45d28b5f6084bc2fa8ad"}}

share, err := shares.Create(vbsClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Example to Delete a Share

shareID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"

deleteopts := shares.DeleteOpts{IsBackupID:false}
err := shares.Delete(vbsclient,shareID,deleteopts).ExtractErr()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStructNestedField

func GetStructNestedField(v *Share, field string, structDriller []string) string

Types

type Backup

type Backup struct {
	// Backup ID
	ID string `json:"id"`
	// Backup name
	Name string `json:"name"`
	// Backup status
	Status string `json:"status"`
	// Backup description
	Description string `json:"description"`
	// AZ where the backup resides
	AvailabilityZone string `json:"availability_zone"`
	// Source volume ID of the backup
	VolumeID string `json:"volume_id"`
	// Cause of the backup failure
	FailReason string `json:"fail_reason"`
	// Backup size
	Size int `json:"size"`
	// Number of objects on OBS for the disk data
	ObjectCount int `json:"object_count"`
	// Container of the backup
	Container string `json:"container"`
	// Backup creation time
	CreatedAt time.Time `json:"-"`
	// Backup metadata
	ServiceMetadata string `json:"service_metadata"`
	// Time when the backup was updated
	UpdatedAt time.Time `json:"-"`
	// Current time
	DataTimeStamp time.Time `json:"-"`
	// Whether a dependent backup exists
	DependentBackups bool `json:"has_dependent_backups"`
	// ID of the snapshot associated with the backup
	SnapshotID string `json:"snapshot_id"`
	// Whether the backup is an incremental backup
	IsIncremental bool `json:"is_incremental"`
}

func (*Backup) UnmarshalJSON

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

UnmarshalJSON overrides the default, to convert the JSON API response into our Backup struct

type CreateOpts

type CreateOpts struct {
	// ID of the backup to be shared
	BackupID string `json:"backup_id" required:"true"`
	// IDs of projects with which the backup is shared
	ToProjectIDs []string `json:"to_project_ids" required:"true"`
}

CreateOpts contains all the values needed to create a new share.

func (CreateOpts) ToShareCreateMap

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

ToShareCreateMap builds a create request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToShareCreateMap() (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 represents the result of a create operation. Call its Extract method to interpret it as a Share.

func Create

func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

Create will create a new Share based on the values in CreateOpts. To extract the Share object from the response, call the Extract method on the CreateResult.

func (CreateResult) Extract

func (r CreateResult) Extract() ([]Share, error)

Extract is a function that accepts a result and extracts shares.

func (CreateResult) ExtractShare

func (r CreateResult) ExtractShare() (*Share, error)

ExtractShare is a function that accepts a result and extracts a share.

type DeleteOpts

type DeleteOpts struct {
	// Whether the ID in the URL is a backup share ID or a backup ID
	IsBackupID bool `q:"is_backup_id"`
}

func (DeleteOpts) ToShareDeleteQuery

func (opts DeleteOpts) ToShareDeleteQuery() (string, error)

type DeleteOptsBuilder

type DeleteOptsBuilder interface {
	ToShareDeleteQuery() (string, error)
}

DeleteOptsBuilder is an interface which can be able to build the query string of share deletion.

type DeleteResult

type DeleteResult struct {
	golangsdk.ErrResult
}

DeleteResult represents the result of a delete operation. Call its ExtractErr method to determine if the request succeeded or failed.

func Delete

func Delete(client *golangsdk.ServiceClient, id string, opts DeleteOptsBuilder) (r DeleteResult)

Delete is a method by which can be able to delete one or all shares of a backup.

type FilterStruct

type FilterStruct struct {
	Value   string
	Driller []string
}

type GetResult

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

GetResult represents the result of a get operation. Call its ExtractShare method to interpret it as a Share.

func Get

func Get(c *golangsdk.ServiceClient, id string) (r GetResult)

Get retrieves a particular share based on its unique ID.

func (GetResult) Extract

func (r GetResult) Extract() ([]Share, error)

Extract is a function that accepts a result and extracts shares.

func (GetResult) ExtractShare

func (r GetResult) ExtractShare() (*Share, error)

ExtractShare is a function that accepts a result and extracts a share.

type ListOpts

type ListOpts struct {
	ID               string
	SnapshotID       string
	ShareToMe        bool    `q:"share_to_me"`
	Name             string  `q:"name"`
	Status           string  `q:"status"`
	BackupID         string  `q:"backup_id"`
	FromProjectID    string  `q:"from_project_id"`
	ToProjectID      string  `q:"to_project_id"`
	AvailabilityZone string  `q:"availability_zone"`
	SortDir          SortDir `q:"sort_dir"`
	Limit            int     `q:"limit"`
	Offset           int     `q:"offset"`
	VolumeID         string  `q:"volume_id"`
}

ListOpts allows the filtering and sorting of paginated collections through the API. Filtering is achieved by passing in struct field values that map to the share attributes you want to see returned.

type Share

type Share struct {
	// Details about the source backup
	Backup Backup `json:"backup"`
	// Backup ID
	BackupID string `json:"backup_id"`
	// Backup share ID
	ID string `json:"id"`
	// ID of the project with which the backup is shared
	ToProjectID string `json:"to_project_id"`
	// ID of the project that shares the backup
	FromProjectID string `json:"from_project_id"`
	// Creation time of the backup share
	CreatedAt time.Time `json:"-"`
	// Update time of the backup share
	UpdatedAt time.Time `json:"-"`
	// Whether the backup has been deleted
	Deleted string `json:"deleted"`
	// Deletion time
	DeletedAt time.Time `json:"-"`
}

func ExtractShareList

func ExtractShareList(r pagination.Page) ([]Share, error)

ExtractShareList accepts a Page struct, specifically a SharePage struct, and extracts the elements into a slice of Shares struct. In other words, a generic collection is mapped into a relevant slice.

func FilterShares

func FilterShares(shares []Share, opts ListOpts) ([]Share, error)

func List

func List(c *golangsdk.ServiceClient, opts ListOpts) ([]Share, error)

List returns collection of share. It accepts a ListOpts struct, which allows you to filter and sort the returned collection for greater efficiency. Default policy settings return only those share that are owned by the tenant who submits the request, unless an admin user submits the request.

func (*Share) UnmarshalJSON

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

UnmarshalJSON overrides the default, to convert the JSON API response into our Share struct

type SharePage

type SharePage struct {
	pagination.LinkedPageBase
}

SharePage is the page returned by a pager when traversing over a collection of Shares.

func (SharePage) IsEmpty

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

IsEmpty checks whether a SharePage struct is empty.

func (SharePage) NextPageURL

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

NextPageURL is invoked when a paginated collection of Shares has reached the end of a page and the pager seeks to traverse over a new one. In order to do this, it needs to construct the next page's URL.

type SortDir

type SortDir string

SortDir is a type for specifying in which direction to sort a list of Shares.

var (
	// SortAsc is used to sort a list of Shares in ascending order.
	SortAsc SortDir = "asc"
	// SortDesc is used to sort a list of Shares in descending order.
	SortDesc SortDir = "desc"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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