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.

11 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 +35
Hi hiteshhapani

Were you able to get it going? izy has some good options for you to try. Let us know
Userlevel 1
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:

http://developer.nutanix.com/reference/v3/#vms

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
Userlevel 1
Badge +6
Hi @hiteshhapani ! :)

I know this is an old post but just wanted to jump in real quick and provide an example of creating a VM using the v3 APIs.

This example creates a basic VM with a single disk cloned from an uploaded image.

code:
{
"metadata": {
"kind":"vm"
},
"spec": {
"name":"test",
"resources": {
"disk_list": [
{
"data_source_reference": {
"kind": "image",
"uuid": "a91f56a0-2133-4080-b6b4-60961e94dad7"
},
"device_properties": {
"device_type": "DISK",
"disk_address": {
"adapter_type": "SCSI",
"device_index": 0
}
}
}
],
"memory_size_mib": 1024,
"num_sockets": 1,
"num_vcpus_per_socket": 1,
"power_state": "OFF"
}
}
}


Cheers,
Chris R @ Nutanix
Badge +1
Hi,
I tried this with CE 5.6 or 2018.05.01 and Hypervisor Nutanix 20180425.199 and I can't get it to work. Both PRISM Elements and PRISM Central throws an error. The error says: "Invalid CDROM bus: SCSI". I have "DISK" specified, see below. I am using a qcow2 image. Is this a bug in CE or what am I missing?
(If I change adapter type to "IDE" it creates a CDROM using my image.)
I'm POSTing to https://a.b.c.d:9440/api/nutanix/v3/vms

Any ideas?

Here is my JSON:
{
"metadata": {
"kind": "vm",
"name": "controller 1"
},
"spec": {
"name": "_infra_server1",
"description": "controller server 1",
"cluster_reference": {
"kind": "cluster",
"uuid": "00057a75-cae0-f081-780e-0894ef657074"
},
"resources": {
"power_state": "OFF",
"num_vcpus_per_socket": 1,
"num_sockets": 4,
"memory_size_mib": 32768,
"disk_list": [ {
"data_source_reference": {
"kind": "image",
"uuid": "81d4c51e-0803-4f5d-b557-64c3bb170e13"
},
"device_properties": {
"device_type": "DISK",
"disk_address": { "adapter_type": "SCSI",
"device_index": 0
}
}
}
],
"nic_list": [
{
"nic_type": "NORMAL_NIC",
"subnet_reference": {
"kind": "subnet",
"uuid": "c84417e3-2f27-4225-a10f-96992872ef8e"
}
}
]
}
}
}
And if you want to clone from a existing VM with a sysprep

code:
{
"metadata":{
"kind":"vm"
},
"spec":{
"name":"VMCLONED001",
"cluster_reference":{
"kind":"cluster",
"name":"CLUSTERNUTA001",
"uuid":"00058128-10da-0XX-2c1f-98039b05d593"
},
"resources":{
"guest_customization":{
"is_overridable":false,
"sysprep":{
"install_type":"PREPARED",
"unattend_xml":"FNjaGVtYSgICm9(...)1cD5BZG1pbmlz="
}
},
"parent_reference":{
"kind":"vm",
"uuid":"b00cc669-cb2d-4235-aXXX-ff9b234bf8c9",
"name":"GoldenMaster001"
},
"power_state":"OFF"
}
}
}

Reply