VMware Cloud Community
OBXMAN007
Contributor
Contributor

help on cold migrations to different datacenter, same vcenter

problem defined: trying to cold migrate vms from one datacenter to another datacenter within same vcenter - no matter what code i try to use, i get an error or "half baked" results - i.e. some vms cold migrate, others do not with an error

example001:

PowerCLI C:\> import-csv c:\maint.csv | %{ get-vm -name $_.ServerName -Location (get-datacenter "dtc001") | move-vm -Datastore (get-datastore -name "DATASTORE_008") -RunAsync -Confirm:$false }

maint.csv contents:

ServerName

SERVER001

error in vcenter:

"a specified parameter was not correct. datastore"

example002 - using Lucd's relocatevm method:

foreach($row in (Import-Csv c:\serverlistmigrate.csv -UseCulture)){

$vm = ''

$esx = ''

$spec = ''

$spec.datastore = ''

$spec.host = ''

$spec.resourcepool = ''

CLS

$vmname = $row.vmname

$vmhost = $row.vmhost

$datastore = $row.datastore

$vm = Get-VM -Name $vmname

$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec

  $spec.datastore = (Get-Datastore -Name $datastore).ExtensionData.MoRef

  $spec.pool = (Get-ResourcePool -Name $resourcepool).ExtensionData.MoRef

  $spec.host = (Get-VMHost -Name $vmhost).ExtensionData.MoRef

  $vmObj = Get-VM -Name $vmname | Get-View

  $vmObj.RelocateVM_Task($spec, "defaultPriority")

}

c:\serverlistmigrate.csv contents:

vmname,vmhost,resourcepool,datastore

"SERVER001,esxhost07,rpl01_High,DATASTORE_008

error in vcenter:

"a specified parameter was not correct. host"

**** USING above method, I will get some to migrate, but some fail with same error as above.

NEEDED:  All I want is to cold migrate multiple vms from one datacenter to another datacenter (different datastore)  within same vcenter with 100% success - I don't care what method is used - I just need solid, reliable, consistent success.

Many thanks in advance!!!!

NOTES - POWERCLI VERSION, etc.

PowerCLI Version
----------------
   VMware vSphere PowerCLI 5.1 Release 1 build 793510
---------------
Snapin Versions
---------------
   VMWare AutoDeploy PowerCLI Component 5.1 build 768137
   VMWare ImageBuilder PowerCLI Component 5.1 build 768137
   VMware License PowerCLI Component 5.1 build 669840
   VMware vSphere PowerCLI Component 5.1 build 793489
Reply
0 Kudos
9 Replies
weinstein5
Immortal
Immortal

I have moved this thread to a more approroiate forum

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
Reply
0 Kudos
LucD
Leadership
Leadership

Are all the datastores shared between the 2 vCenters ?

Btw when on vSphere 5.1, this requirement is dropped. You don't need shared storage anymore to do a vMotion.


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

Reply
0 Kudos
OBXMAN007
Contributor
Contributor

Hi Luc,

datastores are separate in the separate datacenters. so I would say they are "not" shared between datacenters

vcenter version:  4.1   build:   491557

typical host versions:

Server Name : esx001
Name        : VMware ESXi
Version     : 4.1.0
Build       : 800380
FullName    : VMware ESXi 4.1.0 build-800380
ApiVersion  : 4.1
Server Name : esx002
Name        : VMware ESXi
Version     : 4.1.0
Build       : 800380
FullName    : VMware ESXi 4.1.0 build-800380
ApiVersion  : 4.1
Reply
0 Kudos
LucD
Leadership
Leadership

That means your cold migration would only use the network. And that should work in vSphere 4.*

There can be several reasons why the cold migration fails.

Just to name a few:

  • connectivity to the source and destination ESX(i) server, port 443 and 902 afaik
  • there can be an ISO connected to the VM's CD/DVD device
  • a VM with a 64-bit OS and the destination ESX(i) doesn't support 64-bit OS

Does the cold migration work when you do it from the vSphere client ?

Btw, why don't you use the Move-VM cmdlet ?

That has been seriously improved since I wrote that script.


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

Reply
0 Kudos
OBXMAN007
Contributor
Contributor

re: connectivity - it will work sometimes and fails on other times, even going to same host, so there shouldn't be a port block issue, otherwise it would never work

re: ISO - n/a - no connection to ISO, etc.

re: 64 bit - non-issue - these are 32 bit vms in question

re:  using move-vm, do you have any new snazzy code ?  using below I get the error  "a specified parameter was not correct. datastore"

import-csv c:\maint.csv | %{ get-vm -name $_.ServerName -Location (get-datacenter "dtc001") | move-vm -Datastore (get-datastore -name "DATASTORE_008") -RunAsync -Confirm:$false }

maint.csv contents:

ServerName

SERVER001

re: using move-vm - I'm getting the old "must be in same datacenter" error:

PowerCLI C:\> Move-VM -VM 'SERVER001' -Destination $myhost -Datastore $myds -DiskStorageFormat "Thin"
Move-VM : 10/1/2012 1:27:59 PM    Move-VM       Destination container must be in the same Datacenter.
At line:1 char:8
+ Move-VM <<<<  -VM 'BSS11WP-OPTI' -Destination $myhost -Datastore $myds -DiskStorageFormat "Thin"
    + CategoryInfo          : InvalidArgument: (esx07vp.mc.vanderbilt.edu:VMHostImpl) [Move-VM], VimException
    + FullyQualifiedErrorId : Client20_VmHostServiceImpl_CheckMoveVmParameters_InvalidDatacenter,VMware.VimAutomation.
   ViCore.Cmdlets.Commands.MoveVM
Reply
0 Kudos
OBXMAN007
Contributor
Contributor

Luc - more info

I found an old blurb from you.....see BOTTOM of page/thread  (adding the one line $spec )

http://communities.vmware.com/thread/267514

........and implemented it on another "rev" of a script I had  - added the one line  "$spec"   as shown below...........

$tgtDS = $datastore
$tgtHost = $vmhost
$vm = Get-VM $vmname | Get-View
$esx = Get-VMHost $tgtHost | Get-View
$parent = $esx.Parent
while($parent.Type -ne "Datacenter"){
$parent = (Get-View $parent).Parent
}
$dc = Get-View $parent
$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.datastore = (Get-Datastore $tgtDS | Get-View).MoRef
$spec.host = $esx.MoRef
$spec.Pool = (Get-Datacenter $dc.Name | Get-ResourcePool -Name "rpl01_High" | Get-View).MoRef
$spec
$vm.RelocateVM($spec,"defaultPriority")

it is now "working" - yippy!!   - I will test and let you know if I am getting consistent success


Reply
0 Kudos
LucD
Leadership
Leadership

That is very strange :smileyconfused:

In that thread I asked to insert the "$spec" line to dunmp the contents of that object to the console (for debugging purposes).

That shouldn't make a difference to the call to the RelocateVM method.

Is the cold migration failing if you remove that line ?


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

Reply
0 Kudos
OBXMAN007
Contributor
Contributor

Luc - running out of time today - will report back tomorrow - thanks!!

Reply
0 Kudos
OBXMAN007
Contributor
Contributor

Luc - it was very strange - ran without $spec and it ran successfully - latest codes snippet supplied previously seems to be working - you can mark/I will mark as answered - the process of getting the script to work was resulting in inconsistent failures/successes - seems to be working now

Reply
0 Kudos