VMware Cloud Community
saitoz
Contributor
Contributor

2 shared disk on 4 vms and 2 vcenter ?

Hello there,

say that 2 vms on vcenter1 (center) and 2 vms on vcenter2 (recovery). these four nodes see the same 2 LUNs.

2 shared disks were added to 2 vms in the center1. the script I used is below;

Connect-VIServer -Server vcenter1 -User USER -Password PASSWORD

New-VIProperty -Name lunID -ObjectType ScsiLun -Value {
  param($lun)
  [int](Select-String ":L(?<lunID>\d+)$" `
    -InputObject $lun.RuntimeName).Matches[0].Groups['lunID'].Value
} -Force | Out-Null

$esxName = "vmserver01"
$luns = Get-VMHost -Name $esxName | Get-ScsiLun -LunType disk
$lun1 = $luns | where {$_.LunID -eq 100} # disk with LunID 100 will be added
$lun1 = $luns | where {$_.LunID -eq 101} # disk with LunID 101 will be added

$DeviceName1=$lun1.ConsoleDeviceName
$DeviceName2=$lun2.ConsoleDeviceName
$vm1 = Get-VM -Name "vm_in_the_center_01"
$vm2 = Get-VM -Name "vm_in_the_center_02"
$hd1 = New-HardDisk -VM $vm1 -DeviceName $DeviceName1 -DiskType RawVirtual
$ctrl1 = New-ScsiController -HardDisk $hd1 -BusSharingMode Physical -Type VirtualLsiLogicSAS

#add disk with LunID 100, create new scsi controller

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].device += $ctrl1.ExtensionData
$spec.deviceChange[0].device.Key = -101
$spec.deviceChange[0].operation = "add"
$spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[1].device += $hd1.ExtensionData
$spec.deviceChange[1].device.Key = -102
$spec.deviceChange[1].device.ControllerKey = -101
$spec.deviceChange[1].operation = "add"
$vm2.ExtensionData.ReconfigVM($spec)

#add disk with LunID 101, use the scsi controller that is already creared above

$hd2 = New-HardDisk -VM $vm1 -DeviceName $DeviceName2 -DiskType RawVirtual -controller $ctrl1
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].device += $ctrl1.ExtensionData
$spec.deviceChange[0].device.Key = -101
$spec.deviceChange[0].operation = "add"
$spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[1].device += $hd2.ExtensionData
$spec.deviceChange[1].device.Key = -102
$spec.deviceChange[1].device.ControllerKey = -101
$spec.deviceChange[1].operation = "add"
$vm2.ExtensionData.ReconfigVM($spec)

this works perfectly on the center site. now the question is; how to add same disks to vm_in_the_recovery_01 and vm_in_the_recovery_02 on vcenter2 (recovery site) ? these two Luns are exported to both site from storage, and I can see the vmdk files for shared disks (added above) at recovery site. sorry for it's not a short question.

Thank you.

0 Kudos
6 Replies
saitoz
Contributor
Contributor

Hello LUC,

if I add following lines to the script, it works ?

$Hd1Filename=$hd1.Filename #get file path [datastoreAAA] xxxx/xxxx.vmdk
$Hd2Filename=$hd2.Filename

Connect-VIServer -Server vcenter2 -User USER -Password PASSWORD

esxName = "vmserver06" #host from recovery site


$vm1 = Get-VM -Name "vm_in_the_recovery_01"
$vm2 = Get-VM -Name "vm_in_the_recovery_02"
$hd1 = New-HardDisk -VM $vm1 -DiskPath $Hd1Filename
$ctrl1 = New-ScsiController -HardDisk $hd1 -BusSharingMode Physical -Type VirtualLsiLogicSAS

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].device += $ctrl1.ExtensionData
$spec.deviceChange[0].device.Key = -101
$spec.deviceChange[0].operation = "add"
$spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[1].device += $hd1.ExtensionData
$spec.deviceChange[1].device.Key = -102
$spec.deviceChange[1].device.ControllerKey = -101
$spec.deviceChange[1].operation = "add"
$vm2.ExtensionData.ReconfigVM($spec)

and same for disk 2. ?

0 Kudos
LucD
Leadership
Leadership

That should work as far as I can see.

Sharing LUNs is done between ESXi servers, and the vCenters have nothing to do with this afaik.

The only concern I would have is about the mapping file (.VMDK). Is that visible in both environments ?


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

saitoz
Contributor
Contributor

Thank you for your response.

yes mapping file (VMDK) is visible in both environments. when I try to add existing disk with script or manually it gives following error:

Incompatible device backing specified for device '0'.

with script, I get same:

New-HardDisk : 17.04.2013 09:34:33    New-HardDisk        Incompatible device backing specified for device '0'.   
At C:\XXX.ps1:61 char:20
+ $hd1 = New-HardDisk <<<<  -VM $vm1 -DiskPath $Hd1Filename
    + CategoryInfo          : NotSpecified: (:) [New-HardDisk], InvalidDeviceBacking
    + FullyQualifiedErrorId : Client20_VirtualDeviceServiceImpl_AttachHardDisk_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk

0 Kudos
LucD
Leadership
Leadership

Have a look in the vpxd logs, perhaps there is more information there on why the method call fails.


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

0 Kudos
saitoz
Contributor
Contributor

I found the problem and solved. the reason of the error is that it's wrong to add shared disk to the nodes at recovery side by using "diskpath".

in recovery site, in first node I have added disk as a new RDM (like I added at first node in center site) by using LunIDs at recovery site. then I have added the shared disk (from first node) to second node . I changed the script as needed.

Thank you very much.

0 Kudos
LucD
Leadership
Leadership

Good to know. Thanks for letting us know.


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

0 Kudos