v3 api for create vm through uploaded image with minimum fields.

Badge +4
Can Any one provide sample v3 rest call for creating vm from uploaded image.

8 replies

Userlevel 2
Badge +9
Try the following. I tried this on the latest CE version 20170720 and it works.

I used the latest API v3 reference from here: http://developer.nutanix.com/reference/v3/#definitions-vm_intent_input

POST: https://{Cluster IP}:9440/api/nutanix/v3/vms

Example Body:
{ "api_version":"3.0", "metadata": { "kind":"vm", "categories":{ "Project":"Test_Project" } }, "spec":{ "resources":{ "memory_size_mib": 2048, "num_vcpus_per_socket": 1, "num_sockets": 1, "power_state":"OFF", "disk_list": [ { "data_source_reference": { "kind": "image", "uuid": "26c19ab6-6737-44d4-82bb-a79cdfb39add" }, "device_properties": { "device_type": "DISK" } } ] }, "cluster_reference":{ "uuid": "000550d2-1bca-6006-2416-d8cb8a31916d", "kind":"cluster" }, "name":"test_vm" }}
Badge +4
This is not working for me. Rest call succedded but in UI vm create failed no failure reason is shown. I am using community edition and I am not able to find poll task api for v3.
I use following data for create vm.
{ "api_version": "3.0", "metadata": { "kind": "vm" }, "spec": { "resources": { "num_vcpus_per_socket": 1, "num_sockets": 1, "memory_size_mb": 512, "power_state": "POWERED_OFF", "disk_list": [{ "data_source_reference": { "kind": "image", "uuid": "2484bdd2-ba36-47f3-b142-0e070bec804e" }, "device_properties": { "disk_address": { "device_index": 0, "adapter_type": "IDE" }, "device_type": "DISK" } }] }, "name": "test_vm" }}
Userlevel 2
Badge +9
In the output when you create the VM you should see the VM uuid. Use the VM uuid to get the status.

GET https://{Cluster IP}:9440/api/nutanix/v3/vms/{VM uuid}

This should show you the error.

Badge +4
I am getting following reply.
{ "status": { "state": "ERROR", "message_list": [ { "message": "No permission to access the resource. The permissions for the owner require their VMs be in a project.", "reason": "ACCESS_DENIED" } ] }, "spec": { "name": "test_vm", "resources": { "num_vcpus_per_socket": 1, "num_sockets": 1, "power_state": "POWERED_OFF", "disk_list": [ { "data_source_reference": { "kind": "image", "uuid": "5e834c7c-91f6-4f46-9046-c790a0a5344c" }, "device_properties": { "disk_address": { "device_index": 0, "adapter_type": "IDE" }, "device_type": "DISK" }, "disk_size_mib": 512 } ] } }, "api_version": "3.0", "metadata": { "owner_reference": { "kind": "user", "uuid": null, "name": null }, "kind": "vm", "entity_version": 0, "uuid": "db02a87d-bf35-47a7-bb31-c3b0a67032af", "categories": {} }}what does the message mean and how can I resolve it.
Userlevel 2
Badge +9
What permissions does your user have? I'm doing this with 'cluster admin' user and it works without specifying a project (I have the latest CE version 2017.07.20). I remember though that in some past versions I had to create a project in the SSP portal before VM was successfully created. Try creating a VM for a project. Example of body with project is in the first post.

Userlevel 7
Badge +34
Hi hiteshhapani

Were you able to get it going? izy has some good options for you to try. Let us know
Badge +6
This example in this post helped me, specifically the disk_list section. The api docs are not clear what are valid values for data_source_reference and disks aren't mentioned at all on the example spec for posting vm intent:


It would be great if the API docs could be updated with a information about what are valid values and kinds for the different vm resources.

Userlevel 2
Badge +12
"message": "No permission to access the resource. The permissions for the owner require their VMs be in a project.", "reason": "ACCESS_DENIED"This looks like SSP permisions, not sure why that would error