查询物理机(QueryHost)

API请求

URLs
GET zstack/v1/hosts
GET zstack/v1/hosts/{uuid}
Headers
Authorization: OAuth the-session-uuid
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 99a86d711f154752b52a7de2b3c43a63" \
-X GET http://localhost:8080/zstack/v1/hosts?q=uuid=66547f0fc9fd45d98f6b8482488f2993
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth bd46777b8a8c4616a64f0cdbcf1bf98e" \
-X GET http://localhost:8080/zstack/v1/hosts/bb582f21cfad4f61a2ab1ec062131b4a

可查询字段

运行CLI命令行工具,输入QueryHost并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例
{
  "inventories": [
    {
      "zoneUuid": "37649b12f572303a883c19c4c7af0856",
      "name": "example",
      "uuid": "f7bae73b9874344b8766dfcdda48ad6e",
      "clusterUuid": "d59c027b81fe3bbc9d78ef45f574febb",
      "description": "example",
      "managementIp": "192.168.0.1",
      "hypervisorType": "KVM",
      "state": "Enabled",
      "status": "Connected",
      "totalCpuCapacity": 4.0,
      "availableCpuCapacity": 2.0,
      "cpuSockets": 4.0,
      "totalMemoryCapacity": 1840414720,
      "availableMemoryCapacity": 1840414720,
      "cpuNum": 4.0
    }
  ]
}
名字 类型 描述 起始版本
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
名字 类型 描述 起始版本
zoneUuid String 区域UUID 0.6
name String 资源名称 0.6
uuid String 资源的UUID,唯一标示该资源 0.6
clusterUuid String 集群UUID 0.6
description String 资源的详细描述 0.6
managementIp String 0.6
hypervisorType String 0.6
state String 物理机状态,包括:
  • Enabled
  • Disabled
  • PreMaintenance
  • Maintenance
0.6
status String
  • Connecting
  • Connected
  • Disconnected
0.6
totalCpuCapacity Long 0.6
availableCpuCapacity Long 0.6
cpuSockets Integer 0.6
totalMemoryCapacity Long 0.6
availableMemoryCapacity Long 0.6
cpuNum Integer 0.6
createDate Timestamp 创建时间 0.6
lastOpDate Timestamp 最后一次修改时间 0.6
Note: 物理机状态变更总结如下:
  • Enabled 可以转换到 Disabled, PreMaintenance;
  • Disabled 可以转换到 Enabled, PreMaintenance;
  • PreMaintenance 可以转换到 Disabled, Enabled, Maintenance;
  • Maintenance 可以转换到 Disabled, Enabled。

SDK示例

Java SDK
QueryHostAction action = new QueryHostAction();
action.conditions = asList("uuid=fb0510cd5bf04565be44c43da20169c7");
action.sessionId = "d69767ca64854cfb99960282fcdb8aed";
QueryHostAction.Result res = action.call();
Python SDK
QueryHostAction action = QueryHostAction()
action.conditions = ["uuid=2ddc05f8f46b4d5ab40053fdb72ae69d"]
action.sessionId = "96b183220af446c39d7cf2674761d85e"
QueryHostAction.Result res = action.call()