VMware Cloud Community
gmitch64
Enthusiast
Enthusiast

Issue with New-ScsiController and New-HardDisk

This one has been annoying me for a bit. It was an issue in PowerCLI 6.3, and it still an issue after upgrading to PowerCLI 6.5 We're still running on ESXi 5.5 (2718055).

When you use New-VM and add a single disk, SCSI Controller 0 gets created, and the disk is assigned to LUN 0.

If I then do a New-HardDisk | New-ScsiController then the first disk on the Controller is assigned to LUN 1. The next time I call it for the same controller, the disk is assigned to LUN 0, and the next time it's assigned to LUN 2, 3, 4 etc (which makes sense).

I think there's a couple of issues here. Firstly, there seems to be a bug with New-ScsiController in adding the first disk to LUN 1 (its behaviour after that seems reasonable). Secondly, when adding new disks via New-HardDisk (and New-ScsiController) should allow me to specify which LUN I want to use. It shouldn't make me add to the next available LUN, then rely on me to go back in and mess around with VMware.Vim.VirtualDeviceConfigSpec and ExtensionData to change it.

Has anyone else come across the same issue? Is there any cleaner way to put the disk at the LUN I want, or is ExtensionData the best there is at the moment.

Graham

(Sorry for not posting in here first Alan - I didn't have my Weetabix this morning).

$DefaultDatastore = "zzShunt-C1"

$DefaultCluster = "Test Cluster"

$DefaultResourcePool = "Live Pool"

$DefaultFolder = "Build Servers"

$DefaultHost = "vmserver80.ceicmhb"

$vm = "test-gwm-002v"

$DiskSize = 10

$Datastore = $DefaultDatastore

$myTargetVMHost = Get-VMHost -Name $DefaultHost

New-VM -Name $vm -ResourcePool $myTargetVMHost -Datastore $DefaultDatastore -NumCPU 2 -MemoryGB 4 -DiskGB 40 -NetworkName "dvVMGuestAreaB" -Floppy -CD -DiskStorageFormat Thin -GuestID winNetDatacenterGuest -Version v8

$NewHD = New-HardDisk -VM $vm -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore

$NewSCSI = New-ScsiController -HardDisk $NewHD -Type ParaVirtual -BusSharingMode NoSharing -Confirm:$false

$NewHD = New-HardDisk -VM $vm -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore

$NewSCSI = New-ScsiController -HardDisk $NewHD -Type ParaVirtual -BusSharingMode NoSharing -Confirm:$false

$NewHD = New-HardDisk -VM $vm -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore

$NewSCSI = New-ScsiController -HardDisk $NewHD -Type ParaVirtual -BusSharingMode NoSharing -Confirm:$false

At this point disk 0 is LUN 0 on controller 0, all the other disks are LUN 1 on their respective controllers.

$ScsiController0 = get-vm $vm | Get-ScsiController | where name -EQ "SCSI controller 0"

$ScsiController1 = get-vm $vm | Get-ScsiController | where name -EQ "SCSI controller 1"

$ScsiController2 = get-vm $vm | Get-ScsiController | where name -EQ "SCSI controller 2"

$ScsiController3 = get-vm $vm | Get-ScsiController | where name -EQ "SCSI controller 3"

$fred = (get-vm $vm | New-HardDisk -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore -Controller $ScsiController0)

$fred = (get-vm $vm | New-HardDisk -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore -Controller $ScsiController1)

$fred = (get-vm $vm | New-HardDisk -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore -Controller $ScsiController2)

$fred = (get-vm $vm | New-HardDisk -DiskType flat -StorageFormat "Thin" -Persistence Persistent -CapacityGB $DiskSize -Datastore $Datastore -Controller $ScsiController3)

Now, the new disk on controller 0 is LUN 1, the new disk on all the other controllers is LUN 0.

Repeat the last 4 lines again, and all the new disks presented are on LUN 2 on the controllers.

0 Kudos
4 Replies
LucD
Leadership
Leadership

Yup, got the same.
One for Alan's (or Jason's) black book :smileygrin:

The only way around it, that I know of, is to use the API.
There are a couple of posts floating around in here (let me know if you find them).


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
gmitch64
Enthusiast
Enthusiast

Thanks for the confirmation Luc. I'll poke Mr Alan Smiley Happy

Graham

0 Kudos
gmitch64
Enthusiast
Enthusiast

> There are a couple of posts floating around in here (let me know if you find them).

I probably stole this code from you Smiley Happy

$hd = $vm | Get-HardDisk | select -Last 1

  $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

  $spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (1)

  $spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec

  $spec.deviceChange[0].operation = "edit"

  $spec.deviceChange[0].device = $hd.ExtensionData

  $spec.deviceChange[0].device.unitNumber = $SCSIID

  $vm.ExtensionData.ReconfigVM_Task($spec)

That

     select -Last 1

really annoys me for some reason. I always worry that there's going to be a change in the API, and the order the disks are returned in is going to change somehow. There really needs to be a -LUN option so we can straight off specify which LUN we want when we do a New-HardDisk.

Graham.

0 Kudos
LucD
Leadership
Leadership

I normally get my targeted hard disk on the Label ("Hard Disk x").

And yes, a LUNid parameter would be handy.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos