When iterating through a list of devices attached to a VM with the following perl loop, VirtualSCSIController objects instantiated by VirtualLsiLogicSASController, VirtualBusLogicController, or ParaVirtualController return an *UN*initialized array for the device[] property which is supposed to return a list of devices attached to that controller.
If VirtualSCSIController is instantiated by VirtualLsiLogicController, the device[] property is properly initialized as an array and contains a list of devices attached to the controller.
//@vm_devices is returned earlier from a call to the subroutine find_scsi_controller_device() in VMUtil.pm which I have modified to return all VirtualSCSIController objects that match a specific busNumber
sub find_scsi_controller_device {
my %args = @_;
my $vm = $args{vm};
my $vctrl_num = $args{vctrl_num};
my $devices = $vm->config->hardware->device;
print "Controller number passed to find_scsi_controller_device is $vctrl_num\n";
foreach my $device (@$devices) {
if ( $device->isa('VirtualSCSIController') && ($device->busNumber == $vctrl_num) )
{
print "Returning Virtual SCSI Cntroller\n";
print "Device is ".$device." BEFORE RETURN\n";
return $device;
}
}
print "Returning UNDEF from find_scsi_controller_device\n";
return undef;
}
<my code snippet>
my $controller;
foreach my $vm_device (@$vm_devices)
{
print "$vm_device\n";
if ( (ref($vm_device) =~ /VirtualBusLogicController|VirtualLsiLogicController|VirtualLsiLogicSASController|ParaVirtualSCSIController/) && ($vm_device->busNumber == $vctrl_num) )
{
Util::trace(1, "SCSI controller found : $&\n");
$controller = $vm_device;
print "Controller FOUND!!!!!!!!\n";
last;
}
}
my $controllerKey = $controller->key;
# Set new unit number (7 cannot be used, and limit is 15)
my $unitNumber;
my $vm_vdisk_number = $#{$controller->device} + 1;
if ($vm_vdisk_number < 7) {
$unitNumber = $vm_vdisk_number;
}
elsif ($vm_vdisk_number == 15) {
die "ERR: one SCSI controller cannot have more than 15 virtual disks\n";
}
else {
$unitNumber = $vm_vdisk_number + 1;
}
<end code snippet>
Again, if the VM I am running this query against has a VirtualLsiLogicController configured at my specified busNumber, the device[] array is initialized, and the logic to pick the next free device id number works. If the scsi controller is one of the other 3 available types, the device[] array is not initialized and the code fails at the "my $vm_vdisk_number = $#{$controller->device} + 1;" line.
Any ideas?