The engineering team has provided a python script to achieve SvMotion and XvMotion of VMs within the same vCenter server. This script works only within the same vCenter and does not work across multiple vCenter servers. The script does not make any changes to the source VM; however, as a best practice, VMware recommends having backups of the VM. Customers will need to use the PowerCLI scripts to migrate between vCenter servers.
Sample:
Steps :
1. Upload the script to vCenter Server (Check the Attachment: RelocateVM.py) in /tmp folder. The script is attached to the KB.
2. Validate the integrity of the script by using the below "cksum" command after uploading it to vCenter.
3. VMware recommends running the steps below on a small test VM and validating the results.
#cksum /tmp/RelocateVM.py
2479068796 7548 /tmp/RelocateVM.py
3. Run python script on vCenter server
Usage: RelocateVM.py [-h] [-s HOST] [-u USER] [-p PASSWORD] [-c CLUSTER_NAME]
[-t TARGETHOST] [-d DATASTORENAME] [-k VMS] [-r RP]
[-P PROVISIONTYPE]
action
The purpose of this tool is to migrate a virtual machine from a non-vSAN datastore to a vSAN datastore and change the disk provisioning type. The script must be ran on the vCenter Server.
Positional arguments:
action Now the following actions are supported: 'listVMs' 'relocate_vm' (Migrate virtual machine with type 'Change both compute resource and storage'. If '-- targetHost' is specified, compute resource will be migrated to the target host) optional arguments: -h, --help Show this help message and exit -s HOST, --vcHost HOST VC host to connect. (Required) -u USER, --user USER User name of vc host. (Default: '[email protected]') -p PASSWORD, --password PASSWORD Password of vc host. -c CLUSTER_NAME, --clusterName CLUSTER_NAME Specify the cluster need to detect. (Default: 'VSAN-Cluster') -t TARGETHOST, --targetHost TARGETHOST Migrate the virtual machine to a specific host or cluster -d DATASTORENAME, --datastore DATASTORENAME Specify the destination datastore. (Default: 'vsanDatastore') -k VMS, --vm VMS Specify the VM name need to be relocated. Sample: --vms vm1,vm2 -r RP, --resourcepool RP Specify the destination resource pool. Sample: --resourcepool 'rp1'. Relocate to cluster only if no resource pool is specified -P PROVISIONTYPE, --provisionType PROVISIONTYPE Virtual disk provision type, supports: thin, thick; if omitted, thick will be taken # python /tmp/RelocateVM.py -s <VCIP/localhost> -p <vCenterPassword> -c <Name of Destination vSAN cluster> -k <VM_name_source_cluster> -t <destination_host> -d <datastorename/vsandatastore> relocate_vm -P thick Sample command from LAB for ex.
# python /tmp/RelocateVM.py -s localhost -p '******' -c 'Cluster-01' -k 'VM-01' -t 'esx-host-01.example.com' -d 'vsanDatastore' relocate_vm -P thick
Total cluster number: 1
Cluster Name: xxxx_Cluster
vSAN enabled: True
Virtual Machines in cluster: ['VM-01', 'VM-02', 'VM-03', 'VM-04', 'VM-05']
8.0
Syntax:
python RelocateVM.py -s <vcenter_ip> -p '******' -c <CLUSTER_NAME> -k <VM_NAME> -t <HOST_IP> -d <Target_vSAN_Datastore_name> relocate_vm -P <desired_provisioning_type>
Sample command:
root@localhost [ /tmp ]# python RelocateVM.py -s localhost -p <password> -c 'Cluster-01' -k 'Source-Datastore-Name' -t <IP_address> -d 'vsanDatastore' relocate_vm -P thin
Sys path: ['/tmp', '/usr/lib/python3.10', '/usr/lib/vmware/site-packages/']
Total cluster number: 1
Cluster-01, vSAN enabled: True
Virtual Machines in cluster: ['VM-01', 'VM-02', 'VM-03', 'VM-04', 'vCLS-########-####-####-####-############', 'vCLS-########-####-####-####-############', 'vCLS-########-####-####-####-############']
/tmp/RelocateVM.py:166: DeprecationWarning: setDaemon() is deprecated, set the daemon attribute instead
=======
- After migration using RelocateVM.py:
[root@esx-host-01:~] esxcli vsan debug object list --vm-name=VM_Name
Object UUID: ########-####-####-####-############
Version: 19
Health: healthy
Owner: esx-host-02.example.com
Size: 10.00 GB
Used: 0.01 GB
Used 4K Blocks: 0.00 GB
Policy:
stripeWidth: 1
cacheReservation: 0
proportionalCapacity: 0 <=======
[root@esx-host-01:~] /usr/lib/vmware/osfs/bin/objtool getAttr -u ########-####-####-####-############
Object Attributes --
UUID:########-####-####-####-############
Object type:vsan
Group uuid:########-####-####-####-############
Container uuid:(null)
IsSparse:0
Allocation type:Thin <=======
A relocate VM task will be initiated and can be monitored from the UI/vsphere-client.
Workaround:
Customers can also choose to perform the task using powercli.