Get Started

Welcome to the Nutanix NEXT community. To get started please read our short welcome post. Thanks!

cancel
Showing results for 
Search instead for 
Did you mean: 

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

Highlighted
Adventurer

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

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

5 REPLIES
izy
Adventurer

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

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"
 }
}

Adventurer

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

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"
    }
}

izy
Adventurer

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

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.

 

Adventurer

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

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.
izy
Adventurer

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

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.