Documentation ¶
Index ¶
- Constants
- Variables
- func CheckControllerSupported(ctrlType string) bool
- func CheckDiskFormatSupported(diskFormat string) bool
- func DiskformatValidOptions() string
- func GetDatastorePathObjFromVMDiskPath(vmDiskPath string) (*object.DatastorePath, error)
- func GetPathFromVMDiskPath(vmDiskPath string) string
- func IsManagedObjectNotFoundError(err error) bool
- func IsNotFound(err error) bool
- func IsValidUUID(uuid string) bool
- func RecordCreateVolumeMetric(volumeOptions *VolumeOptions, requestTime time.Time, err error)
- func RecordvSphereMetric(actionName string, requestTime time.Time, err error)
- func RegisterMetrics()
- func RemoveStorageClusterORFolderNameFromVDiskPath(vDiskPath string) string
- func SCSIControllerTypeValidOptions() string
- func VerifyVolumePathsForVM(vmMo mo.VirtualMachine, volPaths []string, nodeName string, ...)
- func VerifyVolumePathsForVMDevices(vmDevices object.VirtualDeviceList, volPaths []string, nodeName string, ...)
- type Datacenter
- func (dc *Datacenter) CheckDisksAttached(ctx context.Context, nodeVolumes map[string][]string) (map[string]map[string]bool, error)
- func (dc *Datacenter) GetAllDatastores(ctx context.Context) (map[string]*DatastoreInfo, error)
- func (dc *Datacenter) GetDatastoreByName(ctx context.Context, name string) (*Datastore, error)
- func (dc *Datacenter) GetDatastoreByPath(ctx context.Context, vmDiskPath string) (*Datastore, error)
- func (dc *Datacenter) GetDatastoreMoList(ctx context.Context, dsObjList []*Datastore, properties []string) ([]mo.Datastore, error)
- func (dc *Datacenter) GetFolderByPath(ctx context.Context, folderPath string) (*Folder, error)
- func (dc *Datacenter) GetResourcePool(ctx context.Context, computePath string) (*object.ResourcePool, error)
- func (dc *Datacenter) GetVMByPath(ctx context.Context, vmPath string) (*VirtualMachine, error)
- func (dc *Datacenter) GetVMByUUID(ctx context.Context, vmUUID string) (*VirtualMachine, error)
- func (dc *Datacenter) GetVMMoList(ctx context.Context, vmObjList []*VirtualMachine, properties []string) ([]mo.VirtualMachine, error)
- func (dc *Datacenter) GetVirtualDiskPage83Data(ctx context.Context, diskPath string) (string, error)
- type Datastore
- type DatastoreInfo
- type Folder
- type PbmClient
- func (pbmClient *PbmClient) GetCompatibleDatastores(ctx context.Context, dc *Datacenter, storagePolicyID string, ...) ([]*DatastoreInfo, string, error)
- func (pbmClient *PbmClient) GetPlacementCompatibilityResult(ctx context.Context, storagePolicyID string, datastore []*DatastoreInfo) (pbm.PlacementCompatibilityResult, error)
- func (pbmClient *PbmClient) IsDatastoreCompatible(ctx context.Context, storagePolicyID string, datastore *Datastore) (bool, string, error)
- type VMOptions
- type VSphereConnection
- type VirtualMachine
- func (vm *VirtualMachine) AttachDisk(ctx context.Context, vmDiskPath string, volumeOptions *VolumeOptions) (string, error)
- func (vm *VirtualMachine) CreateDiskSpec(ctx context.Context, diskPath string, dsObj *Datastore, ...) (*types.VirtualDisk, types.BaseVirtualDevice, error)
- func (vm *VirtualMachine) DeleteVM(ctx context.Context) error
- func (vm *VirtualMachine) DetachDisk(ctx context.Context, vmDiskPath string) error
- func (vm *VirtualMachine) GetAllAccessibleDatastores(ctx context.Context) ([]*DatastoreInfo, error)
- func (vm *VirtualMachine) GetResourcePool(ctx context.Context) (*object.ResourcePool, error)
- func (vm *VirtualMachine) GetVirtualDiskPath(ctx context.Context) (string, error)
- func (vm *VirtualMachine) IsActive(ctx context.Context) (bool, error)
- func (vm *VirtualMachine) IsDiskAttached(ctx context.Context, diskPath string) (bool, error)
- type VolumeOptions
Constants ¶
const ( ThinDiskType = "thin" PreallocatedDiskType = "preallocated" EagerZeroedThickDiskType = "eagerZeroedThick" ZeroedThickDiskType = "zeroedThick" )
Volume Constnts
const ( SCSIControllerLimit = 4 SCSIControllerDeviceLimit = 15 SCSIDeviceSlots = 16 SCSIReservedSlot = 7 SCSIControllerType = "scsi" LSILogicControllerType = "lsiLogic" BusLogicControllerType = "busLogic" LSILogicSASControllerType = "lsiLogic-sas" PVSCSIControllerType = "pvscsi" )
Controller Constants
const ( LogLevel = 4 DatastoreProperty = "datastore" ResourcePoolProperty = "resourcePool" DatastoreInfoProperty = "info" VirtualMachineType = "VirtualMachine" RoundTripperDefaultCount = 3 VSANDatastoreType = "vsan" DummyVMPrefixName = "vsphere-k8s" ActivePowerState = "poweredOn" )
Other Constants
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
const ( APICreateVolume = "CreateVolume" APIDeleteVolume = "DeleteVolume" APIAttachVolume = "AttachVolume" APIDetachVolume = "DetachVolume" )
Cloud Provider API constants
const ( OperationDeleteVolume = "DeleteVolumeOperation" OperationAttachVolume = "AttachVolumeOperation" OperationDetachVolume = "DetachVolumeOperation" OperationDiskIsAttached = "DiskIsAttachedOperation" OperationDisksAreAttached = "DisksAreAttachedOperation" OperationCreateVolume = "CreateVolumeOperation" OperationCreateVolumeWithPolicy = "CreateVolumeWithPolicyOperation" OperationCreateVolumeWithRawVSANPolicy = "CreateVolumeWithRawVSANPolicyOperation" )
Cloud Provider Operation constants
Variables ¶
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
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 ¶
CheckControllerSupported checks if the given controller type is valid
func CheckDiskFormatSupported ¶
CheckDiskFormatSupported checks if the diskFormat is valid
func DiskformatValidOptions ¶
func DiskformatValidOptions() string
DiskformatValidOptions generates Valid Options for Diskformat
func GetDatastorePathObjFromVMDiskPath ¶
func GetDatastorePathObjFromVMDiskPath(vmDiskPath string) (*object.DatastorePath, error)
GetDatastorePathObjFromVMDiskPath gets the datastorePathObj from VM disk path.
func GetPathFromVMDiskPath ¶
GetPathFromVMDiskPath retrieves the path from VM Disk Path. Example: For vmDiskPath - [vsanDatastore] kubevols/volume.vmdk, the path is kubevols/volume.vmdk
func IsManagedObjectNotFoundError ¶
IsManagedObjectNotFoundError returns true if error is of type ManagedObjectNotFound
func IsNotFound ¶
IsNotFound return true if err is NotFoundError or DefaultNotFoundError
func IsValidUUID ¶
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 ¶
RecordvSphereMetric records the vSphere API and Operation metrics
func RegisterMetrics ¶
func RegisterMetrics()
RegisterMetrics registers all the API and Operation metrics
func RemoveStorageClusterORFolderNameFromVDiskPath ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
GetFolderByPath gets the Folder Object from the given folder path folderPath should be the full path to folder
func (*Datacenter) GetResourcePool ¶
func (dc *Datacenter) GetResourcePool(ctx context.Context, computePath 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 ¶
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) 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 ¶
type DatastoreInfo struct { *Datastore Info *types.DatastoreInfo }
DatastoreInfo is a structure to store the Datastore and it's Info.
func (DatastoreInfo) String ¶
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 ¶
PbmClient is extending govmomi pbm, and provides functions to get compatible list of datastore for given policy
func NewPbmClient ¶
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 { GoVmomiClient *govmomi.Client Username string Password string Hostname string Port string Insecure bool RoundTripperCount uint }
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.GoVmomiClient. If connection.GoVmomiClient is already set, it obtains the existing user session. if user session is not valid, connection.GoVmomiClient will be set to the new client.
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 ¶
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 ¶
IsDiskAttached checks if disk is attached to the VM.
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