builder/qemu: Replace dot-based parsing with hashicorp/go-version

This commit is contained in:
Radek Simko 2019-05-06 22:27:19 +01:00
parent 3e65b5dbcb
commit c7cf39808d
No known key found for this signature in database
GPG Key ID: 1F1C84FE689A88D7
1 changed files with 7 additions and 9 deletions

View File

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"log" "log"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"github.com/hashicorp/go-version"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate" "github.com/hashicorp/packer/template/interpolate"
@ -85,16 +85,14 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0") defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0")
} }
qemuVersion, err := driver.Version() rawVersion, err := driver.Version()
if err != nil { if err != nil {
return nil, err return nil, err
} }
parts := strings.Split(qemuVersion, ".") qemuVersion, err := version.NewVersion(rawVersion)
qemuMajor, err := strconv.Atoi(parts[0]) v2 := version.Must(version.NewVersion("1.2"))
if err != nil {
return nil, err if qemuVersion.GreaterThanOrEqual(v2) {
}
if qemuMajor >= 2 {
if config.DiskInterface == "virtio-scsi" { if config.DiskInterface == "virtio-scsi" {
deviceArgs = append(deviceArgs, "virtio-scsi-pci,id=scsi0", "scsi-hd,bus=scsi0.0,drive=drive0") deviceArgs = append(deviceArgs, "virtio-scsi-pci,id=scsi0", "scsi-hd,bus=scsi0.0,drive=drive0")
driveArgumentString := fmt.Sprintf("if=none,file=%s,id=drive0,cache=%s,discard=%s,format=%s", imgPath, config.DiskCache, config.DiskDiscard, config.Format) driveArgumentString := fmt.Sprintf("if=none,file=%s,id=drive0,cache=%s,discard=%s,format=%s", imgPath, config.DiskCache, config.DiskDiscard, config.Format)
@ -133,7 +131,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
"to inspect the progress of the build.") "to inspect the progress of the build.")
} }
} else { } else {
if qemuMajor >= 2 { if qemuVersion.GreaterThanOrEqual(v2) {
if !config.UseDefaultDisplay { if !config.UseDefaultDisplay {
defaultArgs["-display"] = "sdl" defaultArgs["-display"] = "sdl"
} }