Hey,
I'm looking for a way to automatically rescan all my HBAs and add the new found LUNS into the storage of the ESX, id like this to be done throw the VC and not from the ESX, so i would be able to see the storage in the VC.
Is this the place? Does anyone have any idea?
Hello David,
Try the attached script. It won't format a new LUN to VMFS-3, but it will do a rescan on all hosts in your farm on all hba-adapters.
Regards
Stefan
Thanks!
Sound like what I've been looking for.
I'm not familiar with VC scripting, how should I run this script?
Regards
David
Download and install ViPerl Toolkit and do a reboot
Edit the script and put some values in for $service_url (="https://VC-servername/sdk"), $username and $password.
Run the script:
perl hbarescan.pl
Stefan
After you run stefan's script, you can discover the new LUNs on your system. Now if you want to
create VMFS on them
foreach host in hosts:
// This will return all the Disks available for creating VMFS storage
HostScsiDisk[] HostScsiDisks = queryAvailableDisksForVmfs(configMgr.getDatastoreSystem(),null);
if(HostScsiDisks.length == 0):
Error("No Disks Available for Creating Disks")
continue;
foreach HostScsiDiskCount in HostScsiDisks:
// Now create the Partition
VmfsDatastoreCreateSpec vmfsCreateSpec = new VmfsDatastoreCreateSpec();
// Set the Partition
HostScsiDiskPartition hsdp = new HostScsiDiskPartition()[];
hsdp.setDiskName(HostScsiDisks[HostScsiDiskCount].getCanonicalName());
hsdp.setPartition(1);
HostDiskPartitionSpec HDPS = new HostDiskPartitionSpec();
HostDiskPartitionAttributes[] HDPA = new HostDiskPartitionAttributes[1];
HDPA[0] = new HostDiskPartitionAttributes();
HDPA[0].setLogical(false);
HDPA[0].setPartition(1);
HDPA[0].setType(HostDiskPartitionInfoType.vmfs.toString());
long blocks = HostScsiDisks[HostScsiDiskCount].getCapacity().getBlock()
HostScsiDisks[HostScsiDiskCount].getCapacity().getBlockSize() / (1024 * 1024);
HDPA[0].setStartSector(1);
HDPA[0].setEndSector(hdpi[0].getSpec().getTotalSectors().longValue() - 512);
HDPS.setPartition(HDPA);
vmfsCreateSpec.setPartition(HDPS);
HostVmfsSpec spec = new HostVmfsSpec();
spec.setExtent(hsdp);
spec.setvolumeName("UniqueVMFSName");
sdk.CreateVmfsDatastore(HostDatastoreSystem,vmfsCreateSpec);
HostDiskPartitionInfo[] hdpi =
service.retrieveDiskPartitionInfo(storageSystemMor,
new String[] {HostScsiDisks[i].getDevicePath()});
This is the Disk Partition Info. Initially do a query using the call queryAvailableDisksForVmfs() and this return you all the disks available. Store it in HostScsiDisks[]. Now depending on which disk you want, get the partition information on that disk.
Thank you. The script is very helpful than scanning 8 hosts manually.
How can I modify the pearl script run against hosts in a particular cluster and not all hosts? Thanks.
This has been a challege for me as well considering the large dynamic environment I manage. I have figured this one out.
I use the VI Toolkit 1.5 and do it with a single line of code.
get-cluster CLUSTERNAME |get-VMHost |get-VMHostStorage -RescanAllHba
and/or
get-cluster CLUSTERNAME |get-VMHost |get-VMHostStorage -RescanVmfs (if needed)
With many VMs having many RDMS presented from our SAN team, scripting this out sure beats clickign in the VI client.
With some customization, you can have this email you the status once complete.