文档目录

USB重定向相关接口

获取云主机usb重定向开关状态(GetVmUsbRedirect)

API请求

URLs

GET zstack/v1/vm-instances/{uuid}/usbredirect

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth bb5fd18e914f4bfd88032edd0ee7b975" \
-X GET http://localhost:8080/zstack/v1/vm-instances/4b9d28c1d35f4f14b8ba1bb982500c50/usbredirect

参数列表

名字 类型 位置 描述 可选值 起始版本
uuid String url 资源的UUID,唯一标示该资源 2.1
systemTags (可选) List query 2.1
userTags (可选) List query 2.1

API返回

返回示例

{
  "enable": true
}
名字 类型 描述 起始版本
enable boolean usb redirect 开关是否开启 2.1
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 2.1

#error

名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 2.1
description String 错误的概要描述 2.1
details String 错误的详细信息 2.1
elaboration String 保留字段,默认为null 2.1
opaque LinkedHashMap 保留字段,默认为null 2.1
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 2.1

SDK示例

Java SDK

GetVmUsbRedirectAction action = new GetVmUsbRedirectAction();
action.uuid = "c58671c58dd147e29d4bc263feafa04d";
action.sessionId = "e173648fdca94fd3ae720473a305ce4c";
GetVmUsbRedirectAction.Result res = action.call();

Python SDK

action = GetVmUsbRedirectAction()
action.uuid = "08efac4de45a4f6789d1009afa9e295e"
action.sessionId = "3f5a7473758d4c8ab3cc4664461500a4"
res = action.call()

设置云主机usb重定向开关(SetVmUsbRedirect)

API请求

URLs

PUT zstack/v1/vm-instances/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{
  "setVmUsbRedirect": {
    "enable": true
  },
  "systemTags": [],
  "userTags": []
}

上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"setVmUsbRedirect":{"enable":true}}' \
http://localhost:8080/zstack/v1/vm-instances/ceeca8ab8c6b33fab9bdc143dec13211/actions

参数列表

名字 类型 位置 描述 可选值 起始版本
uuid String url 资源的UUID,唯一标示该资源 2.1
enable boolean body(包含在setVmUsbRedirect结构中) 设置为true代表开关开启,设置为false代表开关关闭
  • true
  • false
2.1
systemTags (可选) List body 2.1
userTags (可选) List body 2.1

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

SetVmUsbRedirectAction action = new SetVmUsbRedirectAction();
action.uuid = "8c14cf1dd17642c19622c924d065bb00";
action.enable = true;
action.sessionId = "6a5e2cc211794d28b9e1641c1a53d018";
SetVmUsbRedirectAction.Result res = action.call();

Python SDK

action = SetVmUsbRedirectAction()
action.uuid = "977cd1ae8b5f4dcab4c5f2062089ebf9"
action.enable = true
action.sessionId = "e6b4af2b358b44ea9fc3ff185d9af869"
res = action.call()