packer-cn/builder/virtualbox/driver.go

54 lines
1.3 KiB
Go
Raw Normal View History

package virtualbox
import (
"log"
"os/exec"
)
// A driver is able to talk to VirtualBox and perform certain
// operations with it.
type Driver interface {
// SuppressMessages should do what needs to be done in order to
// suppress any annoying popups from VirtualBox.
SuppressMessages() error
// Verify checks to make sure that this driver should function
// properly. If there is any indication the driver can't function,
// this will return an error.
Verify() error
}
type VBox42Driver struct {
// This is the path to the "VBoxManage" application.
VBoxManagePath string
}
func (d *VBox42Driver) SuppressMessages() error {
extraData := map[string]string{
"GUI/RegistrationData": "triesLeft=0",
"GUI/SuppressMessages": "confirmInputCapture,remindAboutAutoCapture,remindAboutMouseIntegrationOff,remindAboutMouseIntegrationOn,remindAboutWrongColorDepth",
}
for k, v := range extraData {
if err := d.vboxmanage("setextradata", "global", k, v); err != nil {
return err
}
}
return nil
}
func (d *VBox42Driver) Verify() error {
return nil
}
func (d *VBox42Driver) vboxmanage(args ...string) error {
log.Printf("Executing VBoxManage: %#v", args)
cmd := exec.Command(d.VBoxManagePath, args...)
if err := cmd.Run(); err != nil {
return err
}
return nil
}