For this tutorial, we will pretend there's a need to change the disk layout of a virtual machine (recently provisioned) based in the following statements:
- Disk 1 needs to be resized from 1TB to 300GB
- Disk 2 needs to be resized from 250GB to 300GB
- New Disk 3 of 300GB needs to be added.
Prerequisites
- Valid access token.
- Access to Virtual Machine
- Virtual Machine name.
Step-by-step guide
Get virtual machine UUID using the search feature in the /vm resource:
Requesthttp -a $TK GET "https://vss-api.eis.utoronto.ca:8001/v2/vm?name=vm-testing&summary"
Response Body{ "_links": { "api": "https://vss-api.eis.utoronto.ca:8001/v2/", "self": "https://vss-api.eis.utoronto.ca:8001/v2/vm" }, "data": [ { "_links": { "self": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>" }, "name": "1606D-vm-testing", "uuid": "<vm_uuid>" } ], "meta": { "count": 1, "time": "10.13983s", "user": "josem" } }
Since vSphere does not support disk "shrinking" (unless it's cloned to a new target disk), we would need to remove Disk 1 and create a new Disk 1 of 300GB. This can be done as follows:
# HTTP DELETE method to the right disk resource will remove the disk http -a $TK DELETE "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/disk/1" # HTTP POST to disk 1 resource will create a new 300GB disk as # specified in the attribute value http -a $TK POST "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/disk/1" value=300
Verifying Disk 1 settings:
Requesthttp -a $TK GET "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/disk/1"
Response Body{ "_links": { "self": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/disk/1", "vm": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>" }, "data": [ { "capacityGB": 300, "controller": { "type": "LSI Logic", "virtualDeviceNode": "SCSI controller 0:1" }, "description": "314,572,800 KB", "fileName": "[CL-NSTOR47-NFS-vol31] 1606D-vm-testing/1606D-vm-testing_1.vmdk", "label": "Hard disk 1", "provisioning": "Thin", "shares": { "level": "normal", "shares": 1000 } } ], "meta": { "count": 1, "time": "0.04656s", "user": "jm" } }
Adding Disk 3 is done making a POST request to /vm/<vm_uuid>/disk/3 resource:
http -a $TK POST "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/disk/3" value=300
Verifying new disk layout:
http -a $TK GET "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/disk"
Response Body{ "_links": { "self": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/disk", "vm": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>" }, "data": [ { "_links": { "self": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/disk/1" }, "capacityGB": 300, "label": "Hard disk 1" }, { "_links": { "self": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/disk/2" }, "capacityGB": 300, "label": "Hard disk 2" }, { "_links": { "self": "https://vss-api.eis.utoronto.ca:8001/v2/vm/<vm_uuid>/disk/3" }, "capacityGB": 300, "label": "Hard disk 3" } ], "meta": { "count": 2, "time": "0.05709s", "user": "jm" } }
Related articles