查询虚拟机
Headers
Authorization: OAuth the-session-uuidCurl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/vm-instances?q=name=vm1&q=vmNics.ip=192.168.20.100curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/vm-instances/72573bf842273c02a09f33dc061bb6f8可查询字段
运行CLI命令行工具,输入QueryVmInstance并按Tab键查看所有可查询字段以及可跨表查询的资源名。
API返回
返回示例
{
"inventories": [
{
"uuid": "a43716db0d713c319be06811ebcc00a1",
"name": "Test-VM",
"description": "web server VM",
"zoneUuid": "dfa731eef1f13f1da298855d6ce282bd",
"clusterUuid": "743b07830cb6324192a2e0cc34186814",
"imageUuid": "ea51c3f89cb53b0db4abdd648c476f80",
"hostUuid": "d808c413110a32cab4d9c4d034818eb0",
"lastHostUuid": "3da349b211ba3cebb5629c0f90aadf63",
"instanceOfferingUuid": "1a3f2ce111cf318688f7bb0cc217d5ff",
"rootVolumeUuid": "b677bd698e1d3e4b9787fa81827d13d4",
"platform": "Linux",
"defaultL3NetworkUuid": "3bcc70b465c4371b8a7f9bd975fdec76",
"type": "UserVm",
"hypervisorType": "KVM",
"memorySize": 8589934592,
"cpuNum": 1,
"allocatorStrategy": "LastHostPreferredAllocatorStrategy",
"createDate": "Nov 14, 2017 10:20:57 PM",
"lastOpDate": "Nov 14, 2017 10:20:57 PM",
"state": "Running",
"vmNics": [
{
"uuid": "39da5aec41f336929db3458395614151",
"vmInstanceUuid": "a43716db0d713c319be06811ebcc00a1",
"usedIpUuid": "69008cc8dbd03aeba1787ec024a0b326",
"l3NetworkUuid": "3bcc70b465c4371b8a7f9bd975fdec76",
"ip": "192.168.1.10",
"mac": "00:0c:29:bd:99:fc",
"hypervisorType": "KVM",
"netmask": "255.255.255.0",
"gateway": "192.168.1.1",
"deviceId": 0,
"state": "enable",
"createDate": "Nov 14, 2017 10:20:57 PM",
"lastOpDate": "Nov 14, 2017 10:20:57 PM"
}
],
"allVolumes": [
{
"uuid": "b677bd698e1d3e4b9787fa81827d13d4",
"name": "Root-Volume-For-VM-a43716db0d713c319be06811ebcc00a1",
"primaryStorageUuid": "413b0d61df4e3b088f5ee045ff84b65b",
"vmInstanceUuid": "a43716db0d713c319be06811ebcc00a1",
"diskOfferingUuid": "37c73ea89a2b3a7bb7126f5fe7a32dc6",
"rootImageUuid": "ea51c3f89cb53b0db4abdd648c476f80",
"installPath": "/zstack_ps/rootVolumes/acct-36c27e8ff05c4780bf6d2fa65700f22e/vol-b677bd698e1d3e4b9787fa81827d13d4/b677bd698e1d3e4b9787fa81827d13d4.qcow2",
"type": "Root",
"format": "qcow2",
"size": 107374182400,
"actualSize": 21474836480,
"deviceId": 0,
"state": "Enabled",
"status": "Ready",
"createDate": "Nov 14, 2017 10:20:57 PM",
"lastOpDate": "Nov 14, 2017 10:20:57 PM"
}
]
}
]
}| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| success | boolean | 0.6 | |
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 0.6 |
| inventories | List | 详情参考inventories | 0.6 |
error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
inventories
名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
name | String | 资源名称 | 0.6 |
description | String | 资源的详细描述 | 0.6 |
zoneUuid | String | 数据中心UUID | 0.6 |
clusterUuid | String | 集群UUID | 0.6 |
imageUuid | String | 镜像UUID | 0.6 |
hostUuid | String | 主机UUID | 0.6 |
lastHostUuid | String |
| 0.6 |
instanceOfferingUuid | String | 计算规格UUID | 0.6 |
rootVolumeUuid | String | 根硬盘UUID | 0.6 |
platform | String |
| 0.6 |
architecture | String | 架构类型 | 4.5.0 |
defaultL3NetworkUuid | String |
| 0.6 |
type | String | 虚拟机类型,包括:- UserVm
| 0.6 |
hypervisorType | String |
| 0.6 |
memorySize | Long |
| 0.6 |
cpuNum | Integer |
| 0.6 |
cpuSpeed | Long |
| 0.6 |
allocatorStrategy | String |
| 0.6 |
createDate | Timestamp | 创建时间 | 0.6 |
lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
state | String | 虚拟机状态,包括:- Created
| 0.6 |
guestOsType | String | 操作系统类型 | 4.5.0 |
vmNics | List | 详情参考vmNics | 0.6 |
allVolumes | List | 详情参考allVolumes | 0.6 |
vmCdRoms | List | 详情参考vmCdRoms | 4.5.0 |
vmNics
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| vmInstanceUuid | String | 虚拟机UUID | 0.6 |
| l3NetworkUuid | String | 分布式端口组UUID | 0.6 |
| ip | String | IP地址 | 0.6 |
| mac | String | MAC地址 | 0.6 |
| hypervisorType | String | 虚拟化类型 | 0.6 |
| netmask | String | 子网掩码 | 0.6 |
| gateway | String | 网关 | 0.6 |
| metaData | String | 0.6 | |
| ipVersion | Integer | IP地址版本 | 0.6 |
| driverType | String | 4.7.13 | |
| internalName | String | 4.7.13 | |
| deviceId | Integer | 设备ID | 0.6 |
| type | String | 网卡类型 | 0.6 |
| state | String | 网卡状态 | 4.7.13 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
| usedIps | List | 详情参考usedIps | 0.6 |
usedIps
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| ipRangeUuid | String | IP段UUID | 0.6 |
| l3NetworkUuid | String | 分布式端口组UUID | 0.6 |
| ipVersion | Integer | IP协议号 | 3.1 |
| ip | String | IP地址 | 0.6 |
| netmask | String | 网络掩码 | 0.6 |
| gateway | String | 网关地址 | 0.6 |
| usedFor | String | 0.6 | |
| ipInLong | long | 0.6 | |
| vmNicUuid | String | 虚拟机网卡UUID | 3.1 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
allVolumes
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| name | String | 资源名称 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| primaryStorageUuid | String | 数据存储UUID | 0.6 |
| vmInstanceUuid | String | 虚拟机UUID | 0.6 |
| diskOfferingUuid | String | 硬盘规格UUID | 0.6 |
| rootImageUuid | String | 硬盘根镜像UUID | 0.6 |
| installPath | String | 硬盘在数据存储上的路径 | 0.6 |
| type | String | 硬盘类型,数据硬盘/根硬盘 | 0.6 |
| format | String | 硬盘格式 | 0.6 |
| size | Long | 硬盘大小 | 0.6 |
| actualSize | Long | 硬盘真实大小 | 0.6 |
| deviceId | Integer | 0.6 | |
| state | String | 硬盘是否开启 | 0.6 |
| status | String | 硬盘状态 | 0.6 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
| isShareable | Boolean | 是否共享硬盘 | 0.6 |
| volumeQos | String | 硬盘Qos,格式如total=1048576 | 3.2.0 |
| lastDetachDate | Timestamp | 4.7.13 | |
| lastVmInstanceUuid | String | 4.7.13 |
vmCdRoms
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 4.5.0 |
| vmInstanceUuid | String | 虚拟机UUID | 4.5.0 |
| deviceId | Integer | 光驱顺序号 | 4.5.0 |
| isoUuid | String | ISO镜像UUID | 4.5.0 |
| isoInstallPath | String | ISO镜像挂载路径 | 4.5.0 |
| name | String | 资源名称 | 4.5.0 |
| description | String | 资源的详细描述 | 4.5.0 |
| createDate | Timestamp | 创建时间 | 4.5.0 |
| lastOpDate | Timestamp | 最后一次修改时间 | 4.5.0 |
SDK示例
Java SDK
QueryVmInstanceAction action = new QueryVmInstanceAction();
action.conditions = asList("name=vm1","vmNics.ip=192.168.20.100");
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
QueryVmInstanceAction.Result res = action.call();Python SDK
action = QueryVmInstanceAction()
action.conditions = ["name=vm1","vmNics.ip=192.168.20.100"]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
res = action.call()