Example #1
0
func (d *VirDomain) AttachDeviceFlags(xml string, flags uint) error {
	cXml := C.CString(xml)
	defer C.free(unsafe.Pointer(cXml))
	result := C.virDomainAttachDeviceFlags(d.ptr, cXml, C.uint(flags))
	if result == -1 {
		return GetLastError()
	}
	return nil
}
Example #2
0
// AttachDevice attaches a virtual device to a domain, using the flags
// parameter to control how the device is attached. DomDeviceModifyCurrent
// specifies that the device allocation is made based on current domain state.
// DomDeviceModifyLive specifies that the device shall be allocated to the
// active domain instance only and is not added to the persisted domain
// configuration. DomDeviceModifyConfig specifies that the device shall be
// allocated to the persisted domain configuration only. Note that the target
// hypervisor must return an error if unable to satisfy flags. E.g. the
// hypervisor driver will return failure if DomDeviceModifyLive is specified
// but it only supports modifying the persisted device allocation.
func (dom Domain) AttachDevice(deviceXML string, flags DomainDeviceModifyFlag) error {
	cXML := C.CString(deviceXML)
	defer C.free(unsafe.Pointer(cXML))

	dom.log.Printf("attaching a virtual device to domain (flags = %v)...\n", flags)
	cRet := C.virDomainAttachDeviceFlags(dom.virDomain, cXML, C.uint(flags))
	ret := int32(cRet)

	if ret == -1 {
		err := LastError()
		dom.log.Printf("an error occurred: %v\n", err)
		return err
	}

	dom.log.Println("device attached")

	return nil
}