Attach PCI Device to VM

POST/zstack/v1/pci-device/pci-devices/{pciDeviceUuid}/attach

Attach a PCI device to a Virtual Machine. Administrators can directly attach PCI devices in System or Active state to Virtual Machines in Active or Stopped state.

Headers

Authorization: OAuth the-session-uuid

Body

{
  "params": {
    "vmInstanceUuid": "d3f41f8b996b390992cc4607e7bb10dc"
  },
  "systemTags": [],
  "userTags": []
}

In the example above, the systemTags and userTags fields can be omitted. They are listed to indicate that the body can contain these two fields.

Curl Example

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"vmInstanceUuid":"d3f41f8b996b390992cc4607e7bb10dc"}}' \
http://localhost:8080/zstack/v1/pci-device/pci-devices/201b541edbed3dccbebfaa57b3beb9bb/attach

Parameter List

NameTypeLocationDescriptionAllowed ValuesStarting Version
pciDeviceUuidStringurlPCI device UUID 2.1
vmInstanceUuidStringbody (contained in the params structure)Virtual Machine UUID 2.1
systemTags (Optional)Listbody  2.1
userTags (Optional)Listbody  2.1

API Response

Response Example

{
  "inventory": {
    "uuid": "f89ad78682d73e08a2ed52bd4837aadf",
    "hostUuid": "f2d1b937a92a3ac6a446feb1030f6315",
    "vmInstanceUuid": "3daa5e997d023c508a4af3ddda65ddac",
    "type": "GPU_Video_Controller",
    "status": "Attached",
    "vendorId": "10de",
    "deviceId": "0e0f",
    "subvendorId": "10de",
    "subdeviceId": "118b",
    "pciDeviceAddress": "0000:06:00.1"
  }
}
NameTypeDescriptionStarting Version
successboolean 0.6
errorErrorCodeError code. If not null, the operation failed. This field is null when the operation succeeds. See error2.1
inventoryPciDeviceInventorySee inventory2.1

error

NameTypeDescriptionStarting Version
codeStringError code, a globally unique identifier of the error, e.g. SYS.1000, HOST.10012.1
descriptionStringBrief description of the error2.1
detailsStringDetailed error information2.1
elaborationStringReserved field, defaults to null2.1
opaqueLinkedHashMapReserved field, defaults to null2.1
causeErrorCodeRoot cause, the source error that caused the current error, null if no original error2.1

inventory

NameTypeDescriptionStarting Version
uuidStringUUID of the resource, uniquely identifies the resource2.1
nameStringResource name3.5.0
descriptionStringResource description2.1
hostUuidStringHost UUID2.1
parentUuidStringPhysical PCI device UUID3.5.0
vmInstanceUuidStringVirtual Machine UUID2.1
pciSpecUuidStringPCI device offering UUID3.5.0
vendorIdStringVendor ID2.1
deviceIdStringDevice ID2.1
subvendorIdStringSub-vendor ID2.1
subdeviceIdStringSub-device ID2.1
pciDeviceAddressStringPCI device address2.1
createDateTimestampCreate date2.1
lastOpDateTimestampLast update date2.1
typePciDeviceTypeSee type2.1
statePciDeviceStateSee state2.1
statusPciDeviceStatusSee status2.1
virtStatusPciDeviceVirtStatusSee virtStatus3.5.0
chooserPciDeviceChooserSee chooser4.1.0
metaDataPciDeviceMetaDataSee metaData2.1
matchedPciDeviceOfferingRefListSee matchedPciDeviceOfferingRef2.1
mdevSpecRefsListSee mdevSpecRefs3.5.0

type

NameTypeDescriptionStarting Version
GPU_Video_ControllerPciDeviceTypeGPU video controller2.1
GPU_Audio_ControllerPciDeviceTypeGPU audio controller2.1
GPU_3D_ControllerPciDeviceTypeGPU 3D controller2.1
Moxa_DevicePciDeviceTypeMOXA card2.1
GenericPciDeviceTypeGeneric device2.1

state

NameTypeDescriptionStarting Version
EnabledPciDeviceStateEnabled2.1
DisabledPciDeviceStateDisabled2.1

status

NameTypeDescriptionStarting Version
ActivePciDeviceStatusReady2.1
AttachedPciDeviceStatusAttached2.1
SystemPciDeviceStatusSystem2.1

virtStatus

NameTypeDescriptionStarting Version
UNVIRTUALIZABLEPciDeviceVirtStatusUnvirtualizable3.5.0
SRIOV_VIRTUALIZABLEPciDeviceVirtStatusSRIOV virtualizable3.5.0
VFIO_MDEV_VIRTUALIZABLEPciDeviceVirtStatusVFIO_MDEV virtualizable3.5.0
SRIOV_VIRTUALIZEDPciDeviceVirtStatusSRIOV virtualized3.5.0
VFIO_MDEV_VIRTUALIZEDPciDeviceVirtStatusVFIO_MDEV virtualized3.5.0
SRIOV_VIRTUALPciDeviceVirtStatusSRIOV virtual device3.5.0
UNKNOWNPciDeviceVirtStatusUnknown3.5.0

chooser

NameTypeDescriptionStarting Version
NonePciDeviceChooser 4.8.0
DevicePciDeviceChooser 4.8.0
SpecPciDeviceChooser 4.8.0

metaData

NameTypeDescriptionStarting Version
metaDataString 2.1
metaDataEntriesListSee metaDataEntries2.1

metaDataEntries

NameTypeDescriptionStarting Version
keyStringKey2.1
valueStringValue2.1
opPciDeviceMetaDataOperatorSee op2.1

op

NameTypeDescriptionStarting Version
EqualPciDeviceMetaDataOperatorEqual2.1
UnequalPciDeviceMetaDataOperatorUnequal2.1

matchedPciDeviceOfferingRef

NameTypeDescriptionStarting Version
pciDeviceUuidString 2.1
pciDeviceOfferingUuidString 2.1

mdevSpecRefs

NameTypeDescriptionStarting Version
pciDeviceUuidStringPCI device UUID3.5.0
mdevSpecUuidStringMDEV device offering UUID3.5.0
effectiveBooleanWhether the current MDEV specification is used to partition this PCI device3.5.0
createDateTimestampCreate date3.5.0
lastOpDateTimestampLast update date3.5.0

SDK Examples

Java SDK

AttachPciDeviceToVmAction action = new AttachPciDeviceToVmAction();
action.pciDeviceUuid = "201b541edbed3dccbebfaa57b3beb9bb";
action.vmInstanceUuid = "d3f41f8b996b390992cc4607e7bb10dc";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
AttachPciDeviceToVmAction.Result res = action.call();

Python SDK

AttachPciDeviceToVmAction action = AttachPciDeviceToVmAction()
action.pciDeviceUuid = "201b541edbed3dccbebfaa57b3beb9bb"
action.vmInstanceUuid = "d3f41f8b996b390992cc4607e7bb10dc"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
AttachPciDeviceToVmAction.Result res = action.call()