2013-09-02 23:23:52 -04:00
|
|
|
package qemu
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2013-09-02 23:23:52 -04:00
|
|
|
"fmt"
|
2013-12-06 19:20:25 -05:00
|
|
|
"log"
|
2013-09-02 23:23:52 -04:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2014-10-03 11:39:57 -04:00
|
|
|
|
2019-05-06 17:27:19 -04:00
|
|
|
"github.com/hashicorp/go-version"
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2020-11-11 13:21:37 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
|
2013-09-02 23:23:52 -04:00
|
|
|
)
|
|
|
|
|
2013-11-06 00:40:49 -05:00
|
|
|
// stepRun runs the virtual machine
|
2013-09-02 23:23:52 -04:00
|
|
|
type stepRun struct {
|
2020-09-15 19:14:52 -04:00
|
|
|
DiskImage bool
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
atLeastVersion2 bool
|
2020-11-19 14:54:31 -05:00
|
|
|
ui packersdk.Ui
|
2013-12-06 19:20:25 -05:00
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *stepRun) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2020-09-18 12:39:32 -04:00
|
|
|
config := state.Get("config").(*Config)
|
2013-11-06 00:40:49 -05:00
|
|
|
driver := state.Get("driver").(Driver)
|
2020-11-19 14:54:31 -05:00
|
|
|
s.ui = state.Get("ui").(packersdk.Ui)
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
// Figure out version of qemu; store on step for later use
|
|
|
|
rawVersion, err := driver.Version()
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error determining qemu version: %s", err)
|
|
|
|
s.ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
2020-09-15 19:14:52 -04:00
|
|
|
}
|
2020-09-18 12:39:32 -04:00
|
|
|
qemuVersion, err := version.NewVersion(rawVersion)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error parsing qemu version: %s", err)
|
|
|
|
s.ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
v2 := version.Must(version.NewVersion("2.0"))
|
2013-11-06 00:40:49 -05:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
s.atLeastVersion2 = qemuVersion.GreaterThanOrEqual(v2)
|
|
|
|
|
|
|
|
// Generate the qemu command
|
|
|
|
command, err := s.getCommandArgs(config, state)
|
2013-12-06 19:20:25 -05:00
|
|
|
if err != nil {
|
2016-09-19 17:34:10 -04:00
|
|
|
err := fmt.Errorf("Error processing QemuArgs: %s", err)
|
2020-09-18 12:39:32 -04:00
|
|
|
s.ui.Error(err.Error())
|
2013-12-06 19:20:25 -05:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
// run the qemu command
|
2013-11-06 00:40:49 -05:00
|
|
|
if err := driver.Qemu(command...); err != nil {
|
|
|
|
err := fmt.Errorf("Error launching VM: %s", err)
|
2020-09-18 12:39:32 -04:00
|
|
|
s.ui.Error(err.Error())
|
2013-11-06 00:40:49 -05:00
|
|
|
return multistep.ActionHalt
|
2013-09-02 23:23:52 -04:00
|
|
|
}
|
|
|
|
|
2013-11-06 00:40:49 -05:00
|
|
|
return multistep.ActionContinue
|
2013-09-02 23:23:52 -04:00
|
|
|
}
|
|
|
|
|
2013-11-06 00:40:49 -05:00
|
|
|
func (s *stepRun) Cleanup(state multistep.StateBag) {
|
|
|
|
driver := state.Get("driver").(Driver)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2013-11-06 00:40:49 -05:00
|
|
|
|
|
|
|
if err := driver.Stop(); err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Error shutting down VM: %s", err))
|
2013-09-02 23:23:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
func (s *stepRun) getDefaultArgs(config *Config, state multistep.StateBag) map[string]interface{} {
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2015-09-08 06:58:21 -04:00
|
|
|
defaultArgs := make(map[string]interface{})
|
2019-07-03 20:38:56 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
// Configure "boot" arguement
|
|
|
|
// Run command is different depending whether we're booting from an
|
|
|
|
// installation CD or a pre-baked image
|
|
|
|
bootDrive := "once=d"
|
|
|
|
message := "Starting VM, booting from CD-ROM"
|
|
|
|
if s.DiskImage {
|
|
|
|
bootDrive = "c"
|
|
|
|
message = "Starting VM, booting disk image"
|
2020-05-03 09:47:03 -04:00
|
|
|
}
|
2020-09-18 12:39:32 -04:00
|
|
|
s.ui.Say(message)
|
|
|
|
defaultArgs["-boot"] = bootDrive
|
2020-05-03 09:47:03 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
// configure "-qmp" arguments
|
2020-05-03 09:47:03 -04:00
|
|
|
if config.QMPEnable {
|
2019-07-16 10:55:19 -04:00
|
|
|
defaultArgs["-qmp"] = fmt.Sprintf("unix:%s,server,nowait", config.QMPSocketPath)
|
2019-07-03 20:38:56 -04:00
|
|
|
}
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
// configure "-name" arguments
|
|
|
|
defaultArgs["-name"] = config.VMName
|
2020-05-03 09:47:03 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
// Configure "-machine" arguments
|
|
|
|
if config.Accelerator == "none" {
|
|
|
|
defaultArgs["-machine"] = fmt.Sprintf("type=%s", config.MachineType)
|
|
|
|
s.ui.Message("WARNING: The VM will be started with no hardware acceleration.\n" +
|
|
|
|
"The installation may take considerably longer to finish.\n")
|
|
|
|
} else {
|
|
|
|
defaultArgs["-machine"] = fmt.Sprintf("type=%s,accel=%s",
|
|
|
|
config.MachineType, config.Accelerator)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure "-netdev" arguments
|
|
|
|
defaultArgs["-netdev"] = fmt.Sprintf("bridge,id=user.0,br=%s", config.NetBridge)
|
2020-05-03 09:47:03 -04:00
|
|
|
if config.NetBridge == "" {
|
2020-09-18 12:39:32 -04:00
|
|
|
defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0")
|
2020-06-02 05:56:36 -04:00
|
|
|
if config.CommConfig.Comm.Type != "none" {
|
2020-09-18 12:39:32 -04:00
|
|
|
commHostPort := state.Get("commHostPort").(int)
|
2020-06-02 05:56:36 -04:00
|
|
|
defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0,hostfwd=tcp::%v-:%d", commHostPort, config.CommConfig.Comm.Port())
|
2020-05-03 09:47:03 -04:00
|
|
|
}
|
2016-07-06 11:52:40 -04:00
|
|
|
}
|
2015-09-08 06:58:21 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
// Configure "-vnc" arguments
|
|
|
|
// vncPort is always set in stepConfigureVNC, so we don't need to
|
|
|
|
// defensively assert
|
|
|
|
vncPort := state.Get("vnc_port").(int)
|
|
|
|
vncIP := config.VNCBindAddress
|
|
|
|
|
|
|
|
vncPort = vncPort - config.VNCPortMin
|
|
|
|
vnc := fmt.Sprintf("%s:%d", vncIP, vncPort)
|
|
|
|
if config.VNCUsePassword {
|
|
|
|
vnc = fmt.Sprintf("%s:%d,password", vncIP, vncPort)
|
2015-09-08 06:58:21 -04:00
|
|
|
}
|
2020-09-18 12:39:32 -04:00
|
|
|
defaultArgs["-vnc"] = vnc
|
|
|
|
|
|
|
|
// Track the connection for the user
|
|
|
|
vncPass, _ := state.Get("vnc_password").(string)
|
|
|
|
|
|
|
|
message = getVncConnectionMessage(config.Headless, vnc, vncPass)
|
|
|
|
if message != "" {
|
|
|
|
s.ui.Message(message)
|
2019-08-29 08:13:46 -04:00
|
|
|
}
|
2019-05-06 17:27:19 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
// Configure "-m" memory argument
|
|
|
|
defaultArgs["-m"] = fmt.Sprintf("%dM", config.MemorySize)
|
|
|
|
|
|
|
|
// Configure "-smp" processor hardware arguments
|
|
|
|
if config.CpuCount > 1 {
|
|
|
|
defaultArgs["-smp"] = fmt.Sprintf("cpus=%d,sockets=%d", config.CpuCount, config.CpuCount)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure "-fda" floppy disk attachment
|
|
|
|
if floppyPathRaw, ok := state.GetOk("floppy_path"); ok {
|
|
|
|
defaultArgs["-fda"] = floppyPathRaw.(string)
|
|
|
|
} else {
|
|
|
|
log.Println("Qemu Builder has no floppy files, not attaching a floppy.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure GUI display
|
|
|
|
if !config.Headless {
|
|
|
|
if s.atLeastVersion2 {
|
|
|
|
// FIXME: "none" is a valid display option in qemu but we have
|
|
|
|
// departed from the qemu usage here to instaed mean "let qemu
|
|
|
|
// set a reasonable default". We need to deprecate this behavior
|
|
|
|
// and let users just set "UseDefaultDisplay" if they want to let
|
|
|
|
// qemu do its thing.
|
|
|
|
if len(config.Display) > 0 && config.Display != "none" {
|
|
|
|
defaultArgs["-display"] = config.Display
|
|
|
|
} else if !config.UseDefaultDisplay {
|
|
|
|
defaultArgs["-display"] = "gtk"
|
2018-12-03 18:52:13 -05:00
|
|
|
}
|
2015-09-08 06:58:21 -04:00
|
|
|
} else {
|
2020-09-18 12:39:32 -04:00
|
|
|
s.ui.Message("WARNING: The version of qemu on your host doesn't support display mode.\n" +
|
|
|
|
"The display parameter will be ignored.")
|
2015-09-08 06:40:23 -04:00
|
|
|
}
|
|
|
|
}
|
2015-09-08 06:58:21 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
deviceArgs, driveArgs := s.getDeviceAndDriveArgs(config, state)
|
|
|
|
defaultArgs["-device"] = deviceArgs
|
|
|
|
defaultArgs["-drive"] = driveArgs
|
2016-05-25 05:10:12 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
return defaultArgs
|
|
|
|
}
|
2019-07-03 20:38:56 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
func getVncConnectionMessage(headless bool, vnc string, vncPass string) string {
|
|
|
|
// Configure GUI display
|
|
|
|
if headless {
|
|
|
|
if vnc == "" {
|
|
|
|
return "The VM will be run headless, without a GUI, as configured.\n" +
|
|
|
|
"If the run isn't succeeding as you expect, please enable the GUI\n" +
|
|
|
|
"to inspect the progress of the build."
|
|
|
|
}
|
2016-05-25 05:10:12 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
if vncPass != "" {
|
|
|
|
return fmt.Sprintf(
|
2016-05-25 05:10:12 -04:00
|
|
|
"The VM will be run headless, without a GUI. If you want to\n"+
|
2020-09-18 12:39:32 -04:00
|
|
|
"view the screen of the VM, connect via VNC to vnc://%s\n"+
|
|
|
|
"with the password: %s", vnc, vncPass)
|
2016-05-25 05:10:12 -04:00
|
|
|
}
|
2020-09-18 12:39:32 -04:00
|
|
|
|
|
|
|
return fmt.Sprintf(
|
|
|
|
"The VM will be run headless, without a GUI. If you want to\n"+
|
|
|
|
"view the screen of the VM, connect via VNC without a password to\n"+
|
|
|
|
"vnc://%s", vnc)
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepRun) getDeviceAndDriveArgs(config *Config, state multistep.StateBag) ([]string, []string) {
|
|
|
|
var deviceArgs []string
|
|
|
|
var driveArgs []string
|
|
|
|
|
|
|
|
vmName := config.VMName
|
|
|
|
imgPath := filepath.Join(config.OutputDir, vmName)
|
|
|
|
|
|
|
|
// Configure virtual hard drives
|
|
|
|
if s.atLeastVersion2 {
|
|
|
|
drivesToAttach := []string{}
|
|
|
|
|
2020-11-30 10:40:03 -05:00
|
|
|
if v, ok := state.GetOk("qemu_disk_paths"); ok {
|
|
|
|
diskFullPaths := v.([]string)
|
|
|
|
drivesToAttach = append(drivesToAttach, diskFullPaths...)
|
|
|
|
}
|
2020-09-18 12:39:32 -04:00
|
|
|
|
|
|
|
for i, drivePath := range drivesToAttach {
|
|
|
|
driveArgumentString := fmt.Sprintf("file=%s,if=%s,cache=%s,discard=%s,format=%s", drivePath, config.DiskInterface, config.DiskCache, config.DiskDiscard, config.Format)
|
|
|
|
if config.DiskInterface == "virtio-scsi" {
|
|
|
|
// TODO: Megan: Remove this conditional. This, and the code
|
|
|
|
// under the TODO below, reproduce the old behavior. While it
|
|
|
|
// may be broken, the goal of this commit is to refactor in a way
|
|
|
|
// that creates a result that is testably the same as the old
|
|
|
|
// code. A pr will follow fixing this broken behavior.
|
|
|
|
if i == 0 {
|
|
|
|
deviceArgs = append(deviceArgs, fmt.Sprintf("virtio-scsi-pci,id=scsi%d", i))
|
2019-10-02 16:56:05 -04:00
|
|
|
}
|
2020-09-18 12:39:32 -04:00
|
|
|
// TODO: Megan: When you remove above conditional,
|
|
|
|
// set deviceArgs = append(deviceArgs, fmt.Sprintf("scsi-hd,bus=scsi%d.0,drive=drive%d", i, i))
|
|
|
|
deviceArgs = append(deviceArgs, fmt.Sprintf("scsi-hd,bus=scsi0.0,drive=drive%d", i))
|
|
|
|
driveArgumentString = fmt.Sprintf("if=none,file=%s,id=drive%d,cache=%s,discard=%s,format=%s", drivePath, i, config.DiskCache, config.DiskDiscard, config.Format)
|
2016-12-16 20:33:33 -05:00
|
|
|
}
|
2020-09-18 12:39:32 -04:00
|
|
|
if config.DetectZeroes != "off" {
|
|
|
|
driveArgumentString = fmt.Sprintf("%s,detect-zeroes=%s", driveArgumentString, config.DetectZeroes)
|
|
|
|
}
|
|
|
|
driveArgs = append(driveArgs, driveArgumentString)
|
2015-09-08 06:58:21 -04:00
|
|
|
}
|
2020-09-18 12:39:32 -04:00
|
|
|
} else {
|
|
|
|
driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=%s,cache=%s,format=%s", imgPath, config.DiskInterface, config.DiskCache, config.Format))
|
2015-09-08 06:58:21 -04:00
|
|
|
}
|
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
deviceArgs = append(deviceArgs, fmt.Sprintf("%s,netdev=user.0", config.NetDevice))
|
|
|
|
|
|
|
|
// Configure virtual CDs
|
2020-09-08 19:33:18 -04:00
|
|
|
cdPaths := []string{}
|
|
|
|
// Add the installation CD to the run command
|
2020-07-07 10:22:30 -04:00
|
|
|
if !config.DiskImage {
|
2020-09-18 12:39:32 -04:00
|
|
|
isoPath := state.Get("iso_path").(string)
|
2020-09-08 19:33:18 -04:00
|
|
|
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 {
|
2020-07-07 10:22:30 -04:00
|
|
|
if config.CDROMInterface == "" {
|
2020-09-08 19:33:18 -04:00
|
|
|
driveArgs = append(driveArgs, fmt.Sprintf("file=%s,index=%d,media=cdrom", cdPath, i))
|
2020-07-07 10:22:30 -04:00
|
|
|
} else if config.CDROMInterface == "virtio-scsi" {
|
2020-09-08 19:33:18 -04:00
|
|
|
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))
|
2020-07-07 10:22:30 -04:00
|
|
|
} else {
|
2020-09-08 19:33:18 -04:00
|
|
|
driveArgs = append(driveArgs, fmt.Sprintf("file=%s,if=%s,index=%d,id=cdrom%d,media=cdrom", cdPath, config.CDROMInterface, i, i))
|
2020-07-07 10:22:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
return deviceArgs, driveArgs
|
|
|
|
}
|
2014-09-02 12:24:31 -04:00
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
func (s *stepRun) applyUserOverrides(defaultArgs map[string]interface{}, config *Config, state multistep.StateBag) ([]string, error) {
|
|
|
|
// Done setting up defaults; time to process user args and defaults together
|
|
|
|
// and generate output args
|
2013-12-06 19:20:25 -05:00
|
|
|
|
2013-10-07 21:58:08 -04:00
|
|
|
inArgs := make(map[string][]string)
|
|
|
|
if len(config.QemuArgs) > 0 {
|
2020-09-18 12:39:32 -04:00
|
|
|
s.ui.Say("Overriding default Qemu arguments with qemuargs template option...")
|
2013-10-07 21:58:08 -04:00
|
|
|
|
2020-10-21 16:33:54 -04:00
|
|
|
commHostPort := 0
|
|
|
|
if config.CommConfig.Comm.Type != "none" {
|
2020-11-30 10:40:03 -05:00
|
|
|
if v, ok := state.GetOk("commHostPort"); ok {
|
|
|
|
commHostPort = v.(int)
|
|
|
|
}
|
2020-10-21 16:33:54 -04:00
|
|
|
}
|
2020-05-21 12:39:54 -04:00
|
|
|
httpIp := state.Get("http_ip").(string)
|
2019-03-19 09:47:21 -04:00
|
|
|
httpPort := state.Get("http_port").(int)
|
2020-09-18 12:39:32 -04:00
|
|
|
|
|
|
|
type qemuArgsTemplateData struct {
|
|
|
|
HTTPIP string
|
|
|
|
HTTPPort int
|
|
|
|
HTTPDir string
|
|
|
|
OutputDir string
|
|
|
|
Name string
|
|
|
|
SSHHostPort int
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
ictx := config.ctx
|
2020-09-18 12:39:32 -04:00
|
|
|
ictx.Data = qemuArgsTemplateData{
|
|
|
|
HTTPIP: httpIp,
|
|
|
|
HTTPPort: httpPort,
|
|
|
|
HTTPDir: config.HTTPDir,
|
|
|
|
OutputDir: config.OutputDir,
|
|
|
|
Name: config.VMName,
|
|
|
|
SSHHostPort: commHostPort,
|
2013-12-06 19:20:25 -05:00
|
|
|
}
|
2020-09-18 12:39:32 -04:00
|
|
|
|
|
|
|
// Interpolate each string in qemuargs
|
2019-03-29 11:50:02 -04:00
|
|
|
newQemuArgs, err := processArgs(config.QemuArgs, &ictx)
|
2013-12-06 19:20:25 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
// Qemu supports multiple appearances of the same switch. This means
|
|
|
|
// each key in the args hash will have an array of string values
|
2013-12-06 19:20:25 -05:00
|
|
|
for _, qemuArgs := range newQemuArgs {
|
2013-10-07 21:58:08 -04:00
|
|
|
key := qemuArgs[0]
|
|
|
|
val := strings.Join(qemuArgs[1:], "")
|
|
|
|
if _, ok := inArgs[key]; !ok {
|
|
|
|
inArgs[key] = make([]string, 0)
|
|
|
|
}
|
|
|
|
if len(val) > 0 {
|
|
|
|
inArgs[key] = append(inArgs[key], val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get any remaining missing default args from the default settings
|
|
|
|
for key := range defaultArgs {
|
|
|
|
if _, ok := inArgs[key]; !ok {
|
|
|
|
arg := make([]string, 1)
|
2015-09-08 06:58:21 -04:00
|
|
|
switch defaultArgs[key].(type) {
|
|
|
|
case string:
|
|
|
|
arg[0] = defaultArgs[key].(string)
|
|
|
|
case []string:
|
|
|
|
arg = defaultArgs[key].([]string)
|
|
|
|
}
|
2013-10-07 21:58:08 -04:00
|
|
|
inArgs[key] = arg
|
2019-12-03 07:42:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we are missing the netDevice #6804
|
|
|
|
if x, ok := inArgs["-device"]; ok {
|
|
|
|
if !strings.Contains(strings.Join(x, ""), config.NetDevice) {
|
|
|
|
inArgs["-device"] = append(inArgs["-device"], fmt.Sprintf("%s,netdev=user.0", config.NetDevice))
|
2018-10-06 08:40:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-07 21:58:08 -04:00
|
|
|
// Flatten to array of strings
|
|
|
|
outArgs := make([]string, 0)
|
|
|
|
for key, values := range inArgs {
|
|
|
|
if len(values) > 0 {
|
|
|
|
for idx := range values {
|
|
|
|
outArgs = append(outArgs, key, values[idx])
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
outArgs = append(outArgs, key)
|
|
|
|
}
|
2013-09-02 23:23:52 -04:00
|
|
|
}
|
2013-10-07 21:58:08 -04:00
|
|
|
|
2013-12-06 19:20:25 -05:00
|
|
|
return outArgs, nil
|
|
|
|
}
|
|
|
|
|
2020-09-18 12:39:32 -04:00
|
|
|
func (s *stepRun) getCommandArgs(config *Config, state multistep.StateBag) ([]string, error) {
|
|
|
|
defaultArgs := s.getDefaultArgs(config, state)
|
|
|
|
|
|
|
|
return s.applyUserOverrides(defaultArgs, config, state)
|
|
|
|
}
|
|
|
|
|
2015-05-27 16:39:43 -04:00
|
|
|
func processArgs(args [][]string, ctx *interpolate.Context) ([][]string, error) {
|
2013-12-06 19:20:25 -05:00
|
|
|
var err error
|
|
|
|
|
|
|
|
if args == nil {
|
|
|
|
return make([][]string, 0), err
|
|
|
|
}
|
|
|
|
|
|
|
|
newArgs := make([][]string, len(args))
|
|
|
|
for argsIdx, rowArgs := range args {
|
|
|
|
parms := make([]string, len(rowArgs))
|
|
|
|
newArgs[argsIdx] = parms
|
|
|
|
for i, parm := range rowArgs {
|
2015-05-27 16:39:43 -04:00
|
|
|
parms[i], err = interpolate.Render(parm, ctx)
|
2013-12-06 19:20:25 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newArgs, err
|
2013-10-07 21:58:08 -04:00
|
|
|
}
|