vclib

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2018 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ThinDiskType             = "thin"
	PreallocatedDiskType     = "preallocated"
	EagerZeroedThickDiskType = "eagerZeroedThick"
	ZeroedThickDiskType      = "zeroedThick"
)

Volume Constnts

View Source
const (
	SCSIControllerLimit       = 4
	SCSIControllerDeviceLimit = 15
	SCSIDeviceSlots           = 16
	SCSIReservedSlot          = 7

	SCSIControllerType        = "scsi"
	LSILogicControllerType    = "lsiLogic"
	BusLogicControllerType    = "busLogic"
	LSILogicSASControllerType = "lsiLogic-sas"
	PVSCSIControllerType      = "pvscsi"
)

Controller Constants

View Source
const (
	LogLevel                 = 4
	DatastoreProperty        = "datastore"
	ResourcePoolProperty     = "resourcePool"
	DatastoreInfoProperty    = "info"
	VirtualMachineType       = "VirtualMachine"
	RoundTripperDefaultCount = 3
	VSANDatastoreType        = "vsan"
	DummyVMPrefixName        = "vsphere-k8s"
	ActivePowerState         = "poweredOn"
)

Other Constants

View Source
const (
	TestDefaultDatacenter = "DC0"
	TestDefaultDatastore  = "LocalDS_0"
	TestDefaultNetwork    = "VM Network"
)

Test Constants

View Source
const (
	FileAlreadyExistErrMsg     = "File requested already exist"
	NoDiskUUIDFoundErrMsg      = "No disk UUID found"
	NoDevicesFoundErrMsg       = "No devices found"
	DiskNotFoundErrMsg         = "No vSphere disk ID found"
	InvalidVolumeOptionsErrMsg = "VolumeOptions verification failed"
	NoVMFoundErrMsg            = "No VM found"
)

Error Messages

View Source
const (
	APICreateVolume = "CreateVolume"
	APIDeleteVolume = "DeleteVolume"
	APIAttachVolume = "AttachVolume"
	APIDetachVolume = "DetachVolume"
)

Cloud Provider API constants

View Source
const (
	OperationDeleteVolume                  = "DeleteVolumeOperation"
	OperationAttachVolume                  = "AttachVolumeOperation"
	OperationDetachVolume                  = "DetachVolumeOperation"
	OperationDiskIsAttached                = "DiskIsAttachedOperation"
	OperationDisksAreAttached              = "DisksAreAttachedOperation"
	OperationCreateVolume                  = "CreateVolumeOperation"
	OperationCreateVolumeWithPolicy        = "CreateVolumeWithPolicyOperation"
	OperationCreateVolumeWithRawVSANPolicy = "CreateVolumeWithRawVSANPolicyOperation"
)

Cloud Provider Operation constants

Variables

View Source
var (
	ErrFileAlreadyExist     = errors.New(FileAlreadyExistErrMsg)
	ErrNoDiskUUIDFound      = errors.New(NoDiskUUIDFoundErrMsg)
	ErrNoDevicesFound       = errors.New(NoDevicesFoundErrMsg)
	ErrNoDiskIDFound        = errors.New(DiskNotFoundErrMsg)
	ErrInvalidVolumeOptions = errors.New(InvalidVolumeOptionsErrMsg)
	ErrNoVMFound            = errors.New(NoVMFoundErrMsg)
)

Error constants

View Source
var (
	// DiskFormatValidType specifies the valid disk formats
	DiskFormatValidType = map[string]string{
		ThinDiskType: ThinDiskType,
		strings.ToLower(EagerZeroedThickDiskType): EagerZeroedThickDiskType,
		strings.ToLower(ZeroedThickDiskType):      PreallocatedDiskType,
	}
	// SCSIControllerValidType specifies the supported SCSI controllers
	SCSIControllerValidType = []string{LSILogicControllerType, LSILogicSASControllerType, PVSCSIControllerType}
)

Functions

func CheckControllerSupported

func CheckControllerSupported(ctrlType string) bool

CheckControllerSupported checks if the given controller type is valid

func CheckDiskFormatSupported

func CheckDiskFormatSupported(diskFormat string) bool

CheckDiskFormatSupported checks if the diskFormat is valid

func DiskformatValidOptions

func DiskformatValidOptions() string

DiskformatValidOptions generates Valid Options for Diskformat

func GetDatastorePathObjFromVMDiskPath added in v1.8.3

func GetDatastorePathObjFromVMDiskPath(vmDiskPath string) (*object.DatastorePath, error)

GetDatastorePathObjFromVMDiskPath gets the datastorePathObj from VM disk path.

func GetPathFromVMDiskPath added in v1.8.3

func GetPathFromVMDiskPath(vmDiskPath string) string

GetPathFromVMDiskPath retrieves the path from VM Disk Path. Example: For vmDiskPath - [vsanDatastore] kubevols/volume.vmdk, the path is kubevols/volume.vmdk

func IsInvalidCredentialsError added in v1.11.0

func IsInvalidCredentialsError(err error) bool

IsInvalidCredentialsError returns true if error is of type InvalidLogin

func IsManagedObjectNotFoundError added in v1.9.0

func IsManagedObjectNotFoundError(err error) bool

IsManagedObjectNotFoundError returns true if error is of type ManagedObjectNotFound

func IsNotFound

func IsNotFound(err error) bool

IsNotFound return true if err is NotFoundError or DefaultNotFoundError

func IsValidUUID added in v1.8.3

func IsValidUUID(uuid string) bool

IsValidUUID checks if the string is a valid UUID.

func RecordCreateVolumeMetric

func RecordCreateVolumeMetric(volumeOptions *VolumeOptions, requestTime time.Time, err error)

RecordCreateVolumeMetric records the Create Volume metric

func RecordvSphereMetric

func RecordvSphereMetric(actionName string, requestTime time.Time, err error)

RecordvSphereMetric records the vSphere API and Operation metrics

func RegisterMetrics

func RegisterMetrics()

RegisterMetrics registers all the API and Operation metrics

func RemoveStorageClusterORFolderNameFromVDiskPath added in v1.9.0

func RemoveStorageClusterORFolderNameFromVDiskPath(vDiskPath string) string

RemoveStorageClusterORFolderNameFromVDiskPath removes the cluster or folder path from the vDiskPath for vDiskPath DatastoreCluster/sharedVmfs-0 kubevols/e2e-vmdk-1234.vmdk, return value is [sharedVmfs-0] kubevols/e2e-vmdk-1234.vmdk for vDiskPath [sharedVmfs-0] kubevols/e2e-vmdk-1234.vmdk, return value remains same [sharedVmfs-0] kubevols/e2e-vmdk-1234.vmdk

func SCSIControllerTypeValidOptions

func SCSIControllerTypeValidOptions() string

SCSIControllerTypeValidOptions generates valid options for SCSIControllerType

func VerifyVolumePathsForVM added in v1.9.0

func VerifyVolumePathsForVM(vmMo mo.VirtualMachine, volPaths []string, nodeName string, nodeVolumeMap map[string]map[string]bool)

VerifyVolumePathsForVM verifies if the volume paths (volPaths) are attached to VM.

func VerifyVolumePathsForVMDevices added in v1.9.0

func VerifyVolumePathsForVMDevices(vmDevices object.VirtualDeviceList, volPaths []string, nodeName string, nodeVolumeMap map[string]map[string]bool)

VerifyVolumePathsForVMDevices verifies if the volume paths (volPaths) are attached to VM.

Types

type Datacenter

type Datacenter struct {
	*object.Datacenter
}

Datacenter extends the govmomi Datacenter object

func GetAllDatacenter added in v1.9.0

func GetAllDatacenter(ctx context.Context, connection *VSphereConnection) ([]*Datacenter, error)

GetAllDatacenter returns all the DataCenter Objects

func GetDatacenter

func GetDatacenter(ctx context.Context, connection *VSphereConnection, datacenterPath string) (*Datacenter, error)

GetDatacenter returns the DataCenter Object for the given datacenterPath If datacenter is located in a folder, include full path to datacenter else just provide the datacenter name

func (*Datacenter) CheckDisksAttached added in v1.8.3

func (dc *Datacenter) CheckDisksAttached(ctx context.Context, nodeVolumes map[string][]string) (map[string]map[string]bool, error)

CheckDisksAttached checks if the disk is attached to node. This is done by comparing the volume path with the backing.FilePath on the VM Virtual disk devices.

func (*Datacenter) GetAllDatastores added in v1.9.0

func (dc *Datacenter) GetAllDatastores(ctx context.Context) (map[string]*DatastoreInfo, error)

GetAllDatastores gets the datastore URL to DatastoreInfo map for all the datastores in the datacenter.

func (*Datacenter) GetDatastoreByName

func (dc *Datacenter) GetDatastoreByName(ctx context.Context, name string) (*Datastore, error)

GetDatastoreByName gets the Datastore object for the given datastore name

func (*Datacenter) GetDatastoreByPath

func (dc *Datacenter) GetDatastoreByPath(ctx context.Context, vmDiskPath string) (*Datastore, error)

GetDatastoreByPath gets the Datastore object from the given vmDiskPath

func (*Datacenter) GetDatastoreMoList

func (dc *Datacenter) GetDatastoreMoList(ctx context.Context, dsObjList []*Datastore, properties []string) ([]mo.Datastore, error)

GetDatastoreMoList gets the Datastore Managed Objects with the given properties from the datastore objects

func (*Datacenter) GetFolderByPath

func (dc *Datacenter) GetFolderByPath(ctx context.Context, folderPath string) (*Folder, error)

GetFolderByPath gets the Folder Object from the given folder path folderPath should be the full path to folder

func (*Datacenter) GetResourcePool added in v1.9.0

func (dc *Datacenter) GetResourcePool(ctx context.Context, resourcePoolPath string) (*object.ResourcePool, error)

GetResourcePool gets the resource pool for the given path

func (*Datacenter) GetVMByPath

func (dc *Datacenter) GetVMByPath(ctx context.Context, vmPath string) (*VirtualMachine, error)

GetVMByPath gets the VM object from the given vmPath vmPath should be the full path to VM and not just the name

func (*Datacenter) GetVMByUUID

func (dc *Datacenter) GetVMByUUID(ctx context.Context, vmUUID string) (*VirtualMachine, error)

GetVMByUUID gets the VM object from the given vmUUID

func (*Datacenter) GetVMMoList

func (dc *Datacenter) GetVMMoList(ctx context.Context, vmObjList []*VirtualMachine, properties []string) ([]mo.VirtualMachine, error)

GetVMMoList gets the VM Managed Objects with the given properties from the VM object

func (*Datacenter) GetVirtualDiskPage83Data added in v1.8.3

func (dc *Datacenter) GetVirtualDiskPage83Data(ctx context.Context, diskPath string) (string, error)

GetVirtualDiskPage83Data gets the virtual disk UUID by diskPath

type Datastore

type Datastore struct {
	*object.Datastore
	Datacenter *Datacenter
}

Datastore extends the govmomi Datastore object

func (*Datastore) CreateDirectory

func (ds *Datastore) CreateDirectory(ctx context.Context, directoryPath string, createParents bool) error

CreateDirectory creates the directory at location specified by directoryPath. If the intermediate level folders do not exist, and the parameter createParents is true, all the non-existent folders are created. directoryPath must be in the format "[vsanDatastore] kubevols"

func (*Datastore) GetType

func (ds *Datastore) GetType(ctx context.Context) (string, error)

GetType returns the type of datastore

func (*Datastore) IsCompatibleWithStoragePolicy

func (ds *Datastore) IsCompatibleWithStoragePolicy(ctx context.Context, storagePolicyID string) (bool, string, error)

IsCompatibleWithStoragePolicy returns true if datastore is compatible with given storage policy else return false for not compatible datastore, fault message is also returned

type DatastoreInfo added in v1.9.0

type DatastoreInfo struct {
	*Datastore
	Info *types.DatastoreInfo
}

DatastoreInfo is a structure to store the Datastore and it's Info.

func (DatastoreInfo) String added in v1.9.0

func (di DatastoreInfo) String() string

type Folder

type Folder struct {
	*object.Folder
	Datacenter *Datacenter
}

Folder extends the govmomi Folder object

func (*Folder) GetVirtualMachines

func (folder *Folder) GetVirtualMachines(ctx context.Context) ([]*VirtualMachine, error)

GetVirtualMachines returns list of VirtualMachine inside a folder.

type PbmClient

type PbmClient struct {
	*pbm.Client
}

PbmClient is extending govmomi pbm, and provides functions to get compatible list of datastore for given policy

func NewPbmClient

func NewPbmClient(ctx context.Context, client *vim25.Client) (*PbmClient, error)

NewPbmClient returns a new PBM Client object

func (*PbmClient) GetCompatibleDatastores

func (pbmClient *PbmClient) GetCompatibleDatastores(ctx context.Context, dc *Datacenter, storagePolicyID string, datastores []*DatastoreInfo) ([]*DatastoreInfo, string, error)

GetCompatibleDatastores filters and returns compatible list of datastores for given storage policy id For Non Compatible Datastores, fault message with the Datastore Name is also returned

func (*PbmClient) GetPlacementCompatibilityResult

func (pbmClient *PbmClient) GetPlacementCompatibilityResult(ctx context.Context, storagePolicyID string, datastore []*DatastoreInfo) (pbm.PlacementCompatibilityResult, error)

GetPlacementCompatibilityResult gets placement compatibility result based on storage policy requirements.

func (*PbmClient) IsDatastoreCompatible

func (pbmClient *PbmClient) IsDatastoreCompatible(ctx context.Context, storagePolicyID string, datastore *Datastore) (bool, string, error)

IsDatastoreCompatible check if the datastores is compatible for given storage policy id if datastore is not compatible with policy, fault message with the Datastore Name is returned

type VMOptions

type VMOptions struct {
	VMFolder       *Folder
	VMResourcePool *object.ResourcePool
}

VMOptions provides helper objects for provisioning volume with SPBM Policy

type VSphereConnection

type VSphereConnection struct {
	Client            *vim25.Client
	Username          string
	Password          string
	Hostname          string
	Port              string
	Insecure          bool
	RoundTripperCount uint
	// contains filtered or unexported fields
}

VSphereConnection contains information for connecting to vCenter

func (*VSphereConnection) Connect

func (connection *VSphereConnection) Connect(ctx context.Context) error

Connect makes connection to vCenter and sets VSphereConnection.Client. If connection.Client is already set, it obtains the existing user session. if user session is not valid, connection.Client will be set to the new client.

func (*VSphereConnection) Logout added in v1.11.0

func (connection *VSphereConnection) Logout(ctx context.Context)

Logout calls SessionManager.Logout for the given connection.

func (*VSphereConnection) NewClient

func (connection *VSphereConnection) NewClient(ctx context.Context) (*vim25.Client, error)

NewClient creates a new govmomi client for the VSphereConnection obj

func (*VSphereConnection) UpdateCredentials added in v1.11.0

func (connection *VSphereConnection) UpdateCredentials(username string, password string)

UpdateCredentials updates username and password. Note: Updated username and password will be used when there is no session active

type VirtualMachine

type VirtualMachine struct {
	*object.VirtualMachine
	Datacenter *Datacenter
}

VirtualMachine extends the govmomi VirtualMachine object

func (*VirtualMachine) AttachDisk

func (vm *VirtualMachine) AttachDisk(ctx context.Context, vmDiskPath string, volumeOptions *VolumeOptions) (string, error)

AttachDisk attaches the disk at location - vmDiskPath from Datastore - dsObj to the Virtual Machine Additionally the disk can be configured with SPBM policy if volumeOptions.StoragePolicyID is non-empty.

func (*VirtualMachine) CreateDiskSpec

func (vm *VirtualMachine) CreateDiskSpec(ctx context.Context, diskPath string, dsObj *Datastore, volumeOptions *VolumeOptions) (*types.VirtualDisk, types.BaseVirtualDevice, error)

CreateDiskSpec creates a disk spec for disk

func (*VirtualMachine) DeleteVM

func (vm *VirtualMachine) DeleteVM(ctx context.Context) error

DeleteVM deletes the VM.

func (*VirtualMachine) DetachDisk

func (vm *VirtualMachine) DetachDisk(ctx context.Context, vmDiskPath string) error

DetachDisk detaches the disk specified by vmDiskPath

func (*VirtualMachine) GetAllAccessibleDatastores

func (vm *VirtualMachine) GetAllAccessibleDatastores(ctx context.Context) ([]*DatastoreInfo, error)

GetAllAccessibleDatastores gets the list of accessible Datastores for the given Virtual Machine

func (*VirtualMachine) GetResourcePool

func (vm *VirtualMachine) GetResourcePool(ctx context.Context) (*object.ResourcePool, error)

GetResourcePool gets the resource pool for VM.

func (*VirtualMachine) GetVirtualDiskPath added in v1.8.3

func (vm *VirtualMachine) GetVirtualDiskPath(ctx context.Context) (string, error)

GetVirtualDiskPath gets the first available virtual disk devicePath from the VM

func (*VirtualMachine) IsActive

func (vm *VirtualMachine) IsActive(ctx context.Context) (bool, error)

IsActive checks if the VM is active. Returns true if VM is in poweredOn state.

func (*VirtualMachine) IsDiskAttached

func (vm *VirtualMachine) IsDiskAttached(ctx context.Context, diskPath string) (bool, error)

IsDiskAttached checks if disk is attached to the VM.

func (*VirtualMachine) RenewVM added in v1.9.2

func (vm *VirtualMachine) RenewVM(client *vim25.Client) VirtualMachine

RenewVM renews this virtual machine with new client connection.

type VolumeOptions

type VolumeOptions struct {
	CapacityKB             int
	Tags                   map[string]string
	Name                   string
	DiskFormat             string
	Datastore              string
	VSANStorageProfileData string
	StoragePolicyName      string
	StoragePolicyID        string
	SCSIControllerType     string
}

VolumeOptions specifies various options for a volume.

func (VolumeOptions) VerifyVolumeOptions

func (volumeOptions VolumeOptions) VerifyVolumeOptions() bool

VerifyVolumeOptions checks if volumeOptions.SCIControllerType is valid controller type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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