VMware Cloud Community
Atomtom
Contributor
Contributor
Jump to solution

ReconfigVM_Task failing - Adding existing RDMs / LUNs

Morning All,

As part of a migration process to move VMs to updated clusters I need to remove the RAW SAN LUNs from the VM before migrating the VM. Once migration is complete, we need to replace the RDMs exactly as they were before migration. I have a working script that utilises the New-Harddisk commands but this is not flexible enough and we are not able to position the disks on the same SCSI ports without manual intervention.

So I've written a new script (many thanks to LucD for inspiration!). However I cannot get i to work. The script runs multiple functions, one to record the details, one to remove the LUNs and one to add them back in. I am able to remove the disks with no issues. But replacing fails. This is the error:

Exception calling "ReconfigVM_Task" with "1" argument(s): "

Error processing attribute "type" with value "RDM"

while parsing MoRef for ManagedObject of type vim.Datastore

at line 1, column 477

while parsing property "datastore" of static type Datastore

while parsing serialized DataObject of type vim.vm.device.VirtualDisk.RawDiskMappingVer1BackingInfo

at line 1, column 341

while parsing property "backing" of static type VirtualDeviceBackingInfo

while parsing serialized DataObject of type vim.vm.device.VirtualDisk

at line 1, column 298

while parsing property "device" of static type VirtualDevice

while parsing serialized DataObject of type vim.vm.device.VirtualDeviceSpec

at line 1, column 258

while parsing property "deviceChange" of static type ArrayOfVirtualDeviceConfigSpec

while parsing serialized DataObject of type vim.vm.ConfigSpec

at line 1, column 252

while parsing call information for method ReconfigVM_Task

at line 1, column 171

while parsing SOAP body

at line 1, column 64

while parsing SOAP envelope

at line 1, column 0

while parsing HTTP request for method reconfigure

on object of type vim.VirtualMachine

at line 1, column 0"

At C:\Users\ZKJEURX\Documents\Scripts\Vmware\ftdGet-RDMsNew.ps1:326 char:9

+         $taskMoRef = $vm.ReconfigVM_Task($spec)

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

This is the function causing the error that I am using to add the existing disks:


function Add-ExistingLunsFTD {

    [CmdLetBinding()]

    Param (

        $ReportFile ,

        $datastore

    )

    $csv = Import-Csv -path $ReportFile

    $disksToAdd = $csv |Where-Object {$_.DiskType -ne "Flat"}

    $vm = Get-vm $csv.VmName |Get-view

   

    Foreach ($Dev in $disksToAdd){

        <# Think the backing needs:

            compatibilityMode

            deviceName - from $dev.LunDevicename

            diskMode = from $dev.HDDiskMode

            lunuuid - Need to get this from $dev.ExtensionData.Backing.LunUuid

        #>

                      

        $back = New-Object VMware.Vim.VirtualDiskRawDiskMappingVer1BackingInfo

        $back.deviceName = $dev.LunDevicename

        $back.DataStore = $Datastore

        $back.FileName = $dev.DiskFile

        if($Dev.DiskType -eq "RawPhysical"){

            $back.compatibilityMode = "physicalMode"

        }

        else{

            $back.compatibilityMode = "virtualMode"

        }

       

        $device = New-Object VMware.Vim.VirtualDisk

        $device.Backing = $back

        $device.ControllerKey = $Dev.HDController

        $device.UnitNumber = $Dev.HDUnit

       

        $DevSpec = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $DevSpec.operation = "add"

        $DevSpec.fileoperation = "create"

        $DevSpec.device = $device

       

        $VmSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

        $VmSpec.deviceChange += $DevSpec

       

        $TaskRef = $vm.ReconfigVM_Task($VmSpec)

        $task = Get-View $TaskRef

        while("running","queued" -contains $task.Info.State){

            $task.UpdateViewData("Info.State")

        }

        $task.UpdateViewData("Info.Result")

    }

}

Kind regards to all
Tom

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I suspect something might be wrong in your CSV file, and that the value 'RDM' is coming from there.
Perhaps you can also share the layout and some sample values of your CSV file.

To see the complete object ($VmSpec) as it is received by vSphere, have a look in the vpxd log file.

That should show the error and a dump of the complete object and it's content.


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

I suspect something might be wrong in your CSV file, and that the value 'RDM' is coming from there.
Perhaps you can also share the layout and some sample values of your CSV file.

To see the complete object ($VmSpec) as it is received by vSphere, have a look in the vpxd log file.

That should show the error and a dump of the complete object and it's content.


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

0 Kudos
Atomtom
Contributor
Contributor
Jump to solution

Hi LucD,

You are a wizard! Bang on the money... Almost.

I think the problem is the value I am passing to the $DataStore parameter. I am passing in a string that looks like this: "RDM-DataStore-City". I ran the script again and substituted "RDM-DataStore-City" with "Tom".... and it ran, but failed because we don't have a datastore like this.

Now I am confused by the API reference material...

This is clearly the object we are trying to populate:

Data Object - VirtualDiskRawDiskMappingVer1BackingInfo(vim.vm.device.VirtualDisk.RawDiskMappingVer1BackingInfo)

This inherits the Datastore property from:

Data Object - VirtualDeviceFileBackingInfo(vim.vm.device.VirtualDevice.FileBackingInfo)

That page seems to imply that the datastore attribute contains a Datastore object?

ManagedObjectReference

to a Datastore

But if I look at the managed object here:

Managed Object - Datastore(vim.Datastore)

It seems to imply I can just pass the string, but it doesn't like it.

Any idea what I am now doing wrong?

Many thanks for your help.

Tom

0 Kudos
Atomtom
Contributor
Contributor
Jump to solution

I figured it out....

I need to get the datastore early on and supply the datastore id to the object. So I have added:

$DataStoreObj = Get-DataStore $DataStore

And then when creating my $DevSpec I add the id:

$back = New-Object VMware.Vim.VirtualDiskRawDiskMappingVer1BackingInfo

$back.deviceName = $dev.LunDevicename

$back.DataStore = $($DataStoreObj.id)

$back.FileName = $dev.DiskFile

I also note that I have to remove the device spec of fileoperation or it moans that the file already exists, so that section looks like this:

        $DevSpec = New-Object VMware.Vim.VirtualDeviceConfigSpec

        $DevSpec.operation = "add"

        $DevSpec.device = $device

I'll paste the full script below.

Many thanks indeed for your help and prompt assistance. My weekend is now looking much easier - I have 250 RDMs to drop and attach from 16 VMs all moving to the same cluster.

Kind regards

Tom

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, that is the Id it needs there.


Not too sure you can leave out the VirtualDeviceConfigSpec though.
Instead of 'add' you would need 'edit' on the operation property.

You can always see the available values in an enum with something like this

[VMware.Vim.VirtualDeviceConfigSpecOperation]::GetValues('VMware.Vim.VirtualDeviceConfigSpecOperation')


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

0 Kudos
Atomtom
Contributor
Contributor
Jump to solution

LucD,

You're a star. Many thanks for that pointer.

I'll try the 'edit' option. It does work without it. But it's good to be specific!

Awesome help. Many thanks indeed.

Kind regards

Tom

0 Kudos
mlgurav
Contributor
Contributor
Jump to solution

Hi,

 

Could you please share the final script. I am looking for something similar and would need something to base my script on.

Thanks...

0 Kudos