Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.4.2
-
None
Description
VIM_SSH.pm::get_virtual_disk_hardware_version calls the following command similar to the following to retrieve the hardware version from a .vmdk file:
vim-cmd hostsvc/datastorebrowser/searchsubfolders 0 "[datastore-name] vmwarelinux-imagename-v9"
It then parses the output:
(vim.host.DatastoreBrowser.SearchResults) [ (vim.host.DatastoreBrowser.SearchResults) { dynamicType = <unset>, datastore = 'vim.Datastore:55921f72-785b973c-9fe6-6c0b8462bd80', folderPath = "[datastore-name] vmwarelinux-imagename-v9", file = (vim.host.DatastoreBrowser.FileInfo) [ (vim.host.DatastoreBrowser.VmDiskInfo) { dynamicType = <unset>, path = "vmwarelinux-imagename-v9.vmdk", fileSize = 9457106944, modification = "2016-02-05T16:58:35Z", owner = <unset>, diskType = "vim.vm.device.VirtualDisk.FlatVer2BackingInfo", capacityKb = 31457280, hardwareVersion = 11, controllerType = "vim.vm.device.VirtualLsiLogicController", diskExtents = (string) [ "[datastore-name] vmwarelinux-imagename-v9/vmwarelinux-imagename-v9-flat.vmdk" ], thin = true, } ], } ]
The important string is hardwareVersion = 11. The code then extracts the part after the equals sign:
my ($hardware_version) = $disk_info =~ /\shardwareVersion\s*=\s*(.+)/i;
At this point, $hardware_version = '11,'. The code does not specifically look for an integer at this point because the output may contain something such as 'unset,'.
The code checks for 'unset', then proceeds to extract an integer with the following regex:
$hardware_version =~ s/.*(\d+).*/$1/ig;
This is problematic because it is not consistently returning only the integer. Sometimes it returns 1 and other times 0.