文档目录

XML Hook相关接口

创建用户自定义XML Hook (CreateVmUserDefinedXmlHookScript)

API请求

URLs
POST zstack/v1/vm-instances/xml-hook-script
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "name": "hook",
    "description": "xml hook",
    "hookScript": "base64"
  },
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"name":"hook","description":"xml hook","hookScript":"base64"}}' http://localhost:8080/zstack/v1/vm-instances/xml-hook-script
参数列表
名字 类型 位置 描述 可选值 起始版本
name String body(包含在params结构中) 资源名称 5.2.0
description (可选) String body(包含在params结构中) 资源的详细描述 5.2.0
hookScript String body(包含在params结构中) xml hook脚本内容 5.2.0
resourceUuid (可选) String body(包含在params结构中) 资源UUID 5.2.0
tagUuids (可选) List body(包含在params结构中) 标签UUID列表 5.2.0
systemTags (可选) List body 系统标签 5.2.0
userTags (可选) List body 用户标签 5.2.0

API返回

返回示例
{
  "inventory": {}
}
名字 类型 描述 起始版本
success boolean 5.2.0
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 5.2.0
inventory XmlHookInventory 详情参考inventory 5.2.0
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 5.2.0
description String 错误的概要描述 5.2.0
details String 错误的详细信息 5.2.0
elaboration String 保留字段,默认为null 5.2.0
opaque LinkedHashMap 保留字段,默认为null 5.2.0
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 5.2.0
#inventory
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 5.2.0
name String 资源名称 5.2.0
description String 资源的详细描述 5.2.0
hookScript String XML Hook脚本内容 5.2.0
libvirtVersion String Libvirt版本 5.2.0
createDate Timestamp 创建时间 5.2.0
lastOpDate Timestamp 最后一次修改时间 5.2.0
type XmlHookType 详情参考type 5.2.0
#type
名字 类型 描述 起始版本
System XmlHookType 5.2.0
Customization XmlHookType 5.2.0

SDK示例

Java SDK
CreateVmUserDefinedXmlHookScriptAction action = new CreateVmUserDefinedXmlHookScriptAction();
action.name = "hook";
action.description = "xml hook";
action.hookScript = "base64";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
CreateVmUserDefinedXmlHookScriptAction.Result res = action.call();
Python SDK
CreateVmUserDefinedXmlHookScriptAction action = CreateVmUserDefinedXmlHookScriptAction()
action.name = "hook"
action.description = "xml hook"
action.hookScript = "base64"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
CreateVmUserDefinedXmlHookScriptAction.Result res = action.call()

彻底删除用户自定义XML Hook (ExpungeVmUserDefinedXmlHookScript)

API请求

URLs
DELETE zstack/v1/vm-instances/xml-hook-script/{uuid}
Headers
Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X DELETE http://localhost:8080/zstack/v1/vm-instances/xml-hook-script/99df64f50f5b34c6be5a7339d676aeb6
参数列表
名字 类型 位置 描述 可选值 起始版本
uuid String url 资源的UUID,唯一标示该资源 5.2.0
systemTags (可选) List body 系统标签 5.2.0
userTags (可选) List body 用户标签 5.2.0

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
ExpungeVmUserDefinedXmlHookScriptAction action = new ExpungeVmUserDefinedXmlHookScriptAction();
action.uuid = "99df64f50f5b34c6be5a7339d676aeb6";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
ExpungeVmUserDefinedXmlHookScriptAction.Result res = action.call();
Python SDK
ExpungeVmUserDefinedXmlHookScriptAction action = ExpungeVmUserDefinedXmlHookScriptAction()
action.uuid = "99df64f50f5b34c6be5a7339d676aeb6"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
ExpungeVmUserDefinedXmlHookScriptAction.Result res = action.call()

查询用户自定义XML Hook (QueryVmUserDefinedXmlHookScript)

API请求

URLs
GET zstack/v1/vm-instances/xml-hook-script
GET zstack/v1/vm-instances/xml-hook-script/{uuid}
Headers
Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/vm-instances/xml-hook-script?q=uuid=xxx&q=name=xxx
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/vm-instances/xml-hook-script/c2643474f4ca3bb1a5c9e821f53c3ed2

可查询字段

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

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
QueryVmUserDefinedXmlHookScriptAction action = new QueryVmUserDefinedXmlHookScriptAction();
action.conditions = asList("uuid=xxx","name=xxx");
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
QueryVmUserDefinedXmlHookScriptAction.Result res = action.call();
Python SDK
QueryVmUserDefinedXmlHookScriptAction action = QueryVmUserDefinedXmlHookScriptAction()
action.conditions = ["uuid=xxx","name=xxx"]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
QueryVmUserDefinedXmlHookScriptAction.Result res = action.call()

更新用户自定义XML Hook (UpdateVmUserDefinedXmlHookScript)

API请求

URLs
PUT zstack/v1/vm-instances/xml-hook-script
Headers
Authorization: OAuth the-session-uuid
Body
{
  "updateVmUserDefinedXmlHookScript": {
    "uuid": "a44a23f78c9c391c9d2f3a6a576e77d6",
    "name": "example"
  },
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"updateVmUserDefinedXmlHookScript":{"uuid":"a44a23f78c9c391c9d2f3a6a576e77d6","name":"example"}}' http://localhost:8080/zstack/v1/vm-instances/xml-hook-script
参数列表
名字 类型 位置 描述 可选值 起始版本
uuid String body(包含在updateVmUserDefinedXmlHookScript结构中) 资源的UUID,唯一标示该资源 5.2.0
name (可选) String body(包含在updateVmUserDefinedXmlHookScript结构中) 资源名称 5.2.0
description (可选) String body(包含在updateVmUserDefinedXmlHookScript结构中) 资源的详细描述 5.2.0
hookScript (可选) String body(包含在updateVmUserDefinedXmlHookScript结构中) XML Hook 脚本内容 5.2.0
systemTags (可选) List body 系统标签 5.2.0
userTags (可选) List body 用户标签 5.2.0
startupStrategy (可选) String body(包含在updateVmUserDefinedXmlHookScript结构中) 启动策略
  • Reboot
  • None
5.2.0

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
UpdateVmUserDefinedXmlHookScriptAction action = new UpdateVmUserDefinedXmlHookScriptAction();
action.uuid = "a44a23f78c9c391c9d2f3a6a576e77d6";
action.name = "example";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
UpdateVmUserDefinedXmlHookScriptAction.Result res = action.call();
Python SDK
UpdateVmUserDefinedXmlHookScriptAction action = UpdateVmUserDefinedXmlHookScriptAction()
action.uuid = "a44a23f78c9c391c9d2f3a6a576e77d6"
action.name = "example"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
UpdateVmUserDefinedXmlHookScriptAction.Result res = action.call()

挂载用户自定义XML Hook到云主机 (AttachUserDefinedXmlHookScriptToVm)

API请求

URLs
POST zstack/v1/xmlhook/{xmlHookUuid}/vm-instances/{vmInstanceUuid}
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "startupStrategy": "None"
  },
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"startupStrategy":"None"}}' http://localhost:8080/zstack/v1/xmlhook/73300c2b203e3e43bc4b0dec7c3b0f21/vm-instances/6baaffd8cb123dcc954b6242835267b9
参数列表
名字 类型 位置 描述 可选值 起始版本
vmInstanceUuid String url 云主机UUID 5.2.0
xmlHookUuid String url xml hook UUID 5.2.0
startupStrategy (可选) String body(包含在params结构中) 启动策略
  • Reboot
  • None
5.2.0
systemTags (可选) List body 系统标签 5.2.0
userTags (可选) List body 用户标签 5.2.0

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
AttachUserDefinedXmlHookScriptToVmAction action = new AttachUserDefinedXmlHookScriptToVmAction();
action.vmInstanceUuid = "6baaffd8cb123dcc954b6242835267b9";
action.xmlHookUuid = "73300c2b203e3e43bc4b0dec7c3b0f21";
action.startupStrategy = "None";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
AttachUserDefinedXmlHookScriptToVmAction.Result res = action.call();
Python SDK
AttachUserDefinedXmlHookScriptToVmAction action = AttachUserDefinedXmlHookScriptToVmAction()
action.vmInstanceUuid = "6baaffd8cb123dcc954b6242835267b9"
action.xmlHookUuid = "73300c2b203e3e43bc4b0dec7c3b0f21"
action.startupStrategy = "None"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
AttachUserDefinedXmlHookScriptToVmAction.Result res = action.call()

从云主机卸载用户自定义XML Hook (DetachUserDefinedXmlHookScriptFromVm)

API请求

URLs
DELETE zstack/v1/xmlhook/vm-instances/{vmInstanceUuid}/detach
Headers
Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X DELETE http://localhost:8080/zstack/v1/xmlhook/vm-instances/588ac603fdd73c7c8519235a73271188/detach
参数列表
名字 类型 位置 描述 可选值 起始版本
vmInstanceUuid String url 云主机UUID 5.2.0
startupStrategy (可选) String body 启动策略
  • Reboot
  • None
5.2.0
deleteMode (可选) String body 删除模式
  • Permissive
  • Enforcing,Permissive
5.2.0
systemTags (可选) List body 系统标签 5.2.0
userTags (可选) List body 用户标签 5.2.0

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
DetachUserDefinedXmlHookScriptFromVmAction action = new DetachUserDefinedXmlHookScriptFromVmAction();
action.vmInstanceUuid = "588ac603fdd73c7c8519235a73271188";
action.startupStrategy = "None";
action.deleteMode = "Permissive";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
DetachUserDefinedXmlHookScriptFromVmAction.Result res = action.call();
Python SDK
DetachUserDefinedXmlHookScriptFromVmAction action = DetachUserDefinedXmlHookScriptFromVmAction()
action.vmInstanceUuid = "588ac603fdd73c7c8519235a73271188"
action.startupStrategy = "None"
action.deleteMode = "Permissive"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
DetachUserDefinedXmlHookScriptFromVmAction.Result res = action.call()
开发手册 | 5.4.12 | ZStack Cloud · ZCF | ZStack 资源中心