Hello community...we're doing a really fun virtual SQL cluster project, running on ESXi 5.0. Without getting too much into the design detail, I'm looking to try to script adding a whole slew (45ish) of RDMs to a VM. The RDMs have been presented to the hosts, so the next step is to add the appropriate RDMs to the VM in the proper order. Here's a partial list of the available RDMs:
Based on our design, I know that LUN 46 needs to go in to SCSI 1:1, LUN 47 needs to go to SCSI 2:1, LUN 48 needs to go to SCSI 3:1, and so on. I have a spreadsheet that has a correlation between LUN ID and SCSI ID needed. I can also manually add 1:0, 2:0, 3:0 to get the controllers created. What I'd like to do is script out the rest.
I've seen a number of scripts and I'm not seeing quite what I need. For starters, how do I specify LUN ID? From there the questions keep coming. Any suggestions/ideas? Thanks!
The error is because there were 2 controllers returned (the same one twice).
Could it be that you have 2 vSphere connections open ? Do a
$global:defaultviservers
If there is more than 1 entry displayed, you should check if you are running in multi-mode. Do a
Get-PowerCLIConfiguration
Does 1 of the scopes say "multiple" ?
If yes, disconnect 1 of the vSphere connections. For example by doing
Disconnect-ViServer -Server $global:defaultviservers[0] -Confirm:$false
Then check if Get-ScsiController only returns 1 object.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is one way of finding the LUN Id.
Get-VMHost MyEsx | Get-ScsiLun -LunType disk |
Select CanonicalName,@{N="LUN ID";E={
(Select-String -Pattern ":L(?<lunid>\d+)$" -InputObject $_.RuntimeName |
Select -ExpandProperty Matches).Groups["lunid"].Value}}
You will need to create the SCSI controllers in order, you can't specify a controller ID afaik.
Each call to New-ScsiController will create a new one with the next sequential ID number.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD, I think I'm getting pretty close. I actually used your script from the other thread to get a list of all LUNs on all hosts, and I was able to filter out this specific cluster to get a list of all of the LUN IDs and Canonical names in the order I need. Next step is to use this info to add the RDMs to the VM.
We have what I think is a pretty unique setup here. 14 SQL instances per VM, all data drives on one controller, Logs on another, TempDB on the 3rd. So in adding the disks we need to add them in order. What I'm looking to do is create SCSI ID 1:0 (2:0 and 3:0) manually, then script out adding 1:1 through 1:15 etc. So 1:0 is added, and controller set to physical mode. If I run:
get-vm MyVM | get-scsicontroller I get this (sorry for the spacing):
Type BusSharingMode UnitNumber
---- -------------- ----------
VirtualLsiLogicSAS NoSharing 3
VirtualLsiLogicSAS Physical 4
VirtualLsiLogicSAS NoSharing 3
VirtualLsiLogicSAS Physical 4
Next, I run this short script for testing:
$devicename = "/vmfs/devices/disks/naa.60060160b01231001ca9bf91bec4e211"
$vm = "MyVM"
New-HardDisk -VM $vm -DeviceName $devicename -DiskType RawVirtual
This creates one disk at SCSI 0:1, then gives a "Invalid configuration for device '0'" error. I assume this is because there are two SCSI controllers listed above for UnitNumber 4 (even though there's only one on the VM itself).
That brings us to this: how do I add this RDM to SCSI 1:1? It seems that the -Controller switch in new-harddisk will not work with RDMs?
You will have to use the Controller parameter on the New-HardDisk cmdlet.
Get the desired controller through the Get-ScsiController, and then use the controller object to pass to the New-HardDisk cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK, so I created the disk for SCSI 1:0 which created SCSI controller 1, and I set it to physical mode.
Now I'm trying this:
$scsi1 = get-scsicontroller -VM $vm | ?{$_.Name -eq "SCSI controller 1"}
The output of $scs1 is:
Type BusSharingMode UnitNumber
---- -------------- ----------
VirtualLsiLogicSAS Physical 4
VirtualLsiLogicSAS Physical 4
I don't know why there's 2 listed, the VM only has one.
Now when I run this:
new-harddisk -VM $vm -devicename $devicename -disktype rawvirtual -controller $scsi1
I immediately get:
New-HardDisk : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomati
on.ViCore.Types.V1.VirtualDevice.ScsiController' required by parameter 'Control
ler'. Specified method is not supported.
At line:1 char:78
+ new-harddisk -VM $vm -devicename $devicename -disktype rawvirtual -controller
<<<< $scsi1
+ CategoryInfo : InvalidArgument: (:) [New-HardDisk], ParameterBi
ndingException
+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCor
e.Cmdlets.Commands.VirtualDevice.NewHardDisk
From what I'm seeing this *should* work, but something isn't working right. Any ideas?
The error is because there were 2 controllers returned (the same one twice).
Could it be that you have 2 vSphere connections open ? Do a
$global:defaultviservers
If there is more than 1 entry displayed, you should check if you are running in multi-mode. Do a
Get-PowerCLIConfiguration
Does 1 of the scopes say "multiple" ?
If yes, disconnect 1 of the vSphere connections. For example by doing
Disconnect-ViServer -Server $global:defaultviservers[0] -Confirm:$false
Then check if Get-ScsiController only returns 1 object.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yep that's exactly what it was. I had a a connection to vcenter and directly to a host. Once I disconnected the host it worked perfectly. Next step is to get the CSV file put together and get the rest of the script done. Thanks for all the help!