Fixes issue#392.
This commit is contained in:
@@ -19,6 +19,7 @@ package vclib
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
@@ -362,12 +363,14 @@ func (vm *VirtualMachine) getVirtualDeviceByPath(ctx context.Context, diskPath s
|
|||||||
glog.Errorf("Failed to get the devices for VM: %q. err: %+v", vm.InventoryPath, err)
|
glog.Errorf("Failed to get the devices for VM: %q. err: %+v", vm.InventoryPath, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter vm devices to retrieve device for the given vmdk file identified by disk path
|
// filter vm devices to retrieve device for the given vmdk file identified by disk path
|
||||||
for _, device := range vmDevices {
|
for _, device := range vmDevices {
|
||||||
if vmDevices.TypeName(device) == "VirtualDisk" {
|
if vmDevices.TypeName(device) == "VirtualDisk" {
|
||||||
virtualDevice := device.GetVirtualDevice()
|
virtualDevice := device.GetVirtualDevice()
|
||||||
if backing, ok := virtualDevice.Backing.(*types.VirtualDiskFlatVer2BackingInfo); ok {
|
if backing, ok := virtualDevice.Backing.(*types.VirtualDiskFlatVer2BackingInfo); ok {
|
||||||
if backing.FileName == diskPath {
|
if matchVirtualDiskAndVolPath(backing.FileName, diskPath) {
|
||||||
|
glog.V(LogLevel).Infof("Found VirtualDisk backing with filename %q for diskPath %q", backing.FileName, diskPath)
|
||||||
return device, nil
|
return device, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,6 +379,13 @@ func (vm *VirtualMachine) getVirtualDeviceByPath(ctx context.Context, diskPath s
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func matchVirtualDiskAndVolPath(diskPath, volPath string) bool {
|
||||||
|
fileExt := ".vmdk"
|
||||||
|
diskPath = strings.TrimSuffix(diskPath, fileExt)
|
||||||
|
volPath = strings.TrimSuffix(volPath, fileExt)
|
||||||
|
return diskPath == volPath
|
||||||
|
}
|
||||||
|
|
||||||
// deleteController removes latest added SCSI controller from VM.
|
// deleteController removes latest added SCSI controller from VM.
|
||||||
func (vm *VirtualMachine) deleteController(ctx context.Context, controllerDevice types.BaseVirtualDevice, vmDevices object.VirtualDeviceList) error {
|
func (vm *VirtualMachine) deleteController(ctx context.Context, controllerDevice types.BaseVirtualDevice, vmDevices object.VirtualDeviceList) error {
|
||||||
controllerDeviceList := vmDevices.SelectByType(controllerDevice)
|
controllerDeviceList := vmDevices.SelectByType(controllerDevice)
|
||||||
|
|||||||
@@ -835,6 +835,7 @@ func (vs *VSphere) DiskIsAttached(volPath string, nodeName k8stypes.NodeName) (b
|
|||||||
glog.Errorf("Failed to get VM object for node: %q. err: +%v", vSphereInstance, err)
|
glog.Errorf("Failed to get VM object for node: %q. err: +%v", vSphereInstance, err)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
volPath = vclib.RemoveStorageClusterORFolderNameFromVDiskPath(volPath)
|
volPath = vclib.RemoveStorageClusterORFolderNameFromVDiskPath(volPath)
|
||||||
attached, err := vm.IsDiskAttached(ctx, volPath)
|
attached, err := vm.IsDiskAttached(ctx, volPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -842,6 +843,7 @@ func (vs *VSphere) DiskIsAttached(volPath string, nodeName k8stypes.NodeName) (b
|
|||||||
volPath,
|
volPath,
|
||||||
vSphereInstance)
|
vSphereInstance)
|
||||||
}
|
}
|
||||||
|
glog.V(4).Infof("DiskIsAttached result: %q and error: %q, for volume: %q", attached, err, volPath)
|
||||||
return attached, err
|
return attached, err
|
||||||
}
|
}
|
||||||
requestTime := time.Now()
|
requestTime := time.Now()
|
||||||
|
|||||||
Reference in New Issue
Block a user