VMware Cloud Community
ice89
Contributor
Contributor
Jump to solution

Migration to another host fails

Hi Community,

i wrote a script to shutdown, enable memory and cpu hotplug, migrate to another host and start the vm after all tasks done.

I use the following command to migrate the vm to another host:

Get-VM -Name $strNewVMName | Move-VM -Destination esxhost1

This command starts the task to migrate the powered off vm from esxhost2 to esxhost1

After the task finished, the script starts the vm with the command: Get-VM -Name $strNewVMName | Start-VM

But now comes my problem:

I see in in the recent Tasks that the vm becomes unregister from the "new" esxhost1 and reregister to esxhost1. The vm starts now on the esxhost1

It works fine when i migrate the powered off vm manually via vCenter but not with my script

Does anyone have any idea to solve my problem?

Thanks in advance and Merry Christmas Smiley Happy

0 Kudos
1 Solution

Accepted Solutions
jpsider
Expert
Expert
Jump to solution

Thats certainly very strange, I walked through your steps manually, and was able to power on a vm, on the new host without a problem. Do you have DRS setup? or is that located on local storage of that host?

View solution in original post

0 Kudos
8 Replies
jpsider
Expert
Expert
Jump to solution

Can you provide your entire script? removing pwd's or ip information?

Also, are you moving just the host? or are you migrating from one datastore to another?

-Thanks

0 Kudos
ice89
Contributor
Contributor
Jump to solution

No problem, no secret or passwords in the script....

i just want to change the host not the datastore....

The script is to move automatically the vm's from a cluster without EVC to a cluster with EVC...

#Snapin für VMware hinzufügen (Add VMware Snapin)

Add-PSSnapin VMware.VimAutomation.Core

#Beim ersten mal Ausführen (Only on first run)

#Set-PowerCLIConfiguration -InvalidCertificateAction Ignore

#Verbindung zu vCenter aufbauen (Connecting vCenter)

connect-viserver vcenter

write-host Verbunden mit vCenter

#Import der CSV Datei

Import-Csv deploy.csv |

foreach {

    $strNewVMName = $_.name

    #write-host $strNewVMName

   write-host "Shutingdown VM:" + $strNewVMName

   Get-VM $strNewVMName | Shutdown-VMGuest -Confirm:$false

   $VMPowerState = Get-VM $strNewVMName | select PowerState

   while ($VMPowerState -match "PoweredOn")

   {

   sleep 5

   $VMPowerState = Get-VM $strNewVMName | select PowerState

   }

   #Enable-MemHotAdd $strNewVMName

   write-host "Configure Memory HotPlug:" $strNewVMName

    $vmview = Get-vm $strNewVMName | Get-View

    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $extra = New-Object VMware.Vim.optionvalue

    $extra.Key="mem.hotadd"

    $extra.Value="true"

    $vmConfigSpec.extraconfig += $extra

    $vmview.ReconfigVM($vmConfigSpec)

    sleep 2

    write-host "Configure CPU HotPlug:" $strNewVMName

    $vmview = Get-vm $strNewVMName | Get-View

    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $extra = New-Object VMware.Vim.optionvalue

    $extra.Key="vcpu.hotadd"

    $extra.Value="true"

    $vmConfigSpec.extraconfig += $extra

    $vmview.ReconfigVM($vmConfigSpec)

    sleep 10

   write-host "Move VM to esxhost01"

   Get-VM -Name $strNewVMName | Move-VM -Destination esxhost01

   sleep 10

  # Get-VM -Name $strNewVMName | Start-VM

                

  

0 Kudos
jpsider
Expert
Expert
Jump to solution

Can you clarify exactly what the problem is?  I'm a bit confused as to what you are seeing and what you would like resolved.

0 Kudos
ice89
Contributor
Contributor
Jump to solution

Hi,

most works, only the last part makes problems.

1. Shutdown VM - works

2. Add Mem/CPU hotplug - works

3. Migrate VM to other host - seems so

4. Start VM on new host - don´t work

EVC.jpg

I don´t unterstand why the vCenter remigrate the vm to the "old" host.

When i migrate the vm via script and start the guest via "Start Guest" Button, the same thing happens.

A migration via vCenter works fine.

0 Kudos
jpsider
Expert
Expert
Jump to solution

Thats certainly very strange, I walked through your steps manually, and was able to power on a vm, on the new host without a problem. Do you have DRS setup? or is that located on local storage of that host?

0 Kudos
ice89
Contributor
Contributor
Jump to solution

Hi jpsider,

thanks for your help...

I´ve just tested and it works without DRS...

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

If you have DRS enabled on your cluster, when you start a virtual machine, DRS will determine the optimal host to start your vm, and will start the vm on that host. So if you use DRS and want to run a vm on a particular host, the best thing you can do is to create a vm to host DRS affinity rule.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
ice89
Contributor
Contributor
Jump to solution

I know the feature of DRS...

But all hosts (six) are under 40% utilization.... I thought it should therefore work

Thanks for all Smiley Happy

0 Kudos