summaryrefslogtreecommitdiff
path: root/pkg/machine
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/machine')
-rw-r--r--pkg/machine/config.go37
-rw-r--r--pkg/machine/fcos.go4
-rw-r--r--pkg/machine/qemu/machine.go20
-rw-r--r--pkg/machine/qemu/options_darwin.go15
-rw-r--r--pkg/machine/qemu/options_darwin_amd64.go18
-rw-r--r--pkg/machine/qemu/options_darwin_arm64.go (renamed from pkg/machine/qemu/options_arm64.go)4
-rw-r--r--pkg/machine/qemu/options_linux.go7
-rw-r--r--pkg/machine/qemu/options_linux_amd64.go (renamed from pkg/machine/qemu/options_amd64.go)8
8 files changed, 66 insertions, 47 deletions
diff --git a/pkg/machine/config.go b/pkg/machine/config.go
index 2a70b8ff7..242401ab4 100644
--- a/pkg/machine/config.go
+++ b/pkg/machine/config.go
@@ -50,7 +50,7 @@ type StartOptions struct{}
type StopOptions struct{}
-type DestroyOptions struct {
+type RemoveOptions struct {
Force bool
SaveKeys bool
SaveImage bool
@@ -59,7 +59,7 @@ type DestroyOptions struct {
type VM interface {
Create(opts CreateOptions) error
- Destroy(name string, opts DestroyOptions) (string, func() error, error)
+ Remove(name string, opts RemoveOptions) (string, func() error, error)
SSH(name string, opts SSHOptions) error
Start(name string, opts StartOptions) error
Stop(name string, opts StopOptions) error
@@ -70,33 +70,18 @@ type DistributionDownload interface {
Get() *Download
}
-// TODO is this even needed?
-type TestVM struct{}
-
-func (vm *TestVM) Create(opts CreateOptions) error {
- return nil
-}
-
-func (vm *TestVM) Start(name string, opts StartOptions) error {
- return nil
-}
-func (vm *TestVM) Stop(name string, opts StopOptions) error {
- return nil
-}
-
func (rc RemoteConnectionType) MakeSSHURL(host, path, port, userName string) url.URL {
userInfo := url.User(userName)
uri := url.URL{
- Scheme: "ssh",
- Opaque: "",
- User: userInfo,
- Host: host,
- Path: path,
- RawPath: "",
- ForceQuery: false,
- RawQuery: "",
- Fragment: "",
- RawFragment: "",
+ Scheme: "ssh",
+ Opaque: "",
+ User: userInfo,
+ Host: host,
+ Path: path,
+ RawPath: "",
+ ForceQuery: false,
+ RawQuery: "",
+ Fragment: "",
}
if len(port) > 0 {
uri.Host = net.JoinHostPort(uri.Hostname(), port)
diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go
index 8bbad458f..0c6a2485e 100644
--- a/pkg/machine/fcos.go
+++ b/pkg/machine/fcos.go
@@ -11,10 +11,8 @@ import (
"strings"
"github.com/containers/storage/pkg/archive"
-
- "github.com/sirupsen/logrus"
-
digest "github.com/opencontainers/go-digest"
+ "github.com/sirupsen/logrus"
)
// These should eventually be moved into machine/qemu as
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index 30d96ce08..504b64bd5 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -10,8 +10,9 @@ import (
"strconv"
"time"
+ "github.com/containers/podman/v3/utils"
+
"github.com/containers/podman/v3/pkg/machine"
- "github.com/containers/podman/v3/pkg/specgen"
"github.com/containers/storage/pkg/homedir"
"github.com/digitalocean/go-qemu/qmp"
"github.com/pkg/errors"
@@ -56,7 +57,7 @@ func NewMachine(opts machine.CreateOptions) (machine.VM, error) {
}
// Add a random port for ssh
- port, err := specgen.GetRandomPort()
+ port, err := utils.GetRandomPort()
if err != nil {
return nil, err
}
@@ -170,7 +171,7 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
attr := new(os.ProcAttr)
files := []*os.File{os.Stdin, os.Stdout, os.Stderr}
attr.Files = files
- fmt.Print(v.CmdLine)
+ logrus.Debug(v.CmdLine)
_, err = os.StartProcess(v.CmdLine[0], v.CmdLine, attr)
return err
}
@@ -211,22 +212,29 @@ func (v *MachineVM) Stop(name string, _ machine.StopOptions) error {
// NewQMPMonitor creates the monitor subsection of our vm
func NewQMPMonitor(network, name string, timeout time.Duration) (Monitor, error) {
- rtDir, err := getDataDir()
+ rtDir, err := getSocketDir()
if err != nil {
return Monitor{}, err
}
+ rtDir = filepath.Join(rtDir, "podman")
+ if _, err := os.Stat(filepath.Join(rtDir)); os.IsNotExist(err) {
+ // TODO 0644 is fine on linux but macos is weird
+ if err := os.MkdirAll(rtDir, 0755); err != nil {
+ return Monitor{}, err
+ }
+ }
if timeout == 0 {
timeout = defaultQMPTimeout
}
monitor := Monitor{
Network: network,
- Address: filepath.Join(rtDir, "podman", "qmp_"+name+".sock"),
+ Address: filepath.Join(rtDir, "qmp_"+name+".sock"),
Timeout: timeout,
}
return monitor, nil
}
-func (v *MachineVM) Destroy(name string, opts machine.DestroyOptions) (string, func() error, error) {
+func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, func() error, error) {
var (
files []string
)
diff --git a/pkg/machine/qemu/options_darwin.go b/pkg/machine/qemu/options_darwin.go
new file mode 100644
index 000000000..46ccf24cb
--- /dev/null
+++ b/pkg/machine/qemu/options_darwin.go
@@ -0,0 +1,15 @@
+package qemu
+
+import (
+ "os"
+
+ "github.com/pkg/errors"
+)
+
+func getSocketDir() (string, error) {
+ tmpDir, ok := os.LookupEnv("TMPDIR")
+ if !ok {
+ return "", errors.New("unable to resolve TMPDIR")
+ }
+ return tmpDir, nil
+}
diff --git a/pkg/machine/qemu/options_darwin_amd64.go b/pkg/machine/qemu/options_darwin_amd64.go
new file mode 100644
index 000000000..69f7982b2
--- /dev/null
+++ b/pkg/machine/qemu/options_darwin_amd64.go
@@ -0,0 +1,18 @@
+package qemu
+
+var (
+ QemuCommand = "qemu-system-x86_64"
+)
+
+func (v *MachineVM) addArchOptions() []string {
+ opts := []string{"-cpu", "host"}
+ return opts
+}
+
+func (v *MachineVM) prepare() error {
+ return nil
+}
+
+func (v *MachineVM) archRemovalFiles() []string {
+ return []string{}
+}
diff --git a/pkg/machine/qemu/options_arm64.go b/pkg/machine/qemu/options_darwin_arm64.go
index c5b0ea16b..7513b3048 100644
--- a/pkg/machine/qemu/options_arm64.go
+++ b/pkg/machine/qemu/options_darwin_arm64.go
@@ -31,10 +31,6 @@ func (v *MachineVM) archRemovalFiles() []string {
return []string{ovmDir}
}
-func getDataDir() (string, error) {
- return "/tmp", nil
-}
-
func getOvmfDir(imagePath, vmName string) string {
return filepath.Join(filepath.Dir(imagePath), vmName+"_ovmf_vars.fd")
}
diff --git a/pkg/machine/qemu/options_linux.go b/pkg/machine/qemu/options_linux.go
new file mode 100644
index 000000000..0a2e40d8f
--- /dev/null
+++ b/pkg/machine/qemu/options_linux.go
@@ -0,0 +1,7 @@
+package qemu
+
+import "github.com/containers/podman/v3/pkg/util"
+
+func getSocketDir() (string, error) {
+ return util.GetRuntimeDir()
+}
diff --git a/pkg/machine/qemu/options_amd64.go b/pkg/machine/qemu/options_linux_amd64.go
index 85a2c4b3e..cc0a4bab2 100644
--- a/pkg/machine/qemu/options_amd64.go
+++ b/pkg/machine/qemu/options_linux_amd64.go
@@ -1,9 +1,5 @@
package qemu
-import (
- "github.com/containers/podman/v3/pkg/util"
-)
-
var (
QemuCommand = "qemu-kvm"
)
@@ -20,7 +16,3 @@ func (v *MachineVM) prepare() error {
func (v *MachineVM) archRemovalFiles() []string {
return []string{}
}
-
-func getDataDir() (string, error) {
- return util.GetRuntimeDir()
-}