VMware Cloud Community
AsharBado
Contributor
Contributor

Change existing controller scsi

Hello,

I want to unmount and/or mount a RDM disk on a VM plus to change the controller id position.

The script works well but i want to change the scsi position on the Controller (for exampl, change the controller id of an existing disk (0:1) to (1:0)) but i can't find the right command.

# Mount or Umount an RDM disk

$delrdmlist = @()
$addrdmlist = @()
$nom_vm_del = @()
$naaid_del = @()
$nom_vm_add = @()
$naaid_add = @()

$delrdmlist = Import-CSV "C:\Users\Ashar\Documents\RDM\del_vm_rdm_list.csv"
$addrdmlist = Import-CSV "C:\Users\Ashar\Documents\RDM\add_vm_rdm_list.csv"

function Remove_RDM {

foreach ($delrdm in $delrdmlist)
{
$nom_vm_del = $delrdm.name
$naaid_del = $delrdm.naaid

get-vm $nom_vm_del | Get-HardDisk -DiskType "RawVirtual" | Remove-HardDisk -Confirm:$false -DeletePermanently

Write-Host "The RDM $naaid_del unmouted on VM $nom_vm_del" -ForegroundColor Green
}
}

function Add_RDM {

foreach ($addrdm in $addrdmlist)
{
$nom_vm_add = $addrdm.name
$naaid_add = $addrdm.naaid

New-HardDisk -VM $nom_vm_add -DeviceName /vmfs/devices/disks/$naaid_add -DiskType RawVirtual -Persistence persistent -Confirm:$false

Write-Host "The RDM $naaid_add was mounted on VM $nom_vm_add" -ForegroundColor Green
}
}


Write-Host ""
Write-Host "====== vCenter : $vCenterConnected ======" -ForegroundColor Green
Write-Host ""
Write-Host "1 - Unmount RDM"
Write-Host "2 - Mount RDM"
Write-Host ""
Write-Host ""

$choice = Read-Host "Choose your selection "

do {

switch ($choice) {
'1'{

Remove_RDM
}
'2'{

Add_RDM
}
}
} until (($choice -eq '1') -or ($choice -eq '2')

 

Thank you for your help !

Ashar

0 Kudos
12 Replies
LucD
Leadership
Leadership

You will need to assign a new SCSI controller (New-ScsiController) to the VM, and then use the Controller parameter, with the newly created controller, on the New-Harddisk cmdlet.


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

0 Kudos
AsharBado
Contributor
Contributor

Hello Luc,

 

Thank you for your reply.

I want just to set an existing Controller, not to create a new Scsi Controller.

 

Best regards.

0 Kudos
AsharBado
Contributor
Contributor

My csv file is like this :

vmname,naaid,SCSIBUSNUMBER,UNITNUMBER
vmtest,naa.60060e800729270000302927000005da,0,4

0 Kudos
LucD
Leadership
Leadership

0 Kudos
AsharBado
Contributor
Contributor

Hello,

I dont' understand the last part of the script.

My wish is to have a script who can add a rdm disk and configure the controller+unitnumber.

 

Can you help me please?

 

0 Kudos
LucD
Leadership
Leadership

What don't you understand about that code?


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

0 Kudos
AsharBado
Contributor
Contributor

Hello Luc,

I don't understand this part of the script (sorry i am not an powercli expert) :

 

# Add the VMDK

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

 

    $device = New-Object VMware.Vim.VirtualDisk

    $device.Backing = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

    $device.Backing.Filename = $vmdk.datastorepath

    $device.UnitNumber = $vmdk.UNITNUMBER

    $device.Backing.DiskMode = 'persistent'

    $device.ControllerKey = $controller.ExtensionData.Key

    $device.Key = -10

 

    $devChange = New-Object VMware.Vim.VirtualDeviceConfigSpec

    $devChange[0].Device = $device

    $devChange[0].Operation = 'add'

 

    $spec.DeviceChange += $devChange

 

    $vm.ExtensionData.ReconfigVM($spec)

 

How can i adapt this this for my need?

 

 

0 Kudos
LucD
Leadership
Leadership

I'm not sure what exactly you want me to do.
The code is attaching a harddisk to a specific controller and with a specific unit number.
Since that functionality is not available through the cmdlet, the script uses the API method.

If you are not experienced with PowerCLI or the vSphere API I don't know how to explain the code to you.


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

0 Kudos
randylawrence42
Contributor
Contributor

First and foremost I want to really thank LucD for all of the amazing knowledge that you post on this forum.  I am simply amazed at how fast you return Answers on this blog and how you can articulate them so well.  I read it daily when I can and use it as my primary learning tool for powercli and powershell. 

As for this issue I totally understand the users frustrations.

Not having an easy way to map SCSI IDs to VMs with the New-HardDisk Command-let.

It makes it very hard to deploy solutions like Oracle RAC and Microsoft Failover Clusters.

This same issue forced me to learn PowerShell and PowerCli at a much deeper level.

I created a series of powershell functions just for this reason to fill this gap.

I give all of the programing logic credit to contributors like LucD as I understand the code but not at the level they do.

I was able to reverse engineer code from this site and others to create a series of powershell functions that allow me to Add VM HardDisks using SCSI IDs : VDN : VirtualDeviceNodes.

I used the PowerShell Methodologies learned from Industry Leaders like Jeff Hicks to make these functions. 

There is a series of them as they use the PowerShell Way of Each Function should do one specific Task.

I can share with the community. 

They have been tested in lab but come without any warranty.  I will do my best to help depending on free cycles.

I know they work.  They have been tested and used  for around 6 months now. 

I should have posted them sooner but got busy on some other IT Projects for other clients.

I wanted to finish some help files in the functions and post to github but never got around to it.

They key is they are gold and work !!!!

-RL

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Kudos
randylawrence42
Contributor
Contributor

Here is a list of function for RDMs I created.

 

<New-RdmDiskFp>
Creates New RDM Disk on Virtual Machine Using Full (VmdkFilePath) as Parameter Input
Requires following facts to be gathered manually 
(diskNAA#) = RDM Disk Serial Number , Canonical Name 
    : Get from Storage Team
(VmdkFilePath) = Full Path to VMDK File on DataStore : Example : '[DataStoreName] rl-centclone1/rl-centclone1_OraTable1_3x3.vmdk
    : VMDK File Name of Youre Choice : Must Supply 
    :  Note : Must Supply .vmdk  or command will fail
Uses VMware API Method with (ReconfigVM_Task) 
 
Parameters = -VMName , -VirtualDeviceNode,  -VmdkFilePath, -diskNAA, -MultiWriter
 
Example1  
New-RdmDiskFn -VMname ora1 -VirtualDeviceNode 1:12 -VmdkFilePath ‘ [OraRedo1] ora1/ora1_Redo1_1x12_b4c44.vmdk’ -diskNAA naa.68ccf09800966e574ff9f556ed5b4c44
 
Example2  (MW)
New-RdmDiskFn -VMname ora1 -VirtualDeviceNode 1:12  -VmdkFilePath ‘ [OraRedo1] ora1/ora1_Redo1_1x12_b4c44.vmdk’  -diskNAA naa.68ccf09800966e574ff9f556ed5b4c44 -MultiWriter
 
 
 
<New-RdmDiskFn>
Creates New RDM Disk Using (DataStore) and (FileName) as Parameter Input
Little easier to Input Parameters than Full VmdkFilePath
Automatically Stitches and Creates (VmdkFilePath) from (DataStore) and (FileName) Parameter Input
Requires following facts to be gathered manually
(diskNAA#) = RDM Disk Serial Number , Canonical Name 
    : Get from Storage Team 
(FileName) = VMDK FileName of youre Choice : Example : ora1_Redo1_1x12_b4c44
    : Note do not put .vmdk as it will cause duplicate extension
Uses VMware API Method with (ReconfigVM_Task) 
 
Parameters = -VMName , -VirtualDeviceNode, -DataStore , -FileName, -diskNAA -MultiWriter
 
Example1 
New-RdmDiskFn -VMname ora1 -VirtualDeviceNode 1:12 -DataStore OraRedo1 -FileName ora1_Redo1_1x12_b4c44 -diskNAA naa.68ccf09800966e574ff9f556ed5b4c44
 
Example2 (MW)
New-RdmDiskFn -VMname ora1 -VirtualDeviceNode 1:12 -DataStore OraRedo1 -FileName ora1_Redo1_1x12_b4c44 -diskNAA naa.68ccf09800966e574ff9f556ed5b4c44 -MultiWriter
 
 
 
<Mount-RdmDiskFp>
Mounts RDM HardDisks Using Full (VmdkFilePath) as Parameter Input
Used to Mount RDM (MW) Disks to Secondary Nodes
Requires (VDN) (VmkFilePath) and (DiskNAA) Number 
Manually Use (Get-OraDiskInfo) Function to gather these facts from Primary Node
Uses VMware API Method with (ReconfigVM_Task) 
 
Parameters = -VMName , -VirtualDeviceNode, -VmdkFilePath, -diskNAA,  -MultiWriter
 
Example1
Mount-RdmDiskFp -VMname rl-centClone2 -VirtualDeviceNode 1:12 -VmdkFilePath '[Sempra-OraRedo1] rl-centClone1/rl-centClone1_OraRedo1_1x12_b4c44.vmdk' -diskNAA naa.68ccf09800966e574ff9f556ed5b4c44 -MultiWriter
 
Example2
Mount-RdmDiskFp -VMname rl-centClone2 -VirtualDeviceNode 1:12 -VmdkFilePath '[Sempra-OraRedo1] rl-centClone1/rl-centClone1_OraRedo1_1x12_b4c44.vmdk' -diskNAA naa.68ccf09800966e574ff9f556ed5b4c44 -MultiWriter
 
 
<DisMount-RdmDiskVdn>
** Uses (Get-OraDiskInfo) Function to gather facts
Unmounts RDM HardDisks using (VDN) as Parameter Input
Leaves VMDK Files In Place on DataStore 
Typically Used to Unmount Shared (MW) Disks on Secondary Nodes 
RDM (MW) HardDisks are Shared and accessed by Primary Node so can not be deleted by Secondary Nodes
Uses (remove-harddisk) Command Under the Covers
 
Parameters = -VMName , -VirtualDeviceNode
 
Example1
DisMount-MwDiskVdn -VMname rl-centClone2 -VirtualDeviceNode 1:22
 
 
 
<Remove-RdmDiskVdn>
** Uses (Get-OraDiskInfo) Function to gather facts
Deletes (RDM) HardDisks using (VDN) as Input Identifier
Deletes VMDK File from DataStore 
** Note This is just pointer file so Array LUN is still Valid.  No Data Loss on Array Lun
Uses (remove-harddisk) Command with -DeletePermanently Flag
 
Parameters = -VMName, VirtualDeviceNode
 
Example1
Remove-RdmDiskVdn -VMname rl-centClone1 -VirtualDeviceNode 1:12
 
 
 
<Remove-RdmApiVdn>
** Uses (Get-OraDiskInfo) Function to gather facts
Does Same Thing as <DisMount-RdmDiskVdn> but uses API instead of (remove-harddisk)
Unmounts RDM HardDisks using (VDN) as Input Identifier
Leaves VMDK Files In Place on DataStore 
Typically Used to Unmount Shared (MW) Disks on Secondary Nodes
Uses VMware API Method with (ReconfigVM_Task) 
 
Parameters = -VMName, VirtualDeviceNode
 
Example1
Remove-RdmDiskVdn -VMname rl-centClone1 -VirtualDeviceNode 1:12
0 Kudos
randylawrence42
Contributor
Contributor

Most of the function rely on another function to gather facts and feed to Disk Functions.

This function I created is called (Get-OraDiskInfo)

It is like gold in oracle RAC Environments when you need to correlate UUIDs and NAAIDs to vdisk  :VDNs.  Virtual Device Nodes : Scsi IDs.

I have this one in a separate module that I Load.  

I will start off by posting this Glue function (Get-OraDiskInfo) and the RDM Functions.

You can play around with them for starters.

Once you get used to the basic AdHoc RDM Function Usage I will upload another wrapper function that uses CSV Input to map out RDMs to VM Nodes.

 

 

 

 

 

0 Kudos
randylawrence42
Contributor
Contributor

I added the RDM Functions to zip file and attached.

Just unzip and load the ps1 file in ISE.

Then Start Playing Around in a test environment. 

I will try to post some Playbooks with examples if people are interested.

It is a .ps1 file with all of the RDM Functions and the Wrapper Function (Get-OraDiskInfo).

Make sure you Load both Get-OraDiskInfo Function into memory when using Functions that Rely on it.

I would suggest creating a powershell module to load all at once or just load all of the function in ISE Session.

I typically run from ISE in more of an administrator AD Hoc Mode.  But will use VSCODE When necessary.

-RL

0 Kudos