VMware {code} Community
othala98000
Contributor
Contributor
Jump to solution

Relocate VMX file with pyvmomi or REST API

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

Labels (3)
0 Kudos
1 Solution

Accepted Solutions
doskiran
Enthusiast
Enthusiast
Jump to solution

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"
	}
}

 

View solution in original post

2 Replies
doskiran
Enthusiast
Enthusiast
Jump to solution

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"
	}
}

 

othala98000
Contributor
Contributor
Jump to solution

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

0 Kudos