Recently I have been working on a project to replace an old FAS2040 NetApp array with a newer FAS2240. The old FC disk shelves from the 2040 will be re-purposed in the 2240, so will be physically moved to the new array complete with all of the existing VMs in the farm.
This poses an interesting problem though, the existing filers with their current IP's will disappear and the new filer will have a different hostname and IP. This change will cause all of the VMs to go grey because they cannot reach their disks. With a little googleing you can find a couple of scripts that are able to re-register VMs, these can be modified to fix this issue.
To add to the interest in this environment we have VMs with multiple disks on different NFS mounts, so we need to fix the vmx files so they point to the new datastores on the new filer.
So whats the plan then??
This poses an interesting problem though, the existing filers with their current IP's will disappear and the new filer will have a different hostname and IP. This change will cause all of the VMs to go grey because they cannot reach their disks. With a little googleing you can find a couple of scripts that are able to re-register VMs, these can be modified to fix this issue.
To add to the interest in this environment we have VMs with multiple disks on different NFS mounts, so we need to fix the vmx files so they point to the new datastores on the new filer.
So whats the plan then??
- Get the names of all your templates
Get-Template | Select-Object Name | Export-Csv -NoTypeInformation -Path ./templates.csv - Convert all templates to VMs
Set-Template -ToVM * -Confirm:$false - Run this command to collect the necessary information
get-view -viewtype virtualmachine -property name, config.files.vmpathname, parent, Runtime.Host | select name, @{n="vmxFilePath"; e={$_.config.files.vmpathname}}, parent, @{n="host"; e={$_.runtime.host}} | Export-Clixml -Path ./vms.xml - Remove all VMs from the inventory
Get-Datastore <regex to get all affected DS> | Get-VM | Remove-VM -Confirm:$false - Enable SSH on a host
Get-VMHost <hostname> | Foreach-Object { Start-VMHostService -Confirm:$False -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )} - Get the datastore locations
SSH to your host > enter ls -l /vmfs/volumes/
Save this info for later - Unmount affected Datastores
Get-Datastore <regex to match all affected DS> | foreach {Remove-Datastore -Confirm:$false -Datastore $_ -VMHost (Get-VMHost <regex to get all affected hosts>)} - Mount your new datastores, since there are heaps of ways to do this I'll leave it to you
- Get the new datastore locations
Just re-do point 6 above - Copy this sh script over to your host, make sure you replace OLD-DATASTORE and NEW-DATASTORE with the correct UID's from point 6 and 9.#!/bin/sh
find /vmfs/volumes/ -name '*.vmx' -maxdepth 3 | while read fl; do
echo $fl
mv "$fl" "$fl.old"
sed 's/OLD-DATASTORE/NEW-DATASTORE/g;s/OLD-DAASTORE/NEW_DATASTORE/g' "$fl.old" > "$fl"
chmod 755 "$fl"
done
You can add as many datastores to rename as you like, just use separate them with ; the example above does 2 datastores. - Disable SSH
Get-VMHost <hostname> | Foreach-Object { Stop-VMHostService -Confirm:$False -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )} - Register all your VMs
Import-Clixml .\vms.xml | foreach { New-VM -VMFilePath $_.vmxfilepath -VMHost (Get-VIObjectByVIView $_.host.toString()) -Location (Get-VIObjectByVIView $_.parent.toString()) -RunAsync} - Convert your templates back to templates
Import-Csv -Path ./templates.csv | foreach {Set-VM -ToTemplate -VM $_.name -Confirm:$false}
With a little luck you should be all done! :)