Document navigation

XML Hook

CreateVmUserDefinedXmlHookScript

API Request

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": []
}

In the preceding sample, both systemTags and userTags are optional. These two fields can be included in the body structure.

Curl Sample

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

Request Parameters

Name Type Location Description Valid Values Starting Version
name String body (contained in the params structure) The XML Hook name. 5.2.0
description String body (contained in the params structure) Optional. The detailed information of the XML Hook. 5.2.0
hookScript String body (contained in the params structure) The XML Hook content. 5.2.0
resourceUuid String body (contained in the params structure) Optional. The resource UUID. 5.2.0
tagUuids List body (contained in the params structure) Optional. The tag UUID list. 5.2.0
systemTags List body Optional. The system tags. 5.2.0
userTags List body Optional. The user tags. 5.2.0

API Response

Sample Response

{
  "inventory": {}
}
Name Type Description Starting Version
success boolean Whether the operation succeeded. 5.2.0
error ErrorCode The error code. If not null, the operation fails, or vice versa. For more information, see error 5.2.0
inventory XmlHookInventory See inventory 5.2.0

#error

Name Type Description Starting Version
code String The error code, which is a numbered or alphanumeric code that specifies an error. For example, SYS.1000, HOST.1001. 5.2.0
description String The brief description of the error. 5.2.0
details String The details about the error. 5.2.0
elaboration String The reserved field. Default value: null. 5.2.0
opaque LinkedHashMap The reserved field. Default value: null. 5.2.0
cause ErrorCode The root error, which is the associated root cause of the current error. If no root error exists, this parameter is null. 5.2.0

#inventory

Name Type Description Satrting Version
uuid String The XML Hook UUID. 5.2.0
name String The XML Hook name. 5.2.0
description String The detailed information of the XML Hook. 5.2.0
hookScript String The XML Hook content. 5.2.0
libvirtVersion String The Libvirt version. 5.2.0
createDate Timestamp The creation time. 5.2.0
lastOpDate Timestamp The last operation time. 5.2.0
type XmlHookType See type 5.2.0

#type

Name Type Description Starting Version
System XmlHookType The System value. 5.2.0
Customization XmlHookType The Customization value. 5.2.0

SDK Sample

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

action = CreateVmUserDefinedXmlHookScriptAction()
action.name = "hook"
action.description = "xml hook"
action.hookScript = "base64"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
res = action.call()

ExpungeVmUserDefinedXmlHookScript

API Request

URLs

DELETE zstack/v1/vm-instances/xml-hook-script/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl Sample

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

Request Parameters

Name Type Location Description Valid Values Starting Version
uuid String url The XML Hook UUID. 5.2.0
systemTags List body Optional. The system tags. 5.2.0
userTags List body Optional. The user tags. 5.2.0

API Response

When the API succeeded, an empty JSON structure {} is returned. When the API failed, the returned JSON structure includes an error field. For example,

{
    "error": {
        "code": "SYS.1001",
        "description": "A message or a operation timeout",
        "details": "Create VM on KVM timeout after 300s"
    }
}

SDK Sample

Java SDK

ExpungeVmUserDefinedXmlHookScriptAction action = new ExpungeVmUserDefinedXmlHookScriptAction();
action.uuid = "99df64f50f5b34c6be5a7339d676aeb6";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
ExpungeVmUserDefinedXmlHookScriptAction.Result res = action.call();

Python SDK

action = ExpungeVmUserDefinedXmlHookScriptAction()
action.uuid = "99df64f50f5b34c6be5a7339d676aeb6"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
res = action.call()

UpdateVmUserDefinedXmlHookScript

API Request

URLs

PUT zstack/v1/vm-instances/xml-hook-script

Headers

Authorization: OAuth the-session-uuid

Body

{
  "updateVmUserDefinedXmlHookScript": {
    "uuid": "a44a23f78c9c391c9d2f3a6a576e77d6",
    "name": "example"
  },
  "systemTags": [],
  "userTags": []
}

In the preceding sample, both systemTags and userTags are optional. These two fields can be included in the body structure.

Curl Sample

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

Request Parameters

Name Type Location Description Valid Values Starting Version
uuid String body (contained in the updateVmUserDefinedXmlHookScript structure) The XML Hook UUID. 5.2.0
name String body (contained in the updateVmUserDefinedXmlHookScript structure) Optional. The XML Hook name. 5.2.0
description String body (contained in the updateVmUserDefinedXmlHookScript structure) Optional. The detailed information of the XML Hook. 5.2.0
hookScript String body (contained in the updateVmUserDefinedXmlHookScript structure) Optional. The XML Hook content. 5.2.0
systemTags List body Optional. The system tags. 5.2.0
userTags List body Optional. The user tags. 5.2.0
startupStrategy String body (contained in the updateVmUserDefinedXmlHookScript structure) Optional. Whether reboot associated VM instances immediately.
  • Reboot
  • None
5.2.0

API Response

When the API succeeded, an empty JSON structure {} is returned. When the API failed, the returned JSON structure includes an error field. For example,

{
    "error": {
        "code": "SYS.1001",
        "description": "A message or a operation timeout",
        "details": "Create VM on KVM timeout after 300s"
    }
}

SDK Sample

Java SDK

UpdateVmUserDefinedXmlHookScriptAction action = new UpdateVmUserDefinedXmlHookScriptAction();
action.uuid = "a44a23f78c9c391c9d2f3a6a576e77d6";
action.name = "example";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
UpdateVmUserDefinedXmlHookScriptAction.Result res = action.call();

Python SDK

action = UpdateVmUserDefinedXmlHookScriptAction()
action.uuid = "a44a23f78c9c391c9d2f3a6a576e77d6"
action.name = "example"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
res = action.call()

AttachUserDefinedXmlHookScriptToVm

API Request

URLs

POST zstack/v1/xmlhook/{xmlHookUuid}/vm-instances/{vmInstanceUuid}

Headers

Authorization: OAuth the-session-uuid

Body

{
  "params": {
    "startupStrategy": "None"
  },
  "systemTags": [],
  "userTags": []
}

In the preceding sample, both systemTags and userTags are optional. These two fields can be included in the body structure.

Curl Sample

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

Request Parameters

Name Type Location Description Valid Values Starting Version
vmInstanceUuid String url The VM instance UUID. 5.2.0
xmlHookUuid String url The XML Hook UUID. 5.2.0
startupStrategy String body (contained in the params structure) Optional. Whether reboot the VM instance immediately.
  • Reboot
  • None
5.2.0
systemTags List body Optional. The system tags. 5.2.0
userTags List body Optional. The user tags. 5.2.0

API Response

When the API succeeded, an empty JSON structure {} is returned. When the API failed, the returned JSON structure includes an error field. For example,

{
    "error": {
        "code": "SYS.1001",
        "description": "A message or a operation timeout",
        "details": "Create VM on KVM timeout after 300s"
    }
}

SDK Sample

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

action = AttachUserDefinedXmlHookScriptToVmAction()
action.vmInstanceUuid = "6baaffd8cb123dcc954b6242835267b9"
action.xmlHookUuid = "73300c2b203e3e43bc4b0dec7c3b0f21"
action.startupStrategy = "None"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
res = action.call()

DetachUserDefinedXmlHookScriptFromVm

API Request

URLs

DELETE zstack/v1/xmlhook/vm-instances/{vmInstanceUuid}/detach

Headers

Authorization: OAuth the-session-uuid

Curl Sample

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

Request Parameters

Name Type Location Description Valid Values Starting Version
vmInstanceUuid String url The VM instance UUID. 5.2.0
startupStrategy String body Optional. Whether reboot the VM instance immediately.
  • Reboot
  • None
5.2.0
deleteMode String body Optional. The deletion mode.
  • Permissive
  • Enforcing,Permissive
5.2.0
systemTags List body Optional. The system tags. 5.2.0
userTags List body Optional. The user tags. 5.2.0

API Response

When the API succeeded, an empty JSON structure {} is returned. When the API failed, the returned JSON structure includes an error field. For example,

{
    "error": {
        "code": "SYS.1001",
        "description": "A message or a operation timeout",
        "details": "Create VM on KVM timeout after 300s"
    }
}

SDK Sample

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

action = DetachUserDefinedXmlHookScriptFromVmAction()
action.vmInstanceUuid = "588ac603fdd73c7c8519235a73271188"
action.startupStrategy = "None"
action.deleteMode = "Permissive"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
res = action.call()

QueryVmUserDefinedXmlHookScript

API Request

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 Sample

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

Queryable Fields

You can check all queryable fields and resource names that can be queried across tables by using zstack-cli, entering QueryVmUserDefinedXmlHookScript, and pressing the Tab key.

API Response

When the API succeeded, an empty JSON structure {} is returned. When the API failed, the returned JSON structure includes an error field. For example,

{
    "error": {
        "code": "SYS.1001",
        "description": "A message or a operation timeout",
        "details": "Create VM on KVM timeout after 300s"
    }
}

SDK Sample

Java SDK

QueryVmUserDefinedXmlHookScriptAction action = new QueryVmUserDefinedXmlHookScriptAction();
action.conditions = asList("uuid=xxx","name=xxx");
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
QueryVmUserDefinedXmlHookScriptAction.Result res = action.call();

Python SDK

action = QueryVmUserDefinedXmlHookScriptAction()
action.conditions = ["uuid=xxx","name=xxx"]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
res = action.call()