From 9140985ab0d49ea8f5b824051e52dd99ecb3837d Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 8 Sep 2020 16:33:18 -0700 Subject: [PATCH] implement cd_files for qemu builder --- builder/qemu/builder.go | 6 ++++++ builder/qemu/step_run.go | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index ea2cc326c..4ac90dde3 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -77,6 +77,7 @@ type Config struct { shutdowncommand.ShutdownConfig `mapstructure:",squash"` CommConfig CommConfig `mapstructure:",squash"` common.FloppyConfig `mapstructure:",squash"` + common.CDConfig `mapstructure:",squash"` // Use iso from provided url. Qemu must support // curl block device. This defaults to `false`. ISOSkipCache bool `mapstructure:"iso_skip_cache" required:"false"` @@ -469,6 +470,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { } errs = packer.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(&b.config.ctx)...) + errs = packer.MultiErrorAppend(errs, b.config.CDConfig.Prepare(&b.config.ctx)...) errs = packer.MultiErrorAppend(errs, b.config.VNCConfig.Prepare(&b.config.ctx)...) if b.config.NetDevice == "" { @@ -622,6 +624,10 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack Directories: b.config.FloppyConfig.FloppyDirectories, Label: b.config.FloppyConfig.FloppyLabel, }, + &common.StepCreateCD{ + Files: b.config.CDConfig.CDFiles, + Label: b.config.CDConfig.CDLabel, + }, new(stepCreateDisk), new(stepCopyDisk), new(stepResizeDisk), diff --git a/builder/qemu/step_run.go b/builder/qemu/step_run.go index daf29655c..f7d277b4e 100644 --- a/builder/qemu/step_run.go +++ b/builder/qemu/step_run.go @@ -190,14 +190,26 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error } } + cdPaths := []string{} + // Add the installation CD to the run command if !config.DiskImage { + cdPaths = append(cdPaths, isoPath) + } + // Add our custom CD created from cd_files, if it exists + cdFilesPath, ok := state.Get("cd_path").(string) + if ok { + if cdFilesPath != "" { + cdPaths = append(cdPaths, cdFilesPath) + } + } + for i, cdPath := range cdPaths { if config.CDROMInterface == "" { - defaultArgs["-cdrom"] = isoPath + driveArgs = append(driveArgs, fmt.Sprintf("file=%s,index=%d,media=cdrom", cdPath, i)) } else if config.CDROMInterface == "virtio-scsi" { - driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=none,id=cdrom,media=cdrom", isoPath)) - deviceArgs = append(deviceArgs, "virtio-scsi-device", "scsi-cd,drive=cdrom") + driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=none,index=%d,id=cdrom%d,media=cdrom", cdPath, i, i)) + deviceArgs = append(deviceArgs, "virtio-scsi-device", fmt.Sprintf("scsi-cd,drive=cdrom%d", i)) } else { - driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=%s,id=cdrom,media=cdrom", isoPath, config.CDROMInterface)) + driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=%s,index=%d,id=cdrom%d,media=cdrom", cdPath, config.CDROMInterface, i, i)) } }