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

Send Multiple Requests as Batch

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 send multiple API requests as a single batch. This sample creates 4 virtual machines – 3 simple/shell VMs, and 1 detailed/advanced VM.

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/batch

Request method:

POST

Recommended Reading

In conjunction with this code sample, it is recommended to read the article titled “Batch Brewing – Multiple Requests with the Nutanix APIs“. It contains walk-through information about how to use API batch requests.

Payload

{
    "action_on_failure": "CONTINUE",
    "execution_order": "SEQUENTIAL",
    "api_request_list": [
        {
            "operation": "POST",
            "path_and_params": "/api/nutanix/v3/vms",
            "body": {
                "spec": {
                    "name": "batch_create_vm_1_basic",
                    "resources": {}
                },
                "metadata": {
                    "kind": "vm"
                }
            }
        },
        {
            "operation": "POST",
            "path_and_params": "/api/nutanix/v3/vms",
            "body": {
                "spec": {
                    "name": "batch_create_vm_2_basic",
                    "resources": {}
                },
                "metadata": {
                    "kind": "vm"
                }
            }
        },
        {
            "operation": "POST",
            "path_and_params": "/api/nutanix/v3/vms",
            "body": {
                "spec": {
                    "name": "batch_create_vm_3_basic",
                    "resources": {}
                },
                "metadata": {
                    "kind": "vm"
                }
            }
        },
        {
            "operation": "POST",
            "path_and_params": "/api/nutanix/v3/vms",
            "body": {
                "spec": {
                    "name": "batch_create_vm_4_detailed",
                    "resources": {
                        "power_state": "ON",
                        "num_vcpus_per_socket": 1,
                        "num_sockets": 1,
                        "memory_size_mib": 1024,
                        "disk_list": [
                            {
                                "disk_size_mib": 1024,
                                "device_properties": {
                                    "device_type": "DISK"
                                }
                            },
                            {
                                "device_properties": {
                                    "device_type": "CDROM"
                                }
                            }
                        ],
                        "nic_list": [
                            {
                                "nic_type": "NORMAL_NIC",
                                "is_connected": true,
                                "ip_endpoint_list": [
                                    {
                                        "ip_type": "DHCP"
                                    }
                                ],
                                "subnet_reference": {
                                    "kind": "subnet",
                                    "name": "{{subnet_name}}",
                                    "uuid": "{{subnet_uuid}}"
                                }
                            }
                        ],
                        "guest_tools": {
                            "nutanix_guest_tools": {
                                "state": "ENABLED",
                                "iso_mount_state": "MOUNTED"
                            }
                        }
                    },
                    "cluster_reference": {
                        "kind": "cluster",
                        "name": "{{cluster_name}}",
                        "uuid": "{{cluster_uuid}}"
                    }
                },
                "api_version": "3.1.0",
                "metadata": {
                    "kind": "vm"
                }
            }
        }
    ],
    "api_version": "3.0"
}

Nutanix CALM DSL LAB 1.0
AVAILABLE NOW!

logo_calm

Have you wanted to learn the Nutanix Calm DSL, but haven't been sure where to start?
Check out the Nutanix Calm DSL Lab 1.0 now!