gcnvapi

package
v0.0.0-...-58f6e79 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package gcnvapi provides a high-level interface to the Google Cloud NetApp Volumes SDK

Package gcnvapi provides a high-level interface to the Google Cloud NetApp Volumes SDK

Package gcnvapi provides a high-level interface to the Google Cloud NetApp Volumes SDK

Package gcnvapi provides a high-level interface to the Google Cloud NetApp Volumes SDK

Index

Constants

View Source
const (
	VolumeCreateTimeout = 10 * time.Second
	SnapshotTimeout     = 240 * time.Second // Snapshotter sidecar has a timeout of 5 minutes.  Stay under that!
	DefaultTimeout      = 120 * time.Second
	MaxLabelLength      = 63
	MaxLabelCount       = 64
	DefaultSDKTimeout   = 30 * time.Second
	PaginationLimit     = 100
)
View Source
const (
	ProtocolTypeUnknown   = "Unknown"
	ProtocolTypeNFSPrefix = "NFSv"
	ProtocolTypeNFSv3     = ProtocolTypeNFSPrefix + "3"
	ProtocolTypeNFSv41    = ProtocolTypeNFSPrefix + "4.1"
	ProtocolTypeSMB       = "SMB"

	ServiceLevelUnspecified = "Unspecified"
	ServiceLevelFlex        = "Flex"
	ServiceLevelStandard    = "Standard"
	ServiceLevelPremium     = "Premium"
	ServiceLevelExtreme     = "Extreme"

	StoragePoolStateUnspecified = "Unspecified"
	StoragePoolStateReady       = "Ready"
	StoragePoolStateCreating    = "Creating"
	StoragePoolStateDeleting    = "Deleting"
	StoragePoolStateDeleted     = "NoSuchState"
	StoragePoolStateUpdating    = "Updating"
	StoragePoolStateRestoring   = "Restoring"
	StoragePoolStateDisabled    = "Disabled"
	StoragePoolStateError       = "Error"

	VolumeStateUnspecified = "Unspecified"
	VolumeStateReady       = "Ready"
	VolumeStateCreating    = "Creating"
	VolumeStateDeleting    = "Deleting"
	VolumeStateDeleted     = "NoSuchState"
	VolumeStateUpdating    = "Updating"
	VolumeStateRestoring   = "Restoring"
	VolumeStateDisabled    = "Disabled"
	VolumeStateError       = "Error"

	SnapshotStateUnspecified = "Unspecified"
	SnapshotStateReady       = "Ready"
	SnapshotStateCreating    = "Creating"
	SnapshotStateDeleting    = "Deleting"
	SnapshotStateDeleted     = "NoSuchState"
	SnapshotStateUpdating    = "Updating"
	SnapshotStateDisabled    = "Disabled"
	SnapshotStateError       = "Error"

	SecurityStyleUnspecified = "Unspecified"
	SecurityStyleNTFS        = "NTFS"
	SecurityStyleUnix        = "Unix"

	AccessTypeUnspecified = "Unspecified"
	AccessTypeReadOnly    = "ReadOnly"
	AccessTypeReadWrite   = "ReadWrite"
	AccessTypeReadNone    = "ReadNone"
)
View Source
const (
	ProjectNumber           = "123456789"
	Location                = "fake-location"
	Type                    = "fake-service-account"
	ProjectID               = "fake-project"
	PrivateKeyID            = "1234567b3456v44n"
	PrivateKey              = "-----BEGIN PRIVATE KEY-----fake-private-key----END PRIVATE KEY-----"
	ClientEmail             = "fake-client@email"
	ClientID                = "c5677na235896345363"
	AuthURI                 = "https://fake-auth.com/auth"
	TokenURI                = "https://fake-token.com/token" // #nosec
	AuthProviderX509CertURL = "https://fake-auth-provider.com/certs"
	ClientX509CertURL       = "https://fake-client.com/certs"

	BackendUUID     = "abcdefgh-03af-4394-ace4-e177cdbcaf28"
	SnapshotUUID    = "deadbeef-5c0d-4afa-8cd8-afa3fba5665c"
	VolumeSizeI64   = int64(107374182400)
	VolumeSizeStr   = "107374182400"
	StateReady      = "Ready"
	NetworkName     = "fake-network"
	NetworkFullName = "projects/" + ProjectNumber + "/locations/" + Location + "/networks/network"
	FullVolumeName  = "projects/" + ProjectNumber + "/locations/" + Location + "/volumes/"
)
View Source
const (
	DefaultMaxCacheAge = 10 * time.Minute
)

Variables

This section is empty.

Functions

func DerefAccessType

func DerefAccessType(at *netapppb.AccessType) netapppb.AccessType

func DerefBool

func DerefBool(b *bool) bool

DerefBool accepts a bool pointer and returns the value of the bool, or false if the pointer is nil.

func DerefString

func DerefString(s *string) string

DerefString accepts a string pointer and returns the value of the string, or "" if the pointer is nil.

func GCNVAccessTypeFromVolumeAccessType

func GCNVAccessTypeFromVolumeAccessType(accessType string) netapppb.AccessType

GCNVAccessTypeFromVolumeAccessType converts string to GCNV volume access type

func GCNVProtocolFromVolumeProtocol

func GCNVProtocolFromVolumeProtocol(protocol string) netapppb.Protocols

GCNVProtocolFromVolumeProtocol converts string to GCNV protocol type

func GCNVSecurityStyleFromVolumeSecurityStyle

func GCNVSecurityStyleFromVolumeSecurityStyle(state string) netapppb.SecurityStyle

GCNVSecurityStyleFromVolumeSecurityStyle converts string to GCNV volume security style

func IsGCNVNotFoundError

func IsGCNVNotFoundError(err error) bool

IsGCNVNotFoundError checks whether an error returned from the GCNV SDK contains a 404 (Not Found) error.

func IsGCNVTooManyRequestsError

func IsGCNVTooManyRequestsError(err error) bool

IsGCNVTooManyRequestsError checks whether an error returned from the GCNV SDK contains a 429 (Too Many Requests) error.

func IsTerminalStateError

func IsTerminalStateError(err error) bool

func ServiceLevelFromCapacityPool

func ServiceLevelFromCapacityPool(capacityPool *CapacityPool) string

func ServiceLevelFromGCNVServiceLevel

func ServiceLevelFromGCNVServiceLevel(serviceLevel netapppb.ServiceLevel) string

ServiceLevelFromGCNVServiceLevel converts GCNV service level to string

func SnapshotStateFromGCNVState

func SnapshotStateFromGCNVState(state netapppb.Snapshot_State) string

SnapshotStateFromGCNVState converts GCNV snapshot state to string

func StoragePoolStateFromGCNVState

func StoragePoolStateFromGCNVState(state netapppb.StoragePool_State) string

StoragePoolStateFromGCNVState converts GCNV storage pool state to string

func VolumeAccessTypeFromGCNVAccessType

func VolumeAccessTypeFromGCNVAccessType(accessType netapppb.AccessType) string

VolumeAccessTypeFromGCNVAccessType converts GCNV volume access type to string

func VolumeProtocolFromGCNVProtocol

func VolumeProtocolFromGCNVProtocol(protocol netapppb.Protocols) string

VolumeProtocolFromGCNVProtocol converts GCNV protocol type to string

func VolumeSecurityStyleFromGCNVSecurityStyle

func VolumeSecurityStyleFromGCNVSecurityStyle(state netapppb.SecurityStyle) string

VolumeSecurityStyleFromGCNVSecurityStyle converts GCNV volume security style to string

func VolumeStateFromGCNVState

func VolumeStateFromGCNVState(state netapppb.Volume_State) string

VolumeStateFromGCNVState converts GCNV volume state to string

Types

type CapacityPool

type CapacityPool struct {
	Name            string
	FullName        string
	Location        string
	ServiceLevel    string
	State           string
	NetworkName     string
	NetworkFullName string
	Zone            string
}

CapacityPool records details of a discovered GCNV storage pool.

func SortCPoolsByPreferredTopologies

func SortCPoolsByPreferredTopologies(
	ctx context.Context, cPools []*CapacityPool, preferredTopologies []map[string]string,
) []*CapacityPool

SortCPoolsByPreferredTopologies returns a list of capacity pools ordered by the provided list of preferred topologies.

type Client

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

Client encapsulates connection details.

func (Client) CapacityPools

func (c Client) CapacityPools() *[]*CapacityPool

CapacityPools returns a list of all discovered GCNV capacity pools.

func (Client) CapacityPoolsForStoragePool

func (c Client) CapacityPoolsForStoragePool(
	ctx context.Context, sPool storage.Pool, serviceLevel string,
) []*CapacityPool

CapacityPoolsForStoragePool returns all discovered capacity pools matching the specified storage pool and service level. The pools are shuffled to enable easier random selection.

func (Client) CapacityPoolsForStoragePools

func (c Client) CapacityPoolsForStoragePools(ctx context.Context) []*CapacityPool

CapacityPoolsForStoragePools returns all discovered capacity pools matching all known storage pools, regardless of service levels.

func (Client) CreateSnapshot

func (c Client) CreateSnapshot(ctx context.Context, volume *Volume, snapshotName string) (*Snapshot, error)

CreateSnapshot creates a new snapshot.

func (Client) CreateVolume

func (c Client) CreateVolume(ctx context.Context, request *VolumeCreateRequest) (*Volume, error)

CreateVolume creates a new volume.

func (Client) DeleteSnapshot

func (c Client) DeleteSnapshot(ctx context.Context, volume *Volume, snapshot *Snapshot) error

DeleteSnapshot deletes a snapshot.

func (Client) DeleteVolume

func (c Client) DeleteVolume(ctx context.Context, volume *Volume) error

DeleteVolume deletes a volume.

func (Client) DiscoverGCNVResources

func (c Client) DiscoverGCNVResources(ctx context.Context) (returnError error)

DiscoverGCNVResources rediscovers the GCNV resources we care about and updates the cache.

func (Client) EnsureVolumeInValidCapacityPool

func (c Client) EnsureVolumeInValidCapacityPool(ctx context.Context, volume *Volume) error

EnsureVolumeInValidCapacityPool checks whether the specified volume exists in any capacity pool that is referenced by the backend config. It returns nil if so, or if no capacity pools are named in the config.

func (Client) FilterCapacityPoolsOnTopology

func (c Client) FilterCapacityPoolsOnTopology(
	ctx context.Context, cPools []*CapacityPool, requisiteTopologies, preferredTopologies []map[string]string,
) []*CapacityPool

FilterCapacityPoolsOnTopology returns all the discovered capacity pools that support any of the requisite topologies. The discovered capacity pools are sorted based on the preferred topologies.

func (Client) Init

func (c Client) Init(ctx context.Context, pools map[string]storage.Pool) error

Init runs startup logic after allocating the driver resources.

func (Client) ListComputeZones

func (c Client) ListComputeZones(ctx context.Context) []string

func (Client) ModifyVolume

func (c Client) ModifyVolume(
	ctx context.Context, volume *Volume, labels map[string]string, unixPermissions *string,
	snapshotDirAccess *bool, _ *ExportRule,
) error

ModifyVolume updates attributes of a volume.

func (Client) RefreshGCNVResources

func (c Client) RefreshGCNVResources(ctx context.Context) error

RefreshGCNVResources refreshes the cache of discovered GCNV resources and validates them against our known storage pools.

func (Client) ResizeVolume

func (c Client) ResizeVolume(ctx context.Context, volume *Volume, newSizeBytes int64) error

ResizeVolume sends a VolumePatch to update a volume's quota.

func (Client) RestoreSnapshot

func (c Client) RestoreSnapshot(ctx context.Context, volume *Volume, snapshot *Snapshot) error

RestoreSnapshot restores a volume to a snapshot.

func (Client) SnapshotForVolume

func (c Client) SnapshotForVolume(
	ctx context.Context, volume *Volume, snapshotName string,
) (*Snapshot, error)

SnapshotForVolume fetches a specific snapshot on a volume by its name.

func (Client) SnapshotsForVolume

func (c Client) SnapshotsForVolume(ctx context.Context, volume *Volume) (*[]*Snapshot, error)

SnapshotsForVolume returns a list of snapshots on a volume.

func (Client) Volume

func (c Client) Volume(ctx context.Context, volConfig *storage.VolumeConfig) (*Volume, error)

Volume uses a volume config record to fetch a volume by the most efficient means.

func (Client) VolumeByID

func (c Client) VolumeByID(ctx context.Context, id string) (*Volume, error)

VolumeByID returns a Filesystem based on its GCNV-style ID.

func (Client) VolumeByName

func (c Client) VolumeByName(ctx context.Context, name string) (*Volume, error)

func (Client) VolumeByNameOrID

func (c Client) VolumeByNameOrID(ctx context.Context, volumeID string) (*Volume, error)

VolumeByNameOrID retrieves a gcnv volume for import by volumeName or volumeID

func (Client) VolumeExists

func (c Client) VolumeExists(ctx context.Context, volConfig *storage.VolumeConfig) (bool, *Volume, error)

VolumeExists uses a volume config record to look for a Filesystem by the most efficient means.

func (Client) VolumeExistsByID

func (c Client) VolumeExistsByID(ctx context.Context, id string) (bool, *Volume, error)

VolumeExistsByID checks whether a volume exists using its volume id as a key.

func (Client) VolumeExistsByName

func (c Client) VolumeExistsByName(ctx context.Context, name string) (bool, *Volume, error)

VolumeExistsByName checks whether a volume exists using its volume name as a key.

func (Client) Volumes

func (c Client) Volumes(ctx context.Context) (*[]*Volume, error)

Volumes queries GCNV SDK for all volumes in the current location.

func (Client) WaitForSnapshotState

func (c Client) WaitForSnapshotState(
	ctx context.Context, snapshot *Snapshot, volume *Volume, desiredState string, abortStates []string,
	maxElapsedTime time.Duration,
) error

WaitForSnapshotState waits for a desired snapshot state and returns once that state is achieved.

func (Client) WaitForVolumeState

func (c Client) WaitForVolumeState(
	ctx context.Context, volume *Volume, desiredState string, abortStates []string,
	maxElapsedTime time.Duration,
) (string, error)

WaitForVolumeState watches for a desired volume state and returns when that state is achieved.

type ClientConfig

type ClientConfig struct {
	StorageDriverName string

	// GCP project number
	ProjectNumber string

	// GCP CVS API authentication parameters
	APIKey *drivers.GCPPrivateKey

	// GCP region
	Location string

	// URL for accessing the API via an HTTP/HTTPS proxy
	ProxyURL string

	// Options
	DebugTraceFlags map[string]bool
	SDKTimeout      time.Duration // Timeout applied to all calls to the GCNV SDK
	MaxCacheAge     time.Duration // The oldest data we should expect in the cached resources
}

ClientConfig holds configuration data for the API driver object.

type ExportPolicy

type ExportPolicy struct {
	Rules []ExportRule
}

ExportPolicy records details of a discovered GCNV volume export policy.

type ExportRule

type ExportRule struct {
	AllowedClients string
	SMB            bool
	Nfsv3          bool
	Nfsv4          bool
	RuleIndex      int32
	AccessType     string
}

ExportRule records details of a discovered GCNV volume export policy rule.

type GCNV

type GCNV interface {
	Init(context.Context, map[string]storage.Pool) error

	RefreshGCNVResources(context.Context) error
	DiscoverGCNVResources(context.Context) error

	CapacityPools() *[]*CapacityPool
	CapacityPoolsForStoragePools(context.Context) []*CapacityPool
	CapacityPoolsForStoragePool(context.Context, storage.Pool, string) []*CapacityPool
	FilterCapacityPoolsOnTopology(context.Context, []*CapacityPool, []map[string]string, []map[string]string) []*CapacityPool
	EnsureVolumeInValidCapacityPool(context.Context, *Volume) error

	Volumes(context.Context) (*[]*Volume, error)
	Volume(context.Context, *storage.VolumeConfig) (*Volume, error)
	VolumeByName(context.Context, string) (*Volume, error)
	VolumeExists(context.Context, *storage.VolumeConfig) (bool, *Volume, error)
	VolumeExistsByName(context.Context, string) (bool, *Volume, error)
	VolumeByID(context.Context, string) (*Volume, error)
	VolumeExistsByID(context.Context, string) (bool, *Volume, error)
	VolumeByNameOrID(context.Context, string) (*Volume, error)
	WaitForVolumeState(context.Context, *Volume, string, []string, time.Duration) (string, error)
	CreateVolume(context.Context, *VolumeCreateRequest) (*Volume, error)
	ModifyVolume(context.Context, *Volume, map[string]string, *string, *bool, *ExportRule) error
	ResizeVolume(context.Context, *Volume, int64) error
	DeleteVolume(context.Context, *Volume) error

	SnapshotsForVolume(context.Context, *Volume) (*[]*Snapshot, error)
	SnapshotForVolume(context.Context, *Volume, string) (*Snapshot, error)
	WaitForSnapshotState(context.Context, *Snapshot, *Volume, string, []string, time.Duration) error
	CreateSnapshot(context.Context, *Volume, string) (*Snapshot, error)
	RestoreSnapshot(context.Context, *Volume, *Snapshot) error
	DeleteSnapshot(context.Context, *Volume, *Snapshot) error
}

func NewDriver

func NewDriver(ctx context.Context, config *ClientConfig) (GCNV, error)

NewDriver is a factory method for creating a new SDK interface.

type GCNVClient

type GCNVClient struct {
	GCNVResources
	// contains filtered or unexported fields
}

type GCNVResources

type GCNVResources struct {
	CapacityPoolMap map[string]*CapacityPool
	StoragePoolMap  map[string]storage.Pool
	// contains filtered or unexported fields
}

GCNVResources is the toplevel cache for the set of things we discover about our GCNV environment.

type MountTarget

type MountTarget struct {
	Export     string
	ExportPath string
	Protocol   string
}

MountTarget records details of a discovered GCNV volume mount target.

type Snapshot

type Snapshot struct {
	Name     string
	FullName string
	Volume   string
	Location string
	State    string
	Created  time.Time
	Labels   map[string]string
}

Snapshot records details of a discovered GCNV snapshot.

type TerminalStateError

type TerminalStateError struct {
	Err error
}

TerminalStateError signals that the object is in a terminal state. This is used to stop waiting on an object to change state.

func TerminalState

func TerminalState(err error) *TerminalStateError

TerminalState wraps the given err in a *TerminalStateError.

func (*TerminalStateError) Error

func (e *TerminalStateError) Error() string

type Volume

type Volume struct {
	Name              string
	CreationToken     string
	FullName          string
	Location          string
	State             string
	CapacityPool      string
	NetworkName       string
	NetworkFullName   string
	ServiceLevel      string
	SizeBytes         int64
	ExportPolicy      *ExportPolicy
	ProtocolTypes     []string
	MountTargets      []MountTarget
	UnixPermissions   string
	Labels            map[string]string
	SnapshotReserve   int64
	SnapshotDirectory bool
	SecurityStyle     string
}

Volume records details of a discovered GCNV volume.

type VolumeCreateRequest

type VolumeCreateRequest struct {
	Name              string
	CreationToken     string
	CapacityPool      string
	SizeBytes         int64
	ExportPolicy      *ExportPolicy
	ProtocolTypes     []string
	UnixPermissions   string
	Labels            map[string]string
	SnapshotReserve   *int64
	SnapshotDirectory bool
	SecurityStyle     string
	SnapshotID        string
}

VolumeCreateRequest embodies all the details of a volume to be created.

Jump to

Keyboard shortcuts

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