I was able to make this request to relocate a specific vdisk for a VM via REST call in python by running this code :
import requests
import json
url = "https://myvcenter.local/rest/vcenter/vm/vm-12016?action=relocate"
payload = json.dumps({
"spec": {
"disks": [
{
"value": {
"datastore": "datastore-11"
},
"key": "2000"
}
]
}
})
headers = {
'Content-Type': 'application/json',
'vmware-api-session-id': 'myToken',
}
response = requests.request("POST", url, headers=headers, data=payload)
This works , the vDisk was moved but not the VMX file that is on the same datastore.
I tried also to do something with pyvmomi example to relocate VM , but I was not able to find out how to move the VMX file : https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/relocate_vm.py
The VMX file seems not to be a vim.vm.device.VirtualDisk object.
Do you guys have any pointers for me to achieve a VMX file migration ? pyvmomi or REST call.
Thanks
Ues below Rest API and spec, which will relocate both vDisk and VMX file into destination datastore.
POST: https://{{vCenter}}/api/vcenter/vm/{vm-id}?action=relocate
Spec:
-----
{
"disks": {
"2000": {
"datastore": "datastore-11"
}
},
"placement": {
"datastore": "datastore-11"
}
}
Ues below Rest API and spec, which will relocate both vDisk and VMX file into destination datastore.
POST: https://{{vCenter}}/api/vcenter/vm/{vm-id}?action=relocate
Spec:
-----
{
"disks": {
"2000": {
"datastore": "datastore-11"
}
},
"placement": {
"datastore": "datastore-11"
}
}
Thanks a lot to take time to reply !
In meatime I figureout dans yes Placement tag is the key to move the VMX file. If you dont specify other vDisk IDs , all vDisk will be moved to the placement datastore.
Cheers,
Jeremy