解决了

通过REST接口创建虚拟机后,虚拟机处于下电状态

  • 2021年1月28日
  • 1回复
  • 232的浏览量

徽章 +1

用于创建虚拟机克隆的REST API工作正常,但在虚拟机克隆之后。它处于断电状态。

有没有办法通过API 3设置电源状态(在API 2中有,但它是旧的和不支持的)

任何其他方式来创建虚拟机或克隆,以便它将在虚拟机创建后处于开机状态。

图标

最佳答案AnishWalia202021年1月28日07:03

hey\u00a0@Balram<\/user-mention>\u00a0I don\u2019t think there is any REST API v3\u00a0operation specifically related to the VM to power it on, but you can do so using PUT \/vms\/UUID v3 opeartion\u00a0<\/strong><\/a><\/p>

To update a VM's specs, we need to send an HTTP PUT request to the Prism Central IP. The request\u00a0body<\/strong>\u00a0should 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<\/strong><\/a><\/p>

Now in the below output of GET operation,\u00a0Scroll down to the\u00a0Response Body<\/strong>\u00a0text box. Find the\u00a0spec\u00a0key and copy starting from \"spec<\/strong>\" down to the last closing curly brace \"}\". Paste it to a text editor.<\/p>

For eg-<\/p>

{
\"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\": {}
}
}<\/code><\/pre>

\u00a0<\/p>

Now, you can update any parameter in the above, you power on a VM, update its\u00a0configuration, add new disk etc.
\u00a0<\/p>

\u00a0<\/p>

or\u00a0another way is by using the Powershell scripts:<\/p>

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

\u00a0<\/p>

Also, this\u00a0PowerShell CMDlets cheatsheet would\u00a0be useful:
\u00a0<\/p>

\"//www.jhbzcj.com/next/prism-for-infra-and-it-ops-26/\"<\/figure>

\u00a0<\/p>

You can check out the Powershell commands under\u00a0Acropolis Task administration(2nd column in the above screenshot)<\/strong>\u00a0to create a new VM, Power it on etc,<\/p>

\u00a0<\/p>","className":"post__content__best_answer"}">

查看原始

本主题已关闭供评论

1回复

Userlevel 6
徽章 +5

@Balram我不认为有任何REST API v3操作专门与VM相关来启动它,但你可以使用PUT /vms/UUID v3操作

为了更新VM的规格,我们需要向Prism Central IP发送一个HTTP PUT请求。请求身体应该包含虚拟机的所有当前规格。获取虚拟机规格的最简单方法是发送一个GET请求到/vms/uuid

现在在下面的GET操作输出中,向下滚动到身体的反应文本框中。找到规格键并从"规范"直到最后一个右花括号"}"。将其粘贴到文本编辑器中。

如-


"规范":{
" cluster_reference ": {
“类型”:“集群”,
“名称”:“冗长的”,
“uuid”:“00052 c80 - 729 d - 8705 - 0000 - 0000000051 - fa”
},
“描述”:“v3api_vm”,
"资源":{
" vnuma_config ": {
“num_vnuma_nodes”:0
},
“nic_list”:(

“ip_endpoint_list”:[],
:“nic_type NORMAL_NIC”,
" subnet_reference ": {
“类型”:“子网”,
“名称”:“vlan25”,
“uuid”:“565784 d2 - 7 - a68 4 - a16 a1bd - 92473760 f607”
},
:“uuid 4 bff96c1 - 386 e - 40 - bb - bc5b - 1 - dc8a85952af”,
:“mac_address 50:6b: 8 d: b4:76:12”

],
“num_vcpus_per_socket”:2
“num_sockets”:1、
“gpu_list”:[],
“memory_size_mib”:4096年,
“power_state”:“关闭”,
:“hardware_clock_timezone UTC”,
" power_state_mechanism ": {
“机制”:“硬”
},
“vga_console_enabled”:没错,
“disk_list”:(

" device_properties ": {
" disk_address ": {
“device_index”:1、
:“adapter_type SCSI”
},
“device_type”:“磁盘”
},
“uuid”:“948915 d8 - 1 - f99 - 46 - f3 - a249 - 39151 - f3f518a”,
“disk_size_bytes”:26484932608,
“disk_size_mib”:25258


},
“名称”:“nuran_v3api”
},
“api_version”:“3.1”,
“元数据”:{
“last_update_time”:“2018 - 11 - 03 t00:26:41z”,
“类型”:“虚拟机”,
“uuid”:“042 dada0 - 2 f55 - 4001 a6f1 - 70 d7b88e323c”,
" project_reference ": {
“类型”:“项目”,
“名称”:“默认”,
:“uuid f86d420a f601 - 4 ca9 - 9135 - 082 - bc38554c6”
},
“spec_version”:1、
“creation_time”:“2018 - 11 - 02年t20:42:52z”,
" owner_reference ": {
“类型”:“用户”,
“uuid”:“00000000-0000-0000-0000-000000000000”,
“名称”:“admin”
},
“类别”:{}

现在,你可以更新上面的任何参数,你可以打开一个虚拟机,更新它的配置,添加新的磁盘等等。

或者另一种方法是使用Powershell脚本:

以下是你可以使用PowerShell CMDlets管理的实体列表:https://portal.nutanix.com/page/documents/details?targetId=API_Ref-Acr_v4_6%3APowerShell_Cmdlets_Reference

此外,这个PowerShell CMDlets备要表将是有用的:

您可以在下面查看Powershell命令Acropolis任务管理(上图第二列)创建一个新的虚拟机,Power it on等,

Baidu