VMware {code} Community
David_Ank
Enthusiast
Enthusiast
Jump to solution

VC Script- rescan HBA and add Storage

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?

Regards, David
Reply
0 Kudos
1 Solution

Accepted Solutions
StefanPahrmann
Jump to solution

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

View solution in original post

Reply
0 Kudos
9 Replies
StefanPahrmann
Jump to solution

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

Reply
0 Kudos
David_Ank
Enthusiast
Enthusiast
Jump to solution

Thanks!

Sound like what I've been looking for.

I'm not familiar with VC scripting, how should I run this script?

Regards

David

Regards, David
Reply
0 Kudos
StefanPahrmann
Jump to solution

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

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

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);

Reply
0 Kudos
Nigel_Stuart
Contributor
Contributor
Jump to solution

Hi cspnanda,

Thanks for posting this! One question. What is the 'hdpi' variable? I don't see it being initialized anywhere.

HDPA[0].setEndSector(hdpi.getSpec().getTotalSectors().longValue() - 512);

Thanks,

- Nigel

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

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.

Reply
0 Kudos
Supal2009
Contributor
Contributor
Jump to solution

Thank you. The script is very helpful than scanning 8 hosts manually.

Reply
0 Kudos
Supal2009
Contributor
Contributor
Jump to solution

How can I modify the pearl script run against hosts in a particular cluster and not all hosts? Thanks.

Reply
0 Kudos
T3Steve
Enthusiast
Enthusiast
Jump to solution

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.

VCP3|VCP4|VSP|VTSP
Reply
0 Kudos