Merge pull request #7614 from radeksimko/f-qemu-go-version
builder/qemu: Replace dot-based parsing with hashicorp/go-version
This commit is contained in:
commit
ad37e45006
|
@ -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"
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -47,7 +47,7 @@ require (
|
||||||
github.com/hashicorp/go-retryablehttp v0.5.2 // indirect
|
github.com/hashicorp/go-retryablehttp v0.5.2 // indirect
|
||||||
github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 // indirect
|
github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 // indirect
|
||||||
github.com/hashicorp/go-uuid v1.0.1
|
github.com/hashicorp/go-uuid v1.0.1
|
||||||
github.com/hashicorp/go-version v1.1.0
|
github.com/hashicorp/go-version v1.2.0
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/hashicorp/serf v0.8.2 // indirect
|
github.com/hashicorp/serf v0.8.2 // indirect
|
||||||
github.com/hashicorp/vault v1.1.0
|
github.com/hashicorp/vault v1.1.0
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -187,6 +187,8 @@ github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1
|
||||||
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||||
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
|
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
|
||||||
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
|
github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E=
|
||||||
|
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
||||||
github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo=
|
github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo=
|
||||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.0
|
|
||||||
- 1.1
|
|
||||||
- 1.2
|
- 1.2
|
||||||
- 1.3
|
- 1.3
|
||||||
- 1.4
|
- 1.4
|
||||||
- 1.9
|
- 1.9
|
||||||
- "1.10"
|
- "1.10"
|
||||||
|
- 1.11
|
||||||
|
- 1.12
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- go test
|
- go test
|
||||||
|
|
|
@ -112,7 +112,7 @@ func Must(v *Version, err error) *Version {
|
||||||
// or larger than the other version, respectively.
|
// or larger than the other version, respectively.
|
||||||
//
|
//
|
||||||
// If you want boolean results, use the LessThan, Equal,
|
// If you want boolean results, use the LessThan, Equal,
|
||||||
// or GreaterThan methods.
|
// GreaterThan, GreaterThanOrEqual or LessThanOrEqual methods.
|
||||||
func (v *Version) Compare(other *Version) int {
|
func (v *Version) Compare(other *Version) int {
|
||||||
// A quick, efficient equality check
|
// A quick, efficient equality check
|
||||||
if v.String() == other.String() {
|
if v.String() == other.String() {
|
||||||
|
@ -288,11 +288,21 @@ func (v *Version) GreaterThan(o *Version) bool {
|
||||||
return v.Compare(o) > 0
|
return v.Compare(o) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GreaterThanOrEqualTo tests if this version is greater than or equal to another version.
|
||||||
|
func (v *Version) GreaterThanOrEqual(o *Version) bool {
|
||||||
|
return v.Compare(o) >= 0
|
||||||
|
}
|
||||||
|
|
||||||
// LessThan tests if this version is less than another version.
|
// LessThan tests if this version is less than another version.
|
||||||
func (v *Version) LessThan(o *Version) bool {
|
func (v *Version) LessThan(o *Version) bool {
|
||||||
return v.Compare(o) < 0
|
return v.Compare(o) < 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LessThanOrEqualTo tests if this version is less than or equal to another version.
|
||||||
|
func (v *Version) LessThanOrEqual(o *Version) bool {
|
||||||
|
return v.Compare(o) <= 0
|
||||||
|
}
|
||||||
|
|
||||||
// Metadata returns any metadata that was part of the version
|
// Metadata returns any metadata that was part of the version
|
||||||
// string.
|
// string.
|
||||||
//
|
//
|
||||||
|
|
|
@ -253,7 +253,7 @@ github.com/hashicorp/go-safetemp
|
||||||
github.com/hashicorp/go-sockaddr
|
github.com/hashicorp/go-sockaddr
|
||||||
# github.com/hashicorp/go-uuid v1.0.1
|
# github.com/hashicorp/go-uuid v1.0.1
|
||||||
github.com/hashicorp/go-uuid
|
github.com/hashicorp/go-uuid
|
||||||
# github.com/hashicorp/go-version v1.1.0
|
# github.com/hashicorp/go-version v1.2.0
|
||||||
github.com/hashicorp/go-version
|
github.com/hashicorp/go-version
|
||||||
# github.com/hashicorp/golang-lru v0.5.0
|
# github.com/hashicorp/golang-lru v0.5.0
|
||||||
github.com/hashicorp/golang-lru/simplelru
|
github.com/hashicorp/golang-lru/simplelru
|
||||||
|
|
Loading…
Reference in New Issue