Solved

VM In Powered Off State After Creation via REST API

  • 28 January 2021
  • 1 reply
  • 155 views

Badge +1

The REST API for creating vm clone is working fine but after vm cloned. It was in powered off state.

Is there any way to set power on state via API 3 (in API 2 it was there, but its old and deprecated not work)

OR

Any other way to create VM or clone so that it will be in power on state after vm creation.

icon

Best answer by AnishWalia20 28 January 2021, 07:03

hey @Balram I don’t think there is any REST API v3 operation specifically related to the VM to power it on, but you can do so using PUT /vms/UUID v3 opeartion 

To update a VM's specs, we need to send an HTTP PUT request to the Prism Central IP. The request body should contain all current specs of the VM. The easiest way to get a VM's specs is to send a GET request to /vms/uuid

Now in the below output of GET operation, Scroll down to the Response Body text box. Find the spec key and copy starting from "spec" down to the last closing curly brace "}". Paste it to a text editor.

For eg-

{
"spec": {
"cluster_reference": {
"kind": "cluster",
"name": "Prolix",
"uuid": "00052c80-729d-8705-0000-0000000051fa"
},
"description": "v3api_vm",
"resources": {
"vnuma_config": {
"num_vnuma_nodes": 0
},
"nic_list": [
{
"ip_endpoint_list": [],
"nic_type": "NORMAL_NIC",
"subnet_reference": {
"kind": "subnet",
"name": "vlan25",
"uuid": "565784d2-7a68-4a16-a1bd-92473760f607"
},
"uuid": "4bff96c1-386e-40bb-bc5b-1dc8a85952af",
"mac_address": "50:6b:8d:b4:76:12"
}
],
"num_vcpus_per_socket": 2,
"num_sockets": 1,
"gpu_list": [],
"memory_size_mib": 4096,
"power_state": "OFF",
"hardware_clock_timezone": "UTC",
"power_state_mechanism": {
"mechanism": "HARD"
},
"vga_console_enabled": true,
"disk_list": [
{
"device_properties": {
"disk_address": {
"device_index": 1,
"adapter_type": "SCSI"
},
"device_type": "DISK"
},
"uuid": "948915d8-1f99-46f3-a249-39151f3f518a",
"disk_size_bytes": 26484932608,
"disk_size_mib": 25258
}
]
},
"name": "nuran_v3api"
},
"api_version": "3.1",
"metadata": {
"last_update_time": "2018-11-03T00:26:41Z",
"kind": "vm",
"uuid": "042dada0-2f55-4001-a6f1-70d7b88e323c",
"project_reference": {
"kind": "project",
"name": "default",
"uuid": "f86d420a-f601-4ca9-9135-082bc38554c6"
},
"spec_version": 1,
"creation_time": "2018-11-02T20:42:52Z",
"owner_reference": {
"kind": "user",
"uuid": "00000000-0000-0000-0000-000000000000",
"name": "admin"
},
"categories": {}
}
}

 

Now, you can update any parameter in the above, you power on a VM, update its configuration, add new disk etc.
 

 

or another way is by using the Powershell scripts:

Here is a list of entities which you can manage using PowerShell CMDlets: https://portal.nutanix.com/page/documents/details?targetId=API_Ref-Acr_v4_6%3APowerShell_Cmdlets_Reference

 

Also, this PowerShell CMDlets cheatsheet would be useful:
 

 

You can check out the Powershell commands under Acropolis Task administration(2nd column in the above screenshot) to create a new VM, Power it on etc,

 

View original

This topic has been closed for comments

1 reply

Userlevel 6
Badge +5

hey @Balram I don’t think there is any REST API v3 operation specifically related to the VM to power it on, but you can do so using PUT /vms/UUID v3 opeartion 

To update a VM's specs, we need to send an HTTP PUT request to the Prism Central IP. The request body should contain all current specs of the VM. The easiest way to get a VM's specs is to send a GET request to /vms/uuid

Now in the below output of GET operation, Scroll down to the Response Body text box. Find the spec key and copy starting from "spec" down to the last closing curly brace "}". Paste it to a text editor.

For eg-

{
"spec": {
"cluster_reference": {
"kind": "cluster",
"name": "Prolix",
"uuid": "00052c80-729d-8705-0000-0000000051fa"
},
"description": "v3api_vm",
"resources": {
"vnuma_config": {
"num_vnuma_nodes": 0
},
"nic_list": [
{
"ip_endpoint_list": [],
"nic_type": "NORMAL_NIC",
"subnet_reference": {
"kind": "subnet",
"name": "vlan25",
"uuid": "565784d2-7a68-4a16-a1bd-92473760f607"
},
"uuid": "4bff96c1-386e-40bb-bc5b-1dc8a85952af",
"mac_address": "50:6b:8d:b4:76:12"
}
],
"num_vcpus_per_socket": 2,
"num_sockets": 1,
"gpu_list": [],
"memory_size_mib": 4096,
"power_state": "OFF",
"hardware_clock_timezone": "UTC",
"power_state_mechanism": {
"mechanism": "HARD"
},
"vga_console_enabled": true,
"disk_list": [
{
"device_properties": {
"disk_address": {
"device_index": 1,
"adapter_type": "SCSI"
},
"device_type": "DISK"
},
"uuid": "948915d8-1f99-46f3-a249-39151f3f518a",
"disk_size_bytes": 26484932608,
"disk_size_mib": 25258
}
]
},
"name": "nuran_v3api"
},
"api_version": "3.1",
"metadata": {
"last_update_time": "2018-11-03T00:26:41Z",
"kind": "vm",
"uuid": "042dada0-2f55-4001-a6f1-70d7b88e323c",
"project_reference": {
"kind": "project",
"name": "default",
"uuid": "f86d420a-f601-4ca9-9135-082bc38554c6"
},
"spec_version": 1,
"creation_time": "2018-11-02T20:42:52Z",
"owner_reference": {
"kind": "user",
"uuid": "00000000-0000-0000-0000-000000000000",
"name": "admin"
},
"categories": {}
}
}

 

Now, you can update any parameter in the above, you power on a VM, update its configuration, add new disk etc.
 

 

or another way is by using the Powershell scripts:

Here is a list of entities which you can manage using PowerShell CMDlets: https://portal.nutanix.com/page/documents/details?targetId=API_Ref-Acr_v4_6%3APowerShell_Cmdlets_Reference

 

Also, this PowerShell CMDlets cheatsheet would be useful:
 

 

You can check out the Powershell commands under Acropolis Task administration(2nd column in the above screenshot) to create a new VM, Power it on etc,