Esempio n. 1
0
// ComposeMachineFilename returns a default VM config file path.
// If baseFolder is empty, VirtualBox's default machine folder will be used.
// It returns a string and any error encountered.
func ComposeMachineFilename(
	name string, flags string, baseFolder string) (string, error) {
	if err := Init(); err != nil {
		return "", err
	}

	var cpath *C.char
	cname := C.CString(name)
	cflags := C.CString(flags)
	cbaseFolder := C.CString(baseFolder)
	result := C.GoVboxComposeMachineFilename(cbox, cname, cflags, cbaseFolder,
		&cpath)
	C.free(unsafe.Pointer(cname))
	C.free(unsafe.Pointer(cflags))
	C.free(unsafe.Pointer(cbaseFolder))

	if C.GoVboxFAILED(result) != 0 || cpath == nil {
		return "", errors.New(
			fmt.Sprintf("IVirtualBox failed to compose machine name: %x", result))
	}

	path := C.GoString(cpath)
	C.GoVboxUtf8Free(cpath)
	return path, nil
}
Esempio n. 2
0
// GetSettingsFilePath returns the path of the machine's settings file.
// It returns a string and any error encountered.
func (machine *Machine) GetSettingsFilePath() (string, error) {
	var cpath *C.char
	result := C.GoVboxGetMachineSettingsFilePath(machine.cmachine, &cpath)
	if C.GoVboxFAILED(result) != 0 || cpath == nil {
		return "", errors.New(
			fmt.Sprintf("Failed to get IMachine settings file path: %x", result))
	}

	path := C.GoString(cpath)
	C.GoVboxUtf8Free(cpath)
	return path, nil
}
Esempio n. 3
0
// GetLocation returns the path to the image file backing the storage medium.
// It returns a string and any error encountered.
func (medium *Medium) GetLocation() (string, error) {
	var clocation *C.char
	result := C.GoVboxGetMediumLocation(medium.cmedium, &clocation)
	if C.GoVboxFAILED(result) != 0 || clocation == nil {
		return "", errors.New(
			fmt.Sprintf("Failed to get IMedium location: %x", result))
	}

	id := C.GoString(clocation)
	C.GoVboxUtf8Free(clocation)
	return id, nil
}
Esempio n. 4
0
// GetOsTypeId returns a string used to identify the guest OS type.
// It returns a string and any error encountered.
func (machine *Machine) GetOsTypeId() (string, error) {
	var cosTypeId *C.char
	result := C.GoVboxGetMachineOSTypeId(machine.cmachine, &cosTypeId)
	if C.GoVboxFAILED(result) != 0 || cosTypeId == nil {
		return "", errors.New(
			fmt.Sprintf("Failed to get IMachine OS type ID: %x", result))
	}

	osTypeId := C.GoString(cosTypeId)
	C.GoVboxUtf8Free(cosTypeId)
	return osTypeId, nil
}
Esempio n. 5
0
// GetName returns the machine's name.
// It returns a string and any error encountered.
func (machine *Machine) GetName() (string, error) {
	var cname *C.char
	result := C.GoVboxGetMachineName(machine.cmachine, &cname)
	if C.GoVboxFAILED(result) != 0 || cname == nil {
		return "", errors.New(
			fmt.Sprintf("Failed to get IMachine name: %x", result))
	}

	name := C.GoString(cname)
	C.GoVboxUtf8Free(cname)
	return name, nil
}
Esempio n. 6
0
// GetId returns the string used to identify this format in other API calls.
// It returns a string and any error encountered.
func (format *MediumFormat) GetId() (string, error) {
	var cid *C.char
	result := C.GoVboxGetMediumFormatId(format.cformat, &cid)
	if C.GoVboxFAILED(result) != 0 || cid == nil {
		return "", errors.New(
			fmt.Sprintf("Failed to get IMediumFormat id: %x", result))
	}

	id := C.GoString(cid)
	C.GoVboxUtf8Free(cid)
	return id, nil
}
Esempio n. 7
0
// GetId returns the string used to identify this OS type in other API calls.
// It returns a string and any error encountered.
func (osType *GuestOsType) GetId() (string, error) {
  var cid *C.char
  result := C.GoVboxGetGuestOSTypeId(osType.ctype, &cid)
  if C.GoVboxFAILED(result) != 0 || cid == nil {
    return "", errors.New(
        fmt.Sprintf("Failed to get IGuestOSType id: %x", result))
  }

  id := C.GoString(cid)
  C.GoVboxUtf8Free(cid)
  return id, nil
}
Esempio n. 8
0
// GetName returns the controller's name.
// It returns a string and any error encountered.
func (controller *UsbController) GetName() (string, error) {
	var cname *C.char
	result := C.GoVboxGetUsbControllerName(controller.ccontroller, &cname)
	if C.GoVboxFAILED(result) != 0 || cname == nil {
		return "", errors.New(
			fmt.Sprintf("Failed to get IUsbController name: %x", result))
	}

	name := C.GoString(cname)
	C.GoVboxUtf8Free(cname)
	return name, nil
}