dynamically determine darwin qemu firmware location

pull/14182/head
Sharif Elgamal 2022-05-16 15:08:35 -07:00
parent 09365b4b04
commit e1517954fb
2 changed files with 30 additions and 16 deletions

View File

@ -38,6 +38,7 @@ import (
"github.com/docker/machine/libmachine/mcnutils"
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
"github.com/pkg/errors"
pkgdrivers "k8s.io/minikube/pkg/drivers"
)
@ -79,11 +80,9 @@ type Driver struct {
DiskPath string
CacheMode string
IOMode string
// conn *libvirt.Connect
// VM *libvirt.Domain
UserDataFile string
CloudConfigRoot string
LocalPorts string
UserDataFile string
CloudConfigRoot string
LocalPorts string
}
func (d *Driver) GetMachineName() string {
@ -273,19 +272,19 @@ func parsePortRange(rawPortRange string) (int, int, error) {
minPort, err := strconv.Atoi(portRange[0])
if err != nil {
return 0, 0, fmt.Errorf("invalid port range")
return 0, 0, errors.Wrap(err, "Invalid port range")
}
maxPort, err := strconv.Atoi(portRange[1])
if err != nil {
return 0, 0, fmt.Errorf("invalid port range")
return 0, 0, errors.Wrap(err, "Invalid port range")
}
if maxPort < minPort {
return 0, 0, fmt.Errorf("invalid port range")
return 0, 0, errors.New("Invalid port range")
}
if maxPort-minPort < 2 {
return 0, 0, fmt.Errorf("port range must be minimum 2 ports")
return 0, 0, errors.New("Port range must be minimum 2 ports")
}
return minPort, maxPort, nil

View File

@ -18,8 +18,10 @@ package qemu2
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
@ -64,17 +66,30 @@ func qemuSystemProgram() (string, error) {
func qemuFirmwarePath() (string, error) {
arch := runtime.GOARCH
// For macOS, find the correct brew installation path for qemu firmware
if runtime.GOOS == "darwin" {
//return "/opt/homebrew/Cellar/qemu/6.2.0_1/share/qemu/edk2-aarch64-code.fd", nil
p := "/usr/local/Cellar/qemu"
fw := "share/qemu/edk2-x86_64-code.fd"
if arch == "arm64" {
p = "/opt/homebrew/Cellar/qemu"
fw = "share/qemu/edk2-aarch64-code.fd"
}
v, err := ioutil.ReadDir(p)
if err != nil {
return "", fmt.Errorf("lookup qemu: %v", err)
}
for _, version := range v {
if version.IsDir() {
return path.Join(p, version.Name(), fw), nil
}
}
}
switch arch {
case "amd64":
// on macOS, we assume qemu is installed via homebrew for simplicity
if runtime.GOOS == "darwin" {
return "/usr/local/Cellar/qemu/6.2.0_1/share/qemu/edk2-x86_64-code.fd", nil
}
return "/usr/share/OVMF/OVMF_CODE.fd", nil
case "arm64":
if runtime.GOOS == "darwin" {
return "/opt/homebrew/Cellar/qemu/6.2.0_1/share/qemu/edk2-aarch64-code.fd", nil
}
return "/usr/share/AAVMF/AAVMF_CODE.fd", nil
default:
return "", fmt.Errorf("unknown arch: %s", arch)