USB Pass-through Operations
AttachUsbDeviceToVm
API Request
URLs
POST zstack/v1/usb-device/usb-devices/{usbDeviceUuid}/attachHeaders
Authorization: OAuth the-session-uuidBody
{
"params": {
"vmInstanceUuid": "2a3697245a4a3e829a246e222c243688",
"attachType": "PassThrough"
},
"systemTags": [],
"userTags": []
}
Note: 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":{"vmInstanceUuid":"2a3697245a4a3e829a246e222c243688","attachType":"PassThrough"}}' http://localhost:8080/zstack/v1/usb-device/usb-devices/84838a1925bb3eb3b2440a8afd420e40/attachRequest Parameters
| Name | Type | Location | Description | Optional Value | Starting Version |
|---|---|---|---|---|---|
| usbDeviceUuid | String | url | The USB device UUID. | 2.2 | |
| vmInstanceUuid | String | body (contained in the params structure) | The VM instance UUID. | 2.2 | |
| attachType | String | body (contained in the params structure) | Optional. The attach type. |
|
3.5.0 |
| systemTags | List | body | Optional. The system tags. | 2.2 | |
| userTags | List | body | Optional. The user tags. | 2.2 |
API Response
Sample Response
{
"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"
}
}
| Name | Type | Description | Starting Version |
|---|---|---|---|
| error | ErrorCode | The error code. If not null, the operation fails, or vice versa. For more information, see error. | 2.2 |
| inventory | UsbDeviceInventory | See inventory. | 2.2 |
#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. | 2.2 |
| description | String | The brief description of the error. | 2.2 |
| details | String | The details about the error. | 2.2 |
| elaboration | String | The reserved field. Default value: null. | 2.2 |
| opaque | LinkedHashMap | The reserved field. Default value: null. | 2.2 |
| cause | ErrorCode | The root error, which is the associated root cause of the current error. If no root error exists, this parameter is null. | 2.2 |
#inventory
| Name | Type | Description | Starting Version |
|---|---|---|---|
| uuid | String | The resource UUID. | 2.2 |
| name | String | The resource name. | 2.2 |
| description | String | The detailed description of the resource. | 2.2 |
| hostUuid | String | The host UUID. | 2.2 |
| vmInstanceUuid | String | The VM instance UUID. | 2.2 |
| busNum | String | The bus No. | 2.2 |
| devNum | String | The device No. | 2.2 |
| idVendor | String | The vendor ID. | 2.2 |
| idProduct | String | The device ID. | 2.2 |
| iManufacturer | String | The manufacturer. | 2.2 |
| iProduct | String | The device type. | 2.2 |
| iSerial | String | The serial No. | 2.2 |
| usbVersion | String | The USB version. | 2.2 |
| attachType | String | The attach type. | 3.5.0 |
| createDate | Timestamp | The creation date. | 2.2 |
| lastOpDate | Timestamp | The last operation date. | 2.2 |
| state | UsbDeviceState | See state. | 2.2 |
#state
| Name | Type | Description | Starting Version |
|---|---|---|---|
| name | String | The resource name. | 2.2 |
| ordinal | int | 2.2 |
SDK Sample
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()DetachUsbDeviceFromVm
API Request
URLs
POST zstack/v1/usb-device/usb-devices/{usbDeviceUuid}/detachHeaders
Authorization: OAuth the-session-uuidBody
{
"params": {},
"systemTags": [],
"userTags": []
}
Note: 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":{}}' \
http://localhost:8080/zstack/v1/usb-device/usb-devices/17a5e98e5f943e8fafa01602d50cf3ad/detachRequest Parameters
| Name | Type | Location | Description | Optional Value | Starting Version |
|---|---|---|---|---|---|
| usbDeviceUuid | String | url | The USB device UUID. | 2.2 | |
| systemTags | List | body | Optional. The system tags. | 2.2 | |
| userTags | List | body | Optional. The user tags. | 2.2 |
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
DetachUsbDeviceFromVmAction action = new DetachUsbDeviceFromVmAction();
action.usbDeviceUuid = "5256c889e9f0489e8fd12b66d176fb7d";
action.sessionId = "8082962f2d304a3fbee969e6b4749338";
DetachUsbDeviceFromVmAction.Result res = action.call();Python
SDK
DetachUsbDeviceFromVmAction action = DetachUsbDeviceFromVmAction()
action.usbDeviceUuid = "ced1bbb139c54d1d973ddc38ae565244"
action.sessionId = "f6550a168b9847fca4c98df088d86c09"
DetachUsbDeviceFromVmAction.Result res = action.call()GetUsbDeviceCandidatesForAttachingVm
API Request
URLs
GET zstack/v1/vm-instances/{vmInstanceUuid}/candidate-usb-devicesHeaders
Authorization: OAuth the-session-uuidCurl
Sample
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/vm-instances/ab759c79169739cb9e13ff091c4fa386/candidate-usb-devices?attachType=PassThroughRequest Parameters
| Name | Type | Location | Description | Optional Value | Starting Version |
|---|---|---|---|---|---|
| vmInstanceUuid | String | url | The VM instance UUID. | 2.2 | |
| attachType | String | query | Optional. The attach type. |
|
3.6.0 |
| systemTags | List | query | Optional. The system tags. | 2.2 | |
| userTags | List | query | Optional. The user tags. | 2.2 |
API Response
Sample
Response
{
"inventories": [
{
"uuid": "b58b4b48b3b8398f93b8b529f6f5b53a",
"name": "usb",
"hostUuid": "9f7438cf6fd233cf8fc27d4f311326ca",
"vmInstanceUuid": "ccdfb1d443433e1a8beac3a1d54374d5",
"state": "Enabled",
"busNum": "001",
"devNum": "001",
"idVendor": "0781",
"idProduct": "5591",
"iManufacturer": "SanDisk",
"iProduct": "Ultra USB 3.0",
"iSerial": "000000000001",
"usbVersion": "3.0",
"attachType": "PassThrough"
}
]
}| Name | Type | Description | Starting Version |
|---|---|---|---|
| success | boolean | The API succeeded. | 2.2 |
| error | ErrorCode | The error code. If not null, the operation fails, or vice versa. For more information, see error. | 2.2 |
| inventories | List | See inventories. | 2.2 |
#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. | 2.2 |
| description | String | The brief description of the error. | 2.2 |
| details | String | The details about the error. | 2.2 |
| elaboration | String | The reserved field. Default value: null. | 2.2 |
| opaque | LinkedHashMap | The reserved field. Default value: null. | 2.2 |
| cause | ErrorCode | The root error, which is the associated root cause of the current error. If no root error exists, this parameter is null. | 2.2 |
#inventories
| Name | Type | Description | Starting Version |
|---|---|---|---|
| uuid | String | The resource UUID. | 2.2 |
| name | String | The resource name. | 2.2 |
| description | String | The detailed description of the resource. | 2.2 |
| hostUuid | String | The host UUID. | 2.2 |
| vmInstanceUuid | String | The VM instance UUID. | 2.2 |
| busNum | String | The bus No. | 2.2 |
| devNum | String | The device No. | 2.2 |
| idVendor | String | The vendor ID. | 2.2 |
| idProduct | String | The device ID. | 2.2 |
| iManufacturer | String | The manufacturer. | 2.2 |
| iProduct | String | The device type. | 2.2 |
| iSerial | String | The serial No. | 2.2 |
| usbVersion | String | The USB version. | 2.2 |
| attachType | String | The attach type. | 3.5.0 |
| createDate | Timestamp | The creation date. | 2.2 |
| lastOpDate | Timestamp | The last operation date. | 2.2 |
| state | UsbDeviceState | See state. | 2.2 |
#state
| Name | Type | Description | Starting Version |
|---|---|---|---|
| name | String | The resource name. | 2.2 |
| ordinal | int | 2.2 |
SDK Sample
Java
SDK
GetUsbDeviceCandidatesForAttachingVmAction action = new GetUsbDeviceCandidatesForAttachingVmAction();
action.vmInstanceUuid = "ab759c79169739cb9e13ff091c4fa386";
action.attachType = "PassThrough";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
GetUsbDeviceCandidatesForAttachingVmAction.Result res = action.call();Python
SDK
GetUsbDeviceCandidatesForAttachingVmAction action = GetUsbDeviceCandidatesForAttachingVmAction()
action.vmInstanceUuid = "ab759c79169739cb9e13ff091c4fa386"
action.attachType = "PassThrough"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
GetUsbDeviceCandidatesForAttachingVmAction.Result res = action.call()QueryUsbDevice
API Request
URLs
GET zstack/v1/usb-device/usb-devices
GET zstack/v1/usb-device/usb-devices/{uuid}Headers
Authorization: OAuth the-session-uuidCurl
Sample
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 54e99d3cba30426599008210fe537a5a" \
-X GET http://localhost:8080/zstack/v1/usb-device/usb-devicescurl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth bd2e6629c65f4be6b0ae893664d80fac" \
-X GET http://localhost:8080/zstack/v1/usb-device/usb-devices/d2da293d46ac46279168ae02b361c69fQueryable Fields
You can check all queryable fields and resource names that can be queried across
tables by using zstack-cli, entering
QueryUsbDevice, and pressing the Tab key.
API Response
Sample
Response
{
"inventories": [
{
"uuid": "0beadc00381c4ca09216dc2ebfb0fba3",
"name": "usb",
"hostUuid": "648749ea79fb412aab27712c5813600a",
"vmInstanceUuid": "f862f3c01f3340d6ab68e7a79757342f",
"state": "Enabled",
"busNum": "001",
"devNum": "001",
"idVendor": "0781",
"idProduct": "5591",
"iManufacturer": "SanDisk",
"iProduct": "Ultra USB 3.0",
"iSerial": "000000000001",
"usbVersion": "3.0",
"attachType": "PassThrough"
}
]
}| Name | Type | Description | Starting Version |
|---|---|---|---|
| error | ErrorCode | The error code. If not null, the operation fails, or vice versa. For more information, see error. | 2.2 |
| inventories | List | See inventories. | 2.2 |
#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. | 2.2 |
| description | String | The brief description of the error. | 2.2 |
| details | String | The details about the error. | 2.2 |
| elaboration | String | The reserved field. Default value: null. | 2.2 |
| opaque | LinkedHashMap | The reserved field. Default value: null. | 2.2 |
| cause | ErrorCode | The root error, which is the associated root cause of the current error. If no root error exists, this parameter is null. | 2.2 |
#inventories
| Name | Type | Description | Starting Version |
|---|---|---|---|
| uuid | String | The resource UUID. | 2.2 |
| name | String | The resource name. | 2.2 |
| description | String | The detailed description of the resource. | 2.2 |
| hostUuid | String | The host UUID. | 2.2 |
| vmInstanceUuid | String | The VM instance UUID. | 2.2 |
| busNum | String | The bus No. | 2.2 |
| devNum | String | The device No. | 2.2 |
| idVendor | String | The vendor ID. | 2.2 |
| idProduct | String | The device ID. | 2.2 |
| iManufacturer | String | The manufacturer. | 2.2 |
| iProduct | String | The device type. | 2.2 |
| iSerial | String | The serial No. | 2.2 |
| usbVersion | String | The USB version. | 2.2 |
| attachType | String | The attach type. | 3.6.0 |
| createDate | Timestamp | The creation date. | 2.2 |
| lastOpDate | Timestamp | The last operation date. | 2.2 |
| state | UsbDeviceState | See state. | 2.2 |
#state
| Name | Type | Description | Starting Version |
|---|---|---|---|
| name | String | The resource name. | 2.2 |
| ordinal | int | 2.2 |
SDK Sample
Java
SDK
QueryUsbDeviceAction action = new QueryUsbDeviceAction();
action.conditions = asList();
action.sessionId = "b51bb939a8844869abb32e9cedbc9a1f";
QueryUsbDeviceAction.Result res = action.call();Python
SDK
QueryUsbDeviceAction action = QueryUsbDeviceAction()
action.conditions = []
action.sessionId = "9f884d4333ba46369cd1039c9ea44965"
QueryUsbDeviceAction.Result res = action.call()UpdateUsbDevice
API Request
URLs
PUT zstack/v1/usb-device/usb-devices/{uuid}/actionsHeaders
Authorization: OAuth the-session-uuidBody
{
"updateUsbDevice": {
"name": "usb",
"description": "this is a usb device",
"state": "Enabled"
},
"systemTags": [],
"userTags": []
}
Note: 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 '{"updateUsbDevice":{"name":"usb","description":"this is a usb device","state":"Enabled"}}' \
http://localhost:8080/zstack/v1/usb-device/usb-devices/9d1ab4950ce933edabbaf8e73ca7e879/actionsRequest Parameters
| Name | Type | Locaiton | Description | Optional Value | Starting Version |
|---|---|---|---|---|---|
| uuid | String | url | The resource UUID. | 2.2 | |
| name | String | body (contained in the updateUsbDevice structure) | Optional. The resource name. | 2.2 | |
| description | String | body (contained in the updateUsbDevice structure) | Optional. The detailed description of the resource. | 2.2 | |
| state | String | body (contained in the updateUsbDevice structure) | Optional. The USB state. |
|
2.2 |
| systemTags | List | body | Optional. The system tags. | 2.2 | |
| userTags | List | body | Optional. The user tags. | 2.2 |
API Response
Sample
Response
{
"inventory": {
"uuid": "2695f7ce0bda4587bbabbbfaad080554",
"description": "test usb",
"hostUuid": "4261ceb358ce473fa62c137c1ba8d3ef",
"vmInstanceUuid": "4c059c5e0a834d86984d3141d8ec42cb",
"state": "Disabled",
"idVendor": "10de",
"idProduct": "0e0f",
"iManufacturer": "SanDisk",
"iProduct": "USB Storage",
"iSerial": "000000000001",
"usbVersion": "3.0",
"attachType": "PassThrough"
}
}| Name | Type | Description | Starting Version |
|---|---|---|---|
| error | ErrorCode | The error code. If not null, the operation fails, or vice versa. For more information, see error. | 2.2 |
| inventory | UsbDeviceInventory | See inventory. | 2.2 |
#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. | 2.2 |
| description | String | The brief description of the error. | 2.2 |
| details | String | The details about the error. | 2.2 |
| elaboration | String | The reserved field. Default value: null. | 2.2 |
| opaque | LinkedHashMap | The reserved field. Default value: null. | 2.2 |
| cause | ErrorCode | The root error, which is the associated root cause of the current error. If no root error exists, this parameter is null. | 2.2 |
#inventory
| Name | Type | Description | Starting Version |
|---|---|---|---|
| uuid | String | The resource UUID. | 2.2 |
| name | String | The resource name. | 2.2 |
| description | String | The detailed description of the resource. | 2.2 |
| hostUuid | String | The host UUID. | 2.2 |
| vmInstanceUuid | String | The VM instance UUID. | 2.2 |
| busNum | String | The bus No. | 2.2 |
| devNum | String | The device No. | 2.2 |
| idVendor | String | The vendor ID. | 2.2 |
| idProduct | String | The device ID. | 2.2 |
| iManufacturer | String | The manufacturer. | 2.2 |
| iProduct | String | The device type. | 2.2 |
| iSerial | String | The serial No. | 2.2 |
| usbVersion | String | The USB version. | 2.2 |
| attachType | String | The attach type. | 3.6.0 |
| createDate | Timestamp | The creation date. | 2.2 |
| lastOpDate | Timestamp | The last operation date. | 2.2 |
| state | UsbDeviceState | See state. | 2.2 |
#state
| Name | Type | Description | Starting Version |
|---|---|---|---|
| name | String | The resource name. | 2.2 |
| ordinal | int | 2.2 |
SDK Sample
Java
SDK
UpdateUsbDeviceAction action = new UpdateUsbDeviceAction();
action.uuid = "86d05b807cfa47a7969745f0ffe8ee4b";
action.name = "usb";
action.description = "this is a usb device";
action.state = "Enabled";
action.sessionId = "86600ceaed5642ad810828129fe0e4a0";
UpdateUsbDeviceAction.Result res = action.call();Python
SDK
UpdateUsbDeviceAction action = UpdateUsbDeviceAction()
action.uuid = "f16940abc205404bb17b00367f5b6a8d"
action.name = "usb"
action.description = "this is a usb device"
action.state = "Enabled"
action.sessionId = "a65b10bd9a164d33a42d8bacfab5acd6"
UpdateUsbDeviceAction.Result res = action.call()