// GetMedium returns a Medium connected to this VM. // It returns the requested Medium and any error encountered. func (machine *Machine) GetMedium(controllerName string, controllerPort int, deviceSlot int) (Medium, error) { var medium Medium cname := C.CString(controllerName) result := C.GoVboxMachineGetMedium(machine.cmachine, cname, C.PRInt32(controllerPort), C.PRInt32(deviceSlot), &medium.cmedium) C.free(unsafe.Pointer(cname)) if C.GoVboxFAILED(result) != 0 || (medium.cmedium == nil) { return medium, errors.New( fmt.Sprintf("Failed to get IMedium from IMachine: %x", result)) } return medium, nil }
// AttachDevice connects a Medium to this VM. // deviceSlot is 0 for IDE master and 1 for IDE slave. All other bus types use // deviceSlot 0. // It returns any error encountered. func (machine *Machine) AttachDevice(controllerName string, controllerPort int, deviceSlot int, deviceType DeviceType, medium Medium) error { cname := C.CString(controllerName) result := C.GoVboxMachineAttachDevice(machine.cmachine, cname, C.PRInt32(controllerPort), C.PRInt32(deviceSlot), C.PRUint32(deviceType), medium.cmedium) C.free(unsafe.Pointer(cname)) if C.GoVboxFAILED(result) != 0 { return errors.New( fmt.Sprintf("Failed to attach IMedium to IMachine: %x", result)) } return nil }
// UnmountMedium ejects a removable Medium from this VM. // It returns any error encountered. func (machine *Machine) UnmountMedium(controllerName string, controllerPort int, deviceSlot int, force bool) error { cforce := C.PRBool(0) if force { cforce = C.PRBool(1) } cname := C.CString(controllerName) result := C.GoVboxMachineUnmountMedium(machine.cmachine, cname, C.PRInt32(controllerPort), C.PRInt32(deviceSlot), cforce) C.free(unsafe.Pointer(cname)) if C.GoVboxFAILED(result) != 0 { return errors.New( fmt.Sprintf("Failed to unmount medium from IMachine: %x", result)) } return nil }
// PutScancodes posts keyboard scancodes to the guest OS event queue. // It returns any error encountered. func (keyboard *Keyboard) PutScancodes(scancodes []int) (uint, error) { scancodesCount := len(scancodes) cscancodes := make([]C.PRInt32, scancodesCount) for i, scancode := range scancodes { cscancodes[i] = C.PRInt32(scancode) } var ccodesStored C.PRUint32 result := C.GoVboxKeyboardPutScancodes(keyboard.ckeyboard, C.PRUint32(scancodesCount), &cscancodes[0], &ccodesStored) if C.GoVboxFAILED(result) != 0 { return uint(ccodesStored), errors.New( fmt.Sprintf("Failed to post IKeyboard scancodes: %x", result)) } return uint(ccodesStored), nil }