Looking to take Nutanix for a free test drive?
Click on the following to see what it's all about:

Update Existing VM

June 18, 2020

by Chris Rasmussen

Intended Audience Level: Beginner/Intro

Code Sample Type: Snippet

Nutanix Technologies: Prism Central

Minimum Product Version: 5.15

Script/Code Language: JSON Payload

REST API Sample? Yes

REST API Version: v3

JSON payload to update an existing AHV VM. “spec” and “metadata” for the existing VM must be obtained first, using a GET request to https://[prism_central_ip_address]:9440/api/nutanix/v3/vms/[vm_uuid].

Code Sample Details

Note this section may be empty, if additional code sample details are not available.

Request Parameters

The below parameters should be used with the sample payload.

Please note you will need to alter {{placeholder}} values to match your environment, e.g. subnet name and UUID, cluster name and UUID.

Request URL:

https://[prism_central_ip_address]:9440/api/nutanix/v3/vms/[vm_uuid]

Request method:

PUT

Recommended Reading

Because the PUT request for a VM update does require some quite specific VM information, it is strongly recommended to read the article titled “PUT that down! Updating a VM with Prism Central v3 API” before using this code sample.

Payload

{
    "spec": {
        "name": "{{vm_name}}",
        "resources": {
            "num_threads_per_core": 1,
            "vnuma_config": {
                "num_vnuma_nodes": 0
            },
            "serial_port_list": [],
            "nic_list": [
                {
                    "nic_type": "NORMAL_NIC",
                    "uuid": "a0e12ace-c07a-4065-9018-1ca31a8c35c0",
                    "ip_endpoint_list": [
                        {
                            "ip": "10.133.16.172",
                            "type": "ASSIGNED"
                        }
                    ],
                    "vlan_mode": "ACCESS",
                    "mac_address": "50:6b:8d:82:a9:9b",
                    "subnet_reference": {
                        "kind": "subnet",
                        "name": "{{subnet_name}}",
                        "uuid": "{{subnet_uuid}}"
                    },
                    "is_connected": true,
                    "trunked_vlan_list": []
                }
            ],
            "num_vcpus_per_socket": 1,
            "num_sockets": 2,
            "disable_branding": false,
            "enable_cpu_passthrough": false,
            "gpu_list": [],
            "is_agent_vm": false,
            "memory_size_mib": 1024,
            "boot_config": {
                "boot_device_order_list": [
                    "CDROM",
                    "DISK",
                    "NETWORK"
                ],
                "boot_type": "LEGACY"
            },
            "hardware_clock_timezone": "UTC",
            "power_state_mechanism": {},
            "power_state": "OFF",
            "machine_type": "PC",
            "vga_console_enabled": true,
            "disk_list": [
                {
                    "device_properties": {
                        "disk_address": {
                            "device_index": 0,
                            "adapter_type": "SCSI"
                        },
                        "device_type": "DISK"
                    },
                    "uuid": "ccafe8ca-d465-474a-8c3b-3c9e37057ebb",
                    "disk_size_bytes": 21474836480,
                    "disk_size_mib": 20480
                },
                {
                    "device_properties": {
                        "disk_address": {
                            "device_index": 0,
                            "adapter_type": "IDE"
                        },
                        "device_type": "CDROM"
                    },
                    "uuid": "e98edf2d-3ae1-489e-ad06-11076ffc37ca"
                }
            ]
        },
        "cluster_reference": {
            "kind": "cluster",
            "name": "{{cluster_name}}",
            "uuid": "{{cluster_uuid}}"
        }
    },
    "api_version": "3.1",
    "metadata": {
        "last_update_time": "2020-06-19T02:35:49Z",
        "kind": "vm",
        "uuid": "{{vm_uuid}}",
        "spec_version": 0,
        "creation_time": "2020-06-19T02:35:49Z",
        "categories_mapping": {},
        "categories": {}
    }
}