Added option for audio controller.

This commit is contained in:
Thomas Dreibholz 2021-02-20 20:09:16 +01:00
parent eb4a6f30a0
commit e9936cf0da
No known key found for this signature in database
GPG Key ID: 5CD5D12AA0877B49
2 changed files with 17 additions and 2 deletions

View File

@ -64,6 +64,11 @@ type Config struct {
// When set to Am79C960, the NICs are AMD PCnet-ISA/NE2100 (Am79C960). // When set to Am79C960, the NICs are AMD PCnet-ISA/NE2100 (Am79C960).
// When set to virtio, the NICs are VirtIO. // When set to virtio, the NICs are VirtIO.
NICType string `mapstructure:"nic_type" required:"false"` NICType string `mapstructure:"nic_type" required:"false"`
// The audio controller type to be used.
// When set to ac97, the audio controller is ICH AC97 (default).
// When set to hda, the audio controller is Intel HD Audio.
// When set to sb16, the audio controller is SoundBlaster 16.
AudioController string `mapstructure:"audio_controller" required:"false"`
// The guest OS type being installed. By default this is other, but you can // The guest OS type being installed. By default this is other, but you can
// get dramatic performance improvements by setting this to the proper // get dramatic performance improvements by setting this to the proper
// value. To view all available values for this run VBoxManage list // value. To view all available values for this run VBoxManage list
@ -220,6 +225,14 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
errs, errors.New("NIC type can only be 82540EM, 82543GC, 82545EM, Am79C970A, Am79C973, Am79C960 or virtio")) errs, errors.New("NIC type can only be 82540EM, 82543GC, 82545EM, Am79C970A, Am79C973, Am79C960 or virtio"))
} }
switch b.config.AudioController {
case "ac97", "hda", "sb16":
// do nothing
default:
errs = packersdk.MultiErrorAppend(
errs, errors.New("Audio controller type can only be ac97, hda or sb16"))
}
if b.config.GuestOSType == "" { if b.config.GuestOSType == "" {
b.config.GuestOSType = "Other" b.config.GuestOSType = "Other"
} }

View File

@ -40,9 +40,11 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
commands[4] = []string{"modifyvm", name, "--usb", map[bool]string{true: "on", false: "off"}[config.HWConfig.USB]} commands[4] = []string{"modifyvm", name, "--usb", map[bool]string{true: "on", false: "off"}[config.HWConfig.USB]}
if strings.ToLower(config.HWConfig.Sound) == "none" { if strings.ToLower(config.HWConfig.Sound) == "none" {
commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound} commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound,
"--audiocontroller", config.AudioController}
} else { } else {
commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound, "--audioin", "on", "--audioout", "on"} commands[5] = []string{"modifyvm", name, "--audio", config.HWConfig.Sound, "--audioin", "on", "--audioout", "on",
"--audiocontroller", config.AudioController}
} }
commands[6] = []string{"modifyvm", name, "--chipset", config.Chipset} commands[6] = []string{"modifyvm", name, "--chipset", config.Chipset}