Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 180329

ReconfigVM_Task failing - Adding existing RDMs / LUNs

$
0
0

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


Viewing all articles
Browse latest Browse all 180329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>