Ejemplo n.º 1
0
func main() {
	if err := vbox.Init(); err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}

	vm, err := vbox.FindMachine("vbox-sample-vm")
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
	defer vm.Release()

	// NOTE: The exact cleanup mode is inconsequential for this sample, but we
	//       want to show the generally recommended value.
	media, err := vm.Unregister(vbox.CleanupMode_DetachAllReturnHardDisksOnly)
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}

	progress, err := vm.DeleteConfig(media)
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}

	if err = progress.WaitForCompletion(-1); err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}

	percent, err := progress.GetPercent()
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
	if percent != 100 {
		fmt.Printf("Config deletion stopped at %d%%\n", percent)
		os.Exit(1)
	}

	result, err := progress.GetResultCode()
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
	if result != 0 {
		fmt.Printf("Config deletion failed with code %x\n", percent)
		os.Exit(1)
	}
}
Ejemplo n.º 2
0
func main() {
	if err := vbox.Init(); err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}

	vm, err := vbox.CreateMachine("vbox-sample-vm", "Linux", "")
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
	defer vm.Release()

	if err = vm.Register(); err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
}
Ejemplo n.º 3
0
func main() {
	if err := vbox.Init(); err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}

	machine, err := vbox.FindMachine("Lubuntu")
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
	defer machine.Release()

	session := vbox.Session{}
	if err := session.Init(); err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
	defer session.Release()

	if err := session.LockMachine(machine, vbox.LockType_Shared); err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
	defer func() {
		if err := session.UnlockMachine(); err != nil {
			fmt.Printf("%v\n", err)
		}
	}()

	console, err := session.GetConsole()
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
	defer console.Release()

	mouse, err := console.GetMouse()
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
	defer mouse.Release()

	hasRelative, err := mouse.GetRelativeSupported()
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Relative mouse support: %v\n", hasRelative)

	hasAbsolute, err := mouse.GetAbsoluteSupported()
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Absolute mouse support: %v\n", hasAbsolute)

	err = mouse.PutEventAbsolute(200, 200, 0, 0, vbox.MouseButtonState_RightButton)
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}

	// The dummy relative event is necessary to get the cursor to show up.
	err = mouse.PutEvent(0, 0, 0, 0, vbox.MouseButtonState_RightButton)
	if err != nil {
		fmt.Printf("%v\n", err)
		os.Exit(1)
	}
}