common

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MbInBytes is the number of bytes in one mebibyte.
	MbInBytes = int64(1024 * 1024)

	// GbInBytes is the number of bytes in one gibibyte.
	GbInBytes = int64(1024 * 1024 * 1024)

	// DefaultGbDiskSize is the default disk size in gibibytes.
	DefaultGbDiskSize = int64(10)

	// DiskTypeString is the value for the PersistentVolume's attribute "type"
	DiskTypeString = "vSphere CNS Block Volume"

	// AttributeDiskType is a PersistentVolume's attribute.
	AttributeDiskType = "type"

	// AttributeDatastoreURL represents URL of the datastore in the StorageClass
	// For Example: DatastoreURL: "ds:///vmfs/volumes/5c9bb20e-009c1e46-4b85-0200483b2a97/"
	AttributeDatastoreURL = "datastoreurl"

	// AttributeStoragePolicyName represents name of the Storage Policy in the Storage Class
	// For Example: StoragePolicy: "vSAN Default Storage Policy"
	AttributeStoragePolicyName = "storagepolicyname"

	// AttributeStoragePolicyID represents Storage Policy Id in the Storage Classs
	// For Example: StoragePolicyId: "251bce41-cb24-41df-b46b-7c75aed3c4ee"
	AttributeStoragePolicyID = "storagepolicyid"

	// AttributeFsType represents filesystem type in the Storage Classs
	// For Example: FsType: "ext4"
	AttributeFsType = "fstype"

	// DefaultFsType represents the default filesystem type which will be used to format the volume
	// during mount if user does not specify the filesystem type in the Storage Class
	DefaultFsType = "ext4"

	//ProviderPrefix is the prefix used for the ProviderID set on the node
	// Example: vsphere://4201794a-f26b-8914-d95a-edeb7ecc4a8f
	ProviderPrefix = "vsphere://"

	// AttributeFirstClassDiskUUID is the SCSI Disk Identifier
	AttributeFirstClassDiskUUID = "diskUUID"

	// BlockVolumeType is the VolumeType for CNS Volume
	BlockVolumeType = "BLOCK"

	// MinSupportedVCenterMajor is the minimum, major version of vCenter
	// on which CNS is supported.
	MinSupportedVCenterMajor int = 6

	// MinSupportedVCenterMinor is the minimum, minor version of vCenter
	// on which CNS is supported.
	MinSupportedVCenterMinor int = 7

	// MinSupportedVCenterPatch is the patch version supported with MinSupportedVCenterMajor and MinSupportedVCenterMinor
	MinSupportedVCenterPatch int = 3
)

Variables

View Source
var (
	// VolumeCaps represents how the volume could be accessed.
	// It is SINGLE_NODE_WRITER since vSphere CNS Block volume could only be
	// attached to a single node at any given time.
	VolumeCaps = []csi.VolumeCapability_AccessMode{
		{
			Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
		},
	}
)

Functions

func AttachVolumeUtil

func AttachVolumeUtil(ctx context.Context, manager *Manager,
	vm *vsphere.VirtualMachine,
	volumeID string) (string, error)

AttachVolumeUtil is the helper function to attach CNS volume to specified vm

func CheckAPI

func CheckAPI(version string) error

CheckAPI checks if specified version is 6.7.3 or higher

func CreateVolumeUtil

func CreateVolumeUtil(ctx context.Context, manager *Manager, spec *CreateVolumeSpec, sharedDatastores []*vsphere.DatastoreInfo) (string, error)

CreateVolumeUtil is the helper function to create CNS volume

func DeleteVolumeUtil

func DeleteVolumeUtil(ctx context.Context, manager *Manager, volumeID string, deleteDisk bool) error

DeleteVolumeUtil is the helper function to delete CNS volume for given volumeId

func DetachVolumeUtil

func DetachVolumeUtil(ctx context.Context, manager *Manager,
	vm *vsphere.VirtualMachine,
	volumeID string) error

DetachVolumeUtil is the helper function to detach CNS volume from specified vm

func FormatDiskUUID

func FormatDiskUUID(uuid string) string

FormatDiskUUID removes any spaces and hyphens in UUID Example UUID input is 42375390-71f9-43a3-a770-56803bcd7baa and output after format is 4237539071f943a3a77056803bcd7baa

func GetLabelsMapFromKeyValue

func GetLabelsMapFromKeyValue(labels []types.KeyValue) map[string]string

GetLabelsMapFromKeyValue creates a map object from given parameter

func GetUUIDFromProviderID

func GetUUIDFromProviderID(providerID string) string

GetUUIDFromProviderID Returns VM UUID from Node's providerID

func GetVCenter

func GetVCenter(ctx context.Context, manager *Manager) (*cnsvsphere.VirtualCenter, error)

GetVCenter returns VirtualCenter object from specified Manager object. Before returning VirtualCenter object, vcenter connection is established if session doesn't exist.

func IsValidVolumeCapabilities

func IsValidVolumeCapabilities(volCaps []*csi.VolumeCapability) bool

IsValidVolumeCapabilities is the helper function to validate capabilities of volume.

func RoundUpSize

func RoundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64

RoundUpSize calculates how many allocation units are needed to accommodate a volume of given size.

func ValidateControllerPublishVolumeRequest

func ValidateControllerPublishVolumeRequest(req *csi.ControllerPublishVolumeRequest) error

ValidateControllerPublishVolumeRequest is the helper function to validate ControllerPublishVolumeRequest for all block controllers. Function returns error if validation fails otherwise returns nil.

func ValidateControllerUnpublishVolumeRequest

func ValidateControllerUnpublishVolumeRequest(req *csi.ControllerUnpublishVolumeRequest) error

ValidateControllerUnpublishVolumeRequest is the helper function to validate ControllerUnpublishVolumeRequest for all block controllers. Function returns error if validation fails otherwise returns nil.

func ValidateCreateVolumeRequest

func ValidateCreateVolumeRequest(req *csi.CreateVolumeRequest) error

ValidateCreateVolumeRequest is the helper function to validate CreateVolumeRequest for all block controllers. Function returns error if validation fails otherwise returns nil.

func ValidateDeleteVolumeRequest

func ValidateDeleteVolumeRequest(req *csi.DeleteVolumeRequest) error

ValidateDeleteVolumeRequest is the helper function to validate DeleteVolumeRequest for all block controllers. Function returns error if validation fails otherwise returns nil.

Types

type CreateVolumeSpec

type CreateVolumeSpec struct {
	Name              string
	StoragePolicyName string
	StoragePolicyID   string
	DatastoreURL      string
	CapacityMB        int64
}

CreateVolumeSpec is the Volume Spec used by CSI driver

type Manager

type Manager struct {
	VcenterConfig  *cnsvsphere.VirtualCenterConfig
	CnsConfig      *config.Config
	VolumeManager  cnsvolume.Manager
	VcenterManager cnsvsphere.VirtualCenterManager
}

Manager type comprises VirtualCenterConfig, CnsConfig, VolumeManager and VirtualCenterManager

Jump to

Keyboard shortcuts

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