VMware Cloud Community
cgrvy
Enthusiast
Enthusiast
Jump to solution

Add all Presented Datastores to Host, register VM's

Hi,

I'm sure this has been carried out already - maybe someone has a script handy that they could share?

I have some snapshotted volumes presented to an ESXi host, I want a script that will automatically name these and add them to the host. It could be one volume - it could be ten. I have figured out the mapping from the storage unit to the host OK, but I'm having trouble on the VMware side.There is a chance that these datastores could be seen by the original host - so I will need to resignature them.

Once the datastores are mounted, I want to find two machines in the datastores and register them in vCenter.

Anyone have anything they can share?

Many Thanks!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Are you getting any error messages ?

Is it not working ?

Sometimes there valuable clues to be found in the vpxd logs.


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

View solution in original post

0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

I assume you are looking for a procedure as outlined in KB1011387 ?

The suggested esxcli commands can easily be done through the Get-EsxCli cmdlet.


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

0 Kudos
cgrvy
Enthusiast
Enthusiast
Jump to solution

Yeah, that looks about right. From the KB:


This is a script I've found in the communities that I'm trying to use - but I think its my connection that is wrong.

Re: mount / map eines existierenden VMFS Datastore

#Get Host Root user password

$HostPassword = Get-Credential -Credential root

#Connect to host

Connect-VIServer -Server xx.xx.xx.xx -Credential $HostPassword


#Rescan HBAs

Get-VMHost | Get-VMHostStorage -RescanAllHba

New-VIProperty -Name lunID -ObjectType Get-ScsiLun -Value { 

      param($lun) 

      [int](Select-String ":L(?<lunID>\d+)$" -InputObject $lun.RuntimeName).Matches[0].Groups['lunID'].Value 

    } -Force | Out-Null 

 

$LunIDfind = Get-VMHost -Name $VMHost | Get-ScsiLun | `Select CanonicalName, lunID, RuntimeName | where {$_.lunID -eq "$LunID"} 

$scsiCname = $LunIDfind.CanonicalName 

#Create list of unresolved scsi devices 

$hostView = get-vmhost -name $VMHost | get-view 

$dsView = get-view $hostView.ConfigManager.DatastoreSystem 

$unBound = $dsView.QueryUnresolvedVmfsVolumes() 

 

#Loop through the unresolved SCSI devices and newly to be signed scsi devices determine ( canonicalName )

foreach ($ub in $UnBound) { 

$extPaths = @() 

$Extents = $ub.Extent; 

foreach ($ex in $Extents) { 

$extPaths = $extPaths + $ex.DevicePath 

 

#Only unresolved SCSI device re-sign whose LunID communicates to canonicalName

IF ($extPaths -match $scsiCname){ 

$res = New-Object VMware.Vim.HostUnresolvedVmfsResignatureSpec 

$res.ExtentDevicePath = $extPaths 

$dsView.ResignatureUnresolvedVmfsVolume($res) 

 

# Read VMFS Label of before re-signing and write for further processing in variable 

$VmfsLabelFind = $unBound | select VmfsLabel 

$VmfsLabel = $VmfsLabelFind.vmfslabel 

Write-Host $VmfsLabel

 

#Find new DataStore and rename 

$NewDatastore = Get-Datastore -VmHost $VMHost | Where{ $_.Name -like "snap-*$VmfsLabel" } 

Set-Datastore $NewDatastore -Name "snap-$VmfsLabel"

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you getting any error messages ?

Is it not working ?

Sometimes there valuable clues to be found in the vpxd logs.


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

0 Kudos
cgrvy
Enthusiast
Enthusiast
Jump to solution

I've fixed a few issues that I have in the script, but I'm having trouble with this line:

#Find new DataStore and rename 

$NewDatastore = Get-Datastore -VmHost $VMHost | Where{ $_.Name -like "snap-*$VmfsLabel" }

write-host "NEW DATASTORE: " $NewDatastore

Set-Datastore $NewDatastore -Name "snap-$VmfsLabel"

When I run it I get an error against the last line above.

"Set-Datastore : Cannot validate argument on parameter 'Datastore'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command

again."

So I tried outputting some of the values I got earlier in the script - the $unbounc value returns nothing. This is the line for it:

$unBound = $dsView.QueryUnresolvedVmfsVolume()

Thanks!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That seems to indicate that the LUN, with the VMFS datastore on them, are not visisble in that specific host.

Are you doing a Rescan before ?

Does that complete without error ?

Can you see those unbound LUNs in the Web Client ?


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

0 Kudos
cgrvy
Enthusiast
Enthusiast
Jump to solution

Yes, running a rescan without issue - and I can see the LUN's when I attempt to manually add storage after the script fails.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are there any entries in the vpxd log when you call the QueryUnresolvedVmfsVolume method ?


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

0 Kudos
cgrvy
Enthusiast
Enthusiast
Jump to solution

I'm running this command directly on the host - not via vCenter - still look in vpxd log?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, check /var/log/vmkernel.log


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

0 Kudos
cgrvy
Enthusiast
Enthusiast
Jump to solution

This is what I'm seeing:

2016-02-23T11:12:40.013Z cpu10:233018)World: 14302: VC opID hostd-2093 maps to vmkernel opID 94f1cff9

2016-02-23T11:12:59.890Z cpu0:233529 opID=f20bd4f)World: 14302: VC opID hostd-f4e8 maps to vmkernel opID f20bd4f

2016-02-23T11:12:59.930Z cpu5:33010 opID=f20bd4f)ScsiScan: 976: Path 'vmhba2:C0:T0:L1': Vendor: 'PURE    '  Model: 'FlashArray      '  Rev: '455 '

2016-02-23T11:12:59.930Z cpu5:33010 opID=f20bd4f)ScsiScan: 979: Path 'vmhba2:C0:T0:L1': Type: 0x0, ANSI rev: 6, TPGS: 1 (implicit only)

2016-02-23T11:12:59.930Z cpu5:33010 opID=f20bd4f)ScsiScan: 1503: Add path: vmhba2:C0:T0:L1

2016-02-23T11:12:59.931Z cpu0:233529 opID=f20bd4f)ScsiPath: 4695: Plugin 'NMP' claimed path 'vmhba2:C0:T0:L1'

2016-02-23T11:12:59.931Z cpu0:233529 opID=f20bd4f)vmw_psp_mru: psp_mruSelectPathToActivateInt:346: Changing active path from NONE to vmhba2:C0:T0:L1 for device "Unregistered Device".

2016-02-23T11:12:59.931Z cpu0:233529 opID=f20bd4f)StorageApdHandler: 698: APD Handle  Created with lock[StorageApd0x410923]

2016-02-23T11:12:59.931Z cpu0:233529 opID=f20bd4f)ScsiEvents: 501: Event Subsystem: Device Events, Created!

2016-02-23T11:12:59.932Z cpu0:233529 opID=f20bd4f)VMWARE SCSI Id: Id for vmhba2:C0:T0:L1

0x62 0x4a 0x93 0x70 0xd1 0xd1 0x50 0x3c 0x7d 0x57 0xdd 0xd2 0x00 0x01 0xc8 0xa7 0x46 0x6c 0x61 0x73 0x68 0x41

2016-02-23T11:12:59.932Z cpu0:233529 opID=f20bd4f)ScsiDeviceIO: 7456: Get VPD 86 Inquiry for device "naa.624a9370d1d1503c7d57ddd20001c8a7" from Plugin "NMP" failed. Not supported

2016-02-23T11:12:59.932Z cpu0:233529 opID=f20bd4f)ScsiDeviceIO: 6187: QErr is correctly set to 0x0 for device naa.624a9370d1d1503c7d57ddd20001c8a7.

2016-02-23T11:12:59.932Z cpu0:233529 opID=f20bd4f)ScsiDeviceIO: 6684: Could not detect setting of sitpua for device naa.624a9370d1d1503c7d57ddd20001c8a7. Error Not supported.

2016-02-23T11:12:59.933Z cpu0:233529 opID=f20bd4f)ScsiDevice: 3443: Successfully registered device "naa.624a9370d1d1503c7d57ddd20001c8a7" from plugin "NMP" of type 0

2016-02-23T11:12:59.949Z cpu23:33006 opID=f20bd4f)ScsiScan: 976: Path 'vmhba5:C0:T0:L1': Vendor: 'PURE    '  Model: 'FlashArray      '  Rev: '455 '

2016-02-23T11:12:59.949Z cpu23:33006 opID=f20bd4f)ScsiScan: 979: Path 'vmhba5:C0:T0:L1': Type: 0x0, ANSI rev: 6, TPGS: 1 (implicit only)

2016-02-23T11:12:59.949Z cpu23:33006 opID=f20bd4f)ScsiScan: 1503: Add path: vmhba5:C0:T0:L1

2016-02-23T11:12:59.950Z cpu0:233529 opID=f20bd4f)ScsiPath: 4695: Plugin 'NMP' claimed path 'vmhba5:C0:T0:L1'

2016-02-23T11:12:59.952Z cpu8:33494)usb-storage: detected SCSI revision number 4 on vmhba32

2016-02-23T11:12:59.952Z cpu8:33494)usb-storage: patching inquiry data to change SCSI revision number from 4 to 2 on vmhba32

2016-02-23T11:12:59.952Z cpu0:33010 opID=f20bd4f)ScsiUid: 273: Path 'vmhba32:C0:T0:L0' does not support VPD Device Id page.

2016-02-23T11:12:59.952Z cpu0:33010 opID=f20bd4f)VMWARE SCSI Id: Could not get disk id for vmhba32:C0:T0:L0

2016-02-23T11:13:00.058Z cpu2:233017)World: 14302: VC opID hostd-ef9c maps to vmkernel opID 9af89c86

2016-02-23T11:13:20.015Z cpu12:34118)World: 14302: VC opID hostd-87d2 maps to vmkernel opID 6fc78cbe

Any thoughts?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The LUN seems to be detected ok.

I know that when you use for example EMC PowerPath you also can face some issues with the QueryUnresolvedVmfsVolume method.

Perhaps you should contact your storage provider, looks like you are using Pure Storage, and ask if they have any guidelines on the use of that method.


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

0 Kudos
cgrvy
Enthusiast
Enthusiast
Jump to solution

Got it...

The snapshot wasn't formatted on the primary SAN - once I completed that it worked out fine.

Thanks for your help!

0 Kudos