集群相关接口
创建一个集群(CreateCluster)
API请求
URLs
POST zstack/v1/clustersHeaders
Authorization: OAuth the-session-uuidBody
{
"params": {
"zoneUuid": "d5629a75f0a24280ac669d93d38a7dcd",
"name": "cluster1",
"description": "test",
"hypervisorType": "KVM"
},
"systemTags": [],
"userTags": []
}Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"zoneUuid":"e1fb7d87073b397c857eaeeb16243103","name":"cluster1","description":"test","hypervisorType":"KVM"}}' \
http://localhost:8080/zstack/v1/clusters参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| zoneUuid | String | body(包含在params结构中) | 区域UUID | 0.6 | |
| name | String | body(包含在params结构中) | 资源名称 | 0.6 | |
| description (可选) | String | body(包含在params结构中) | 资源的详细描述 | 0.6 | |
| hypervisorType | String | body(包含在params结构中) | 虚拟机管理程序类型 |
|
4.0.0 |
| type (可选) | String | body(包含在params结构中) | 保留域, 请不要使用 |
|
0.6 |
| resourceUuid (可选) | String | body(包含在params结构中) |
|
0.6 | |
| architecture (可选) | String | body(包含在params结构中) |
|
4.0.0 | |
| tagUuids (可选) | List | body(包含在params结构中) | 4.0.0 | ||
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
返回示例
{
"inventory": {
"name": "cluster1",
"uuid": "dc7442bb39674d779d688369329ba845",
"description": "test",
"state": "Enabled",
"hypervisorType": "KVM",
"createDate": "Jun 7, 2017 9:20:31 PM",
"lastOpDate": "Jun 7, 2017 9:20:31 PM",
"zoneUuid": "342b68c14869412984d6327a58b18f9b",
"type": "zstack"
}
}| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 0.6 |
| inventory | ClusterInventory | 详情参考inventory | 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 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| name | String | 资源名称 | 0.6 |
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| state | String | 集群状态 | 0.6 |
| hypervisorType | String | 虚拟机管理程序类型 | 0.6 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
| zoneUuid | String | 区域UUID | 0.6 |
| type | String | 保留域 | 0.6 |
SDK示例
Java
SDK
CreateClusterAction action = new CreateClusterAction();
action.zoneUuid = "70fd596da027478eb22ac9357aed23f4";
action.name = "cluster1";
action.description = "test";
action.hypervisorType = "KVM";
action.sessionId = "894477861bcc45488978b584908e4ee3";
CreateClusterAction.Result res = action.call();Python
SDK
CreateClusterAction action = CreateClusterAction()
action.zoneUuid = "cfe698802c87486986878daa2da7e02f"
action.name = "cluster1"
action.description = "test"
action.hypervisorType = "KVM"
action.sessionId = "0664130c5d36414bbb3a7a59ef87ea5a"
CreateClusterAction.Result res = action.call()删除一个集群(DeleteCluster)
API请求
URLs
DELETE zstack/v1/clusters/{uuid}?deleteMode={deleteMode}Headers
Authorization: OAuth the-session-uuidCurl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth d55b1a48ad2348ceb3bea95b407a8bde" \
-X DELETE http://localhost:8080/zstack/v1/clusters/a5bb7e5ca83f41748538d953709ba3c3?deleteMode=Permissive参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| uuid | String | url | 资源的UUID,唯一标示该资源 | 0.6 | |
| deleteMode (可选) | String | body | 删除模式 | 0.6 | |
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:
{
"error": {
"code": "SYS.1001",
"description": "A message or a operation timeout",
"details": "Create VM on KVM timeout after 300s"
}
}
SDK示例
Java
SDK
DeleteClusterAction action = new DeleteClusterAction();
action.uuid = "51b6e91ce692487ea582418f52835061";
action.deleteMode = "Permissive";
action.sessionId = "41695ae924854a3abfc1e681e092f744";
DeleteClusterAction.Result res = action.call();Python
SDK
DeleteClusterAction action = DeleteClusterAction()
action.uuid = "2e9d94bbe3d240d3a660e86a7cd6aff8"
action.deleteMode = "Permissive"
action.sessionId = "386fba061d404eeb830a772e31fd4faf"
DeleteClusterAction.Result res = action.call()查询集群(QueryCluster)
API请求
URLs
GET zstack/v1/clusters
GET zstack/v1/clusters/{uuid}Headers
Authorization: OAuth the-session-uuidCurl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 815c808ecfb5461b953544d4bcefea31" \
-X GET http://localhost:8080/zstack/v1/clusters?q=hypervisorType=KVMcurl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 663eef55906d4b6e9750f9b4ed65f5f9" \
-X GET http://localhost:8080/zstack/v1/clusters/a8d5ea1ceda34616a26bec2fce3b4d8a可查询字段
运行CLI命令行工具,输入QueryCluster并按Tab键查看所有可查询字段以及可跨表查询的资源名。
API返回
返回示例
{
"inventories": [
{
"name": "cluster1",
"uuid": "41f3a4eb130347a2af6d7f2e0d21fab0",
"description": "test",
"state": "Enabled",
"hypervisorType": "KVM",
"createDate": "Jun 7, 2017 9:20:13 PM",
"lastOpDate": "Jun 7, 2017 9:20:13 PM",
"zoneUuid": "aad01c8b25774796b2e341ec51a7c9c1",
"type": "zstack"
}
]
}| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| 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
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| name | String | 资源名称 | 0.6 |
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| state | String | 集群状态 | 0.6 |
| hypervisorType | String | 虚拟机管理程序类型 | 0.6 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
| zoneUuid | String | 区域UUID | 0.6 |
| type | String | 保留域 | 0.6 |
SDK示例
Java
SDK
QueryClusterAction action = new QueryClusterAction();
action.conditions = asList("hypervisorType=KVM");
action.sessionId = "3e214b652cc947ea9e1aa256d05752ea";
QueryClusterAction.Result res = action.call();Python
SDK
QueryClusterAction action = QueryClusterAction()
action.conditions = ["hypervisorType=KVM"]
action.sessionId = "ad8f3cd4b5bc4da0a3a91dc8bcbdd18c"
QueryClusterAction.Result res = action.call()更新集群(UpdateCluster)
API请求
URLs
PUT zstack/v1/clusters/{uuid}/actionsHeaders
Authorization: OAuth the-session-uuidBody
{
"updateCluster": {
"name": "cluster1",
"description": "test"
},
"systemTags": [],
"userTags": []
}Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"updateCluster":{"name":"cluster1","description":"test"}}' \
http://localhost:8080/zstack/v1/clusters/851a3783e1503de2a1b9222014c843c4/actions参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| uuid | String | url | 资源的UUID,唯一标示该资源 | 0.6 | |
| name (可选) | String | body(包含在updateCluster结构中) | 资源名称 | 0.6 | |
| description (可选) | String | body(包含在updateCluster结构中) | 资源的详细描述 | 0.6 | |
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
返回示例
{
"inventory": {
"name": "cluster1",
"uuid": "9dd0fbecb0e04260ad161c66d1da9f96",
"description": "test",
"state": "Enabled",
"hypervisorType": "KVM",
"createDate": "Jun 7, 2017 9:20:29 PM",
"lastOpDate": "Jun 7, 2017 9:20:29 PM",
"zoneUuid": "25b7ddce968f4cbbb58aa5a205e116ee",
"type": "zstack"
}
}| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 0.6 |
| inventory | ClusterInventory | 详情参考inventory | 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 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| name | String | 资源名称 | 0.6 |
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| state | String | 集群状态 | 0.6 |
| hypervisorType | String | 虚拟机管理程序类型 | 0.6 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
| zoneUuid | String | 区域UUID | 0.6 |
| type | String | 保留域 | 0.6 |
SDK示例
Java
SDK
UpdateClusterAction action = new UpdateClusterAction();
action.uuid = "ce185b26a4f14153941a868435d94498";
action.name = "cluster1";
action.description = "test";
action.sessionId = "5abfadbc97d64b4687ba6281de117d2d";
UpdateClusterAction.Result res = action.call();Python
SDK
UpdateClusterAction action = UpdateClusterAction()
action.uuid = "a643ba1b98524c60acced530ce2ded1b"
action.name = "cluster1"
action.description = "test"
action.sessionId = "cc779e5d5344493d9bd1cb1ced887321"
UpdateClusterAction.Result res = action.call()改变一个集群的可用状态(ChangeClusterState)
API请求
URLs
PUT zstack/v1/clusters/{uuid}/actionsHeaders
Authorization: OAuth the-session-uuid
Body
{
"changeClusterState": {
"stateEvent": "disable"
},
"systemTags": [],
"userTags": []
}Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"changeClusterState":{"stateEvent":"disable"}}' \
http://localhost:8080/zstack/v1/clusters/652ee5e996203bfbb5eb75e750720093/actions参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| uuid | String | url | 资源的UUID,唯一标示该资源 | 0.6 | |
| stateEvent | String | body(包含在changeClusterState结构中) | 可用状态触发事件 |
|
0.6 |
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
返回示例
{
"inventory": {
"name": "cluster1",
"uuid": "2cebd4274c7c4550add1ee3620b52a81",
"description": "test",
"state": "Enabled",
"hypervisorType": "KVM",
"createDate": "Jun 7, 2017 9:20:25 PM",
"lastOpDate": "Jun 7, 2017 9:20:25 PM",
"zoneUuid": "90eb72b73e144650990db2aa1ddee7c1",
"type": "zstack"
}
}| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 0.6 |
| inventory | ClusterInventory | 详情参考inventory | 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 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| name | String | 资源名称 | 0.6 |
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| description | String | 资源的详细描述 | 0.6 |
| state | String | 集群状态 | 0.6 |
| hypervisorType | String | 虚拟机管理程序类型 | 0.6 |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
| zoneUuid | String | 区域UUID | 0.6 |
| type | String | 保留域 | 0.6 |
SDK示例
Java
SDK
ChangeClusterStateAction action = new ChangeClusterStateAction();
action.uuid = "b97eb5ab5e264edbad128090b0ac28c2";
action.stateEvent = "disable";
action.sessionId = "79368b716c6a4d5db37fc7c601bf14cc";
ChangeClusterStateAction.Result res = action.call();Python
SDK
ChangeClusterStateAction action = ChangeClusterStateAction()
action.uuid = "24f520e8991d464eaf2ed9b1e55996a3"
action.stateEvent = "disable"
action.sessionId = "11db5049d24342e7af8b1a3992484184"
ChangeClusterStateAction.Result res = action.call()升级集群内物理机的操作系统(UpdateClusterOS)
API请求
URLs
PUT zstack/v1/clusters/{uuid}/actionsHeaders
Authorization: OAuth the-session-uuidBody
{
"updateClusterOS": {
"excludePackages": [
"kernel",
"systemd*"
],
"updatePackages": [
"zstack-release"
],
"releaseVersion": "c74",
"force": false
},
"systemTags": [],
"userTags": []
}
Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"updateClusterOS":{"excludePackages":["kernel","systemd*"],"updatePackages":["zstack-release"],"releaseVersion":"c74","force":false}}' http://localhost:8080/zstack/v1/clusters/31c4951f39ae38969802e833448369ae/actions参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| uuid | String | url | 资源的UUID,唯一标示该资源 | 2.3 | |
| excludePackages (可选) | List | body(包含在updateClusterOS结构中) | 不升级的包列表 | 3.7.0 | |
| updatePackages (可选) | List | body(包含在updateClusterOS结构中) | 要升级的包列表 | 3.7.0 | |
| releaseVersion (可选) | String | body(包含在updateClusterOS结构中) | 升级所用源的版本 | 3.7.0 | |
| resourceUuid (可选) | String | body(包含在updateClusterOS结构中) | 3.7.0 | ||
| tagUuids (可选) | List | body(包含在updateClusterOS结构中) | 标签UUID列表 | 3.7.0 | |
| systemTags (可选) | List | body | 系统标签 | 2.3 | |
| userTags (可选) | List | body | 用户标签 | 2.3 | |
| force (可选) | boolean | body(包含在updateClusterOS结构中) | 强制 |
|
5.2.0 |
API返回
返回示例
{
"inventory": {
"uuid": "932696598b64375ea4ae6226cc0c1407"
}
}| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| success | boolean | 0.6 | |
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 2.3 |
| inventory | LongJobInventory | 详情参考inventory | 2.2 |
#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 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 2.2.4 |
| name | String | 资源名称 | 2.2.4 |
| description | String | 资源的详细描述 | 2.2.4 |
| apiId | String | 用于关联TaskProgress的APIID | 2.2.4 |
| jobName | String | 任务名称 | 2.2.4 |
| jobData | String | 任务数据 | 2.2.4 |
| jobResult | String | 任务结果 | 2.2.4 |
| targetResourceUuid | String | 目标资源UUID | 2.2.4 |
| managementNodeUuid | String | 管理节点UUID | 2.2.4 |
| createDate | Timestamp | 创建时间 | 2.2.4 |
| lastOpDate | Timestamp | 最后一次修改时间 | 2.2.4 |
| executeTime | Long | 3.7.0 | |
| state | LongJobState | 详情参考state | 2.2.4 |
#state
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| name | String | 资源名称 | 2.24 |
| ordinal | int | 2.2.4 |
SDK示例
Java
SDK
UpdateClusterOSAction action = new UpdateClusterOSAction();
action.uuid = "31c4951f39ae38969802e833448369ae";
action.excludePackages = asList("kernel","systemd*");
action.updatePackages = asList("zstack-release");
action.releaseVersion = "c74";
action.force = false;
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
UpdateClusterOSAction.Result res = action.call();
Python
SDK
UpdateClusterOSAction action = UpdateClusterOSAction()
action.uuid = "31c4951f39ae38969802e833448369ae"
action.excludePackages = [kernel, systemd*]
action.updatePackages = [zstack-release]
action.releaseVersion = "c74"
action.force = false
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
UpdateClusterOSAction.Result res = action.call()
