云主机加载物理机USB设备(AttachUsbDeviceToVm)
API请求
URLs
POST zstack/v1/usb-device/usb-devices/{usbDeviceUuid}/attachHeaders
Authorization: OAuth the-session-uuidBody
{
"params": {
"vmInstanceUuid": "2a3697245a4a3e829a246e222c243688",
"attachType": "PassThrough"
},
"systemTags": [],
"userTags": []
}Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"vmInstanceUuid":"2a3697245a4a3e829a246e222c243688","attachType":"PassThrough"}}' http://localhost:8080/zstack/v1/usb-device/usb-devices/84838a1925bb3eb3b2440a8afd420e40/attach参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| usbDeviceUuid | String | url | USB设备UUID | 2.2 | |
| vmInstanceUuid | String | body(包含在params结构中) | 云主机UUID | 2.2 | |
| attachType (可选) | String | body(包含在params结构中) | 加载类型 |
|
3.5.0 |
| systemTags (可选) | List | body | 系统标签 | 2.2 | |
| userTags (可选) | List | body | 用户标签 | 2.2 |
API返回
返回示例
{
"inventory": {
"uuid": "dc782167a4853525848fd04bf606d072",
"name": "usb",
"hostUuid": "dea6020aae7b3244be45eee6ae1d4d0f",
"vmInstanceUuid": "33471e0ae8a33b3b8b0f295eff6e4db4",
"state": "Enabled",
"busNum": "001",
"devNum": "001",
"idVendor": "0781",
"idProduct": "5591",
"iManufacturer": "SanDisk",
"iProduct": "Ultra USB 3.0",
"iSerial": "000000000001",
"usbVersion": "3.0",
"attachType": "PassThrough"
}
}
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 2.2 |
| inventory | UsbDeviceInventory | 详情参考inventory | 2.2 |
#error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 2.2 |
| description | String | 错误的概要描述 | 2.2 |
| details | String | 错误的详细信息 | 2.2 |
| elaboration | String | 保留字段,默认为null | 2.2 |
| opaque | LinkedHashMap | 保留字段,默认为null | 2.2 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 2.2 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 2.2 |
| name | String | 资源名称 | 2.2 |
| description | String | 资源的详细描述 | 2.2 |
| hostUuid | String | 物理机UUID | 2.2 |
| vmInstanceUuid | String | 云主机UUID | 2.2 |
| busNum | String | 总线号 | 2.2 |
| devNum | String | 设备号 | 2.2 |
| idVendor | String | VendorID | 2.2 |
| idProduct | String | ProductID | 2.2 |
| iManufacturer | String | 生产商 | 2.2 |
| iProduct | String | 设备类型 | 2.2 |
| iSerial | String | 序列号 | 2.2 |
| usbVersion | String | USB版本 | 2.2 |
| attachType | String | 加载方式 | 3.5.0 |
| createDate | Timestamp | 创建时间 | 2.2 |
| lastOpDate | Timestamp | 最后一次修改时间 | 2.2 |
| state | UsbDeviceState | 详情参考state | 2.2 |
#state
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| name | String | 资源名称 | 2.2 |
| ordinal | int | 2.2 |
SDK示例
Java
SDK
AttachUsbDeviceToVmAction action = new AttachUsbDeviceToVmAction();
action.usbDeviceUuid = "84838a1925bb3eb3b2440a8afd420e40";
action.vmInstanceUuid = "2a3697245a4a3e829a246e222c243688";
action.attachType = "PassThrough";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
AttachUsbDeviceToVmAction.Result res = action.call();Python
SDK
AttachUsbDeviceToVmAction action = AttachUsbDeviceToVmAction()
action.usbDeviceUuid = "84838a1925bb3eb3b2440a8afd420e40"
action.vmInstanceUuid = "2a3697245a4a3e829a246e222c243688"
action.attachType = "PassThrough"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
AttachUsbDeviceToVmAction.Result res = action.call()