How to create and update virtual disks

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

  1. Valid access token
  2. Access to Virtual Machine

Step-by-step guide

  1. Get virtual machine ID, either moref or uuid using the search feature in the /vm resource:

    Request
    http GET "https://vss-api.eis.utoronto.ca/v2/vm?name=like,%Frontend2%&short=1" "Authorization: Bearer $TK"
    Response Body
    {
        "_links": {
            "self": "https://vss-api-dev.eis.utoronto.ca/v2/vm?filter=name,like,%25Frontend2%25&short=1"
        },
        "data": [
            {
                "hostname": null,
                "ip_address": "",
                "moref": "vm-2183",
                "name": "2004T-Frontend2",
                "power_state": "poweredOff",
                "uuid": "50309a8a-88ca-5291-2ad3-63f2522c3f8e"
            }
        ],
        "meta": {
            "count": 1,
            "filter": "name,like,%Frontend2%",
            "pages": {
                "first_url": "https://vss-api-dev.eis.utoronto.ca/v2/vm?filter=name%2Clike%2C%25Frontend2%25&page=1&per_page=100&expand=True",
                "last_url": "https://vss-api-dev.eis.utoronto.ca/v2/vm?filter=name%2Clike%2C%25Frontend2%25&page=1&per_page=100&expand=True",
                "next_url": null,
                "page": 1,
                "pages": 1,
                "per_page": 100,
                "prev_url": null,
                "total": 1
            },
            "time": "0.00804s",
            "user": "jm"
        }
    }
  2. Since vSphere does not support disk "shrinking" (unless the disk is 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 DELETE "https://vss-api.eis.utoronto.ca/v2/vm/<vm-id>/disk/1" "Authorization: Bearer $TK"
     
    # HTTP POST to disk 1 resource will create a new 300GB disk as 
    # specified in the attribute value
    http POST "https://vss-api.eis.utoronto.ca/v2/vm/<vm-id>/disk" "Authorization: Bearer $TK" value:='[300]' 
  3. Verifying Disk 1 settings:

    Request
    http GET "https://vss-api.eis.utoronto.ca/v2/vm/<vm_uuid>/disk/1" "Authorization: Bearer $TK"
    Response Body
    {
        "_links": {
            "disk": "https://vss-api-dev.eis.utoronto.ca/v2/vm/vm-2183/disk",
            "self": "https://vss-api-dev.eis.utoronto.ca/v2/vm/vm-2183/disk/1"
        },
        "data": [
            {
                "capacity_gb": 300,
                "controller": {
                    "type": "LSI Logic",
                    "virtual_device_node": "SCSI controller 0:0"
                },
                "description": "314,572,800 KB",
                "key": 2000,
                "label": "Hard disk 1",
                "shares": {
                    "level": "normal",
                    "shares": 1000
                },
                "unit": 1
            }
        ],
        "meta": {
            "count": 1,
            "time": "0.03733s",
            "user": "jm"
        }
    }
  4. Adding Disk 3 is done making a POST request to /vm/<vm_uuid>/disk resource:

    http POST "https://vss-api.eis.utoronto.ca/v2/vm/<vm-id>/disk" "Authorization: Bearer $TK"  value:='[300]' 
  5. Verifying new disk layout:

    http GET "https://vss-api.eis.utoronto.ca/v2/vm/<vm-id>/disk" "Authorization: Bearer $TK"
    Response Body
    {
        "_links": {
            "self": "https://vss-api.eis.utoronto.ca/v2/vm/<vm-id>/disk",
            "vm": "https://vss-api.eis.utoronto.ca/v2/vm/<vm-id>"
        },
        "data": [
            {
                "_links": {
                    "self": "https://vss-api.eis.utoronto.ca/v2/vm/<vm-id>/disk/1"
                },
                "capacityGB": 300,
                "unit": 1
            },
            {
                "_links": {
                    "self": "https://vss-api.eis.utoronto.ca/v2/vm/<vm-id>/disk/2"
                },
                "capacityGB": 300,
                "unit": 2"
            },
            {
                "_links": {
                    "self": "https://vss-api.eis.utoronto.ca/v2/vm/<vm-id>/disk/3"
                },
                "capacityGB": 300,
                "unit": 3
            }
        ],
        "meta": {
            "count": 2,
            "time": "0.05709s",
            "user": "jm"
        }
    }