文档目录

区域相关接口

创建区域(CreateZone)

API请求

URLs
POST zstack/v1/zones
Headers
Authorization: OAuth the-session-uuid
Body
{
"params": {
"name": "TestZone",
"description": "test zone"
  },
"systemTags": [],
"userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"name":"TestZone","description":"test zone"}}' \
http://localhost:8080/zstack/v1/zones
参数列表
名字 类型 位置 描述 可选值 起始版本
name String body(包含在params结构中) 资源名称 0.6
description (可选) String body(包含在params结构中) 资源的详细描述 0.6
resourceUuid (可选) String body(包含在params结构中) 用户指定的资源uuid 0.6
systemTags (可选) List body 系统标签 0.6
userTags (可选) List body 用户标签 0.6

API返回

返回示例

{
"inventory": {
"uuid": "0d26522305c34d07b5661ccda62053c0",
"name": "TestZone",
"description": "Test",
"state": "Enabled",
"type": "zstack",
"createDate": "Jun 7, 2017 9:20:28 PM",
"lastOpDate": "Jun 7, 2017 9:20:28 PM"
  }
}
名字 类型 描述 起始版本
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 0.6
inventory ZoneInventory 详情参考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
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 0.6
name String 资源名称 0.6
description String 资源的详细描述 0.6
state String 0.6
type String 0.6
createDate Timestamp 创建时间 0.6
lastOpDate Timestamp 最后一次修改时间 0.6

SDK示例

Java SDK
CreateZoneAction action = new CreateZoneAction();
action.name = "TestZone";
action.description = "test zone";
action.sessionId = "982a09118de64ef7a9051fde346270c5";
CreateZoneAction.Result res = action.call();
Python SDK
CreateZoneAction action = CreateZoneAction()
action.name = "TestZone"
action.description = "test zone"
action.sessionId = "79e260dca17b4bdf9b7d7b4e150883df"
CreateZoneAction.Result res = action.call()

删除区域(DeleteZone)

API请求

URLs
DELETE zstack/v1/zones/{uuid}?deleteMode={deleteMode}
Headers
Authorization: OAuth the-session-uuid
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 05fc0a34be264877a9dc8dfb5f90d619" \
-X DELETE http://localhost:8080/zstack/v1/zones/d3483ca440334af3acc09d8631e814c6?deleteMode=Permissive
参数列表
名字 类型 位置 描述 可选值 起始版本
uuid String url 资源的UUID,唯一标示该资源 0.6
deleteMode (可选) String body
  • Permissive:如果删除过程中发生错误或者删除不被允许,云平台会停止删除操作;在这种情况下, 包含失败原因的错误代码会被返回。
  • Enforcing:云平台会忽略所有错误和权限而直接删除资源;在这种情况下, 删除操作总是会成功。
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
DeleteZoneAction action = new DeleteZoneAction();
action.uuid = "8987020fccd14191a5a89dda6f3db81e";
action.deleteMode = "Permissive";
action.sessionId = "835b1b72c4554a7e92c425ad9eaebc6d";
DeleteZoneAction.Result res = action.call();
Python SDK
DeleteZoneAction action = DeleteZoneAction()
action.uuid = "a4bcb439c99a42e197cac90be83e706e"
action.deleteMode = "Permissive"
action.sessionId = "6eaf02e52c884e378a3730ce4267d83a"
DeleteZoneAction.Result res = action.call()

查询区域(QueryZone)

API请求

URLs
GET zstack/v1/zones
GET zstack/v1/zones/{uuid}
Headers
Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth e556a104ae874303897ac67d83564086" \
-X GET http://localhost:8080/zstack/v1/zones?q=name=TestZone&q=state=Enabled
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 7e9fd15bba0d43a2b1a7212c85fb8787" \
-X GET http://localhost:8080/zstack/v1/zones/9276d05c7d7545d6b61bfc50f017b86c

可查询字段

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

API返回

返回示例
{
"inventories": [
    {
"uuid": "a58fb4240ed04129a0896b565f24a9df",
"name": "TestZone",
"description": "Test",
"state": "Enabled",
"type": "zstack",
"createDate": "Jun 7, 2017 9:20:29 PM",
"lastOpDate": "Jun 7, 2017 9:20:29 PM"
    }
  ]
}
名字 类型 描述 起始版本
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
state String 0.6
type String 0.6
createDate Timestamp 创建时间 0.6
lastOpDate Timestamp 最后一次修改时间 0.6

SDK示例

Java SDK
QueryZoneAction action = new QueryZoneAction();
action.conditions = asList("name=TestZone","state=Enabled");
action.sessionId = "608079b963b54e8a9aa3a2291adae89f";
QueryZoneAction.Result res = action.call();
Python SDK
QueryZoneAction action = QueryZoneAction()
action.conditions = ["name=TestZone","state=Enabled"]
action.sessionId = "be89929b7fd34d25a5c1a7f47f4490cd"
QueryZoneAction.Result res = action.call()

更新区域(UpdateZone)

更新区域的名称、描述、系统标签或者用户标签。

API请求

URLs
PUT zstack/v1/zones/{uuid}/actions
Headers
Authorization: OAuth the-session-uuid
Body
{
"updateZone": {
"name": "TestZone2",
"description": "test second zone"
  },
"systemTags": [],
"userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"updateZone":{"name":"TestZone2","description":"test second zone"}}' \
http://localhost:8080/zstack/v1/zones/3fc9a2d76b043ead90c537561edcb50e/actions
参数列表
名字 类型 位置 描述 可选值 起始版本
name (可选) String body(包含在updateZone结构中) 资源名称 0.6
description (可选) String body(包含在updateZone结构中) 资源的详细描述 0.6
uuid String url 资源的UUID,唯一标示该资源 0.6
systemTags (可选) List body 系统标签 0.6
userTags (可选) List body 用户标签 0.6

API返回

返回示例
{
"inventory": {
"uuid": "eb5d94d030e84fb286c4f281520b163b",
"name": "TestZone",
"description": "Test",
"state": "Enabled",
"type": "zstack",
"createDate": "Jun 7, 2017 9:20:45 PM",
"lastOpDate": "Jun 7, 2017 9:20:45 PM"
  }
}
名字 类型 描述 起始版本
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 0.6
inventory ZoneInventory 详情参考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
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 0.6
name String 资源名称 0.6
description String 资源的详细描述 0.6
state String 0.6
type String 0.6
createDate Timestamp 创建时间 0.6
lastOpDate Timestamp 最后一次修改时间 0.6

SDK示例

Java SDK
UpdateZoneAction action = new UpdateZoneAction();
action.name = "TestZone2";
action.description = "test second zone";
action.uuid = "e676dc07cbad45ccb96fd6033ed3c72f";
action.sessionId = "14b97d8a960b4c758389f6b6f5930210";
UpdateZoneAction.Result res = action.call();
Python SDK
UpdateZoneAction action = UpdateZoneAction()
action.name = "TestZone2"
action.description = "test second zone"
action.uuid = "20ab7e6d18134e84ac5322741be661ca"
action.sessionId = "8b46ebd366c54b808c63812ecef9fff0"
UpdateZoneAction.Result res = action.call()

改变区域的可用状态(ChangeZoneState)

API请求

URLs
PUT zstack/v1/zones/{uuid}/actions
Headers
Authorization: OAuth the-session-uuid
Body
{
"changeZoneState": {
"stateEvent": "enable"
  },
"systemTags": [],
"userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"changeZoneState":{"stateEvent":"enable"}}' \
http://localhost:8080/zstack/v1/zones/af28b8e014ba35619ab68739fe72c2a3/actions
参数列表
名字 类型 位置 描述 可选值 起始版本
uuid String url 资源的UUID,唯一标示该资源 0.6
stateEvent String body(包含在changeZoneState结构中) 状态触发事件
  • enable
  • disable
0.6
systemTags (可选) List body 系统标签 0.6
userTags (可选) List body 用户标签 0.6

API返回

返回示例
{
"inventory": {
"uuid": "5ea6fdd8a3a24fa2b17b1b89ad29da6b",
"name": "TestZone",
"description": "Test",
"state": "Enabled",
"type": "zstack",
"createDate": "Jun 7, 2017 9:21:08 PM",
"lastOpDate": "Jun 7, 2017 9:21:08 PM"
  }
}
名字 类型 描述 起始版本
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 0.6
inventory ZoneInventory 详情参考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
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 0.6
name String 资源名称 0.6
description String 资源的详细描述 0.6
state String 0.6
type String 0.6
createDate Timestamp 创建时间 0.6
lastOpDate Timestamp 最后一次修改时间 0.6

SDK示例

Java SDK
ChangeZoneStateAction action = new ChangeZoneStateAction();
action.uuid = "61defcb978894aec8839a099bd0eb1a2";
action.stateEvent = "enable";
action.sessionId = "166c291cd367487c9032f4f23531863c";
ChangeZoneStateAction.Result res = action.call();
Python SDK
ChangeZoneStateAction action = ChangeZoneStateAction()
action.uuid = "8feaadcae6f847a7b7fe707d150b7fef"
action.stateEvent = "enable"
action.sessionId = "b6988f47cb2e4a13abe7b2116d3a2a78"
ChangeZoneStateAction.Result res = action.call()
开发手册 | 5.4.12 | ZStack Cloud · ZCF | ZStack 资源中心