summaryrefslogtreecommitdiff
path: root/pkg/machine
diff options
context:
space:
mode:
authorAshley Cui <acui@redhat.com>2021-03-25 15:28:49 -0400
committerAshley Cui <acui@redhat.com>2021-03-25 17:45:27 -0400
commitf6638571037c3d92066540e32fa08b76ce7f1fd8 (patch)
tree5c7332668bb4aae33f3f278f8b50ddd5ed8cff1d /pkg/machine
parentdb356748738762c31a036c179d23488d7978dabf (diff)
downloadpodman-f6638571037c3d92066540e32fa08b76ce7f1fd8.tar.gz
podman-f6638571037c3d92066540e32fa08b76ce7f1fd8.tar.bz2
podman-f6638571037c3d92066540e32fa08b76ce7f1fd8.zip
Rename podman machine create to init and clean up
Rename podman machine create to init because we're initing a VM, not really creating it Wire up CPUs flag Suppress QEMU GUI from popping up when not in debug mode [NO TESTS NEEDED] Signed-off-by: Ashley Cui <acui@redhat.com>
Diffstat (limited to 'pkg/machine')
-rw-r--r--pkg/machine/config.go4
-rw-r--r--pkg/machine/libvirt/machine.go2
-rw-r--r--pkg/machine/qemu/machine.go22
3 files changed, 18 insertions, 10 deletions
diff --git a/pkg/machine/config.go b/pkg/machine/config.go
index 242401ab4..4933deee8 100644
--- a/pkg/machine/config.go
+++ b/pkg/machine/config.go
@@ -9,7 +9,7 @@ import (
"github.com/containers/storage/pkg/homedir"
)
-type CreateOptions struct {
+type InitOptions struct {
Name string
CPUS uint64
Memory uint64
@@ -58,7 +58,7 @@ type RemoveOptions struct {
}
type VM interface {
- Create(opts CreateOptions) error
+ Init(opts InitOptions) error
Remove(name string, opts RemoveOptions) (string, func() error, error)
SSH(name string, opts SSHOptions) error
Start(name string, opts StartOptions) error
diff --git a/pkg/machine/libvirt/machine.go b/pkg/machine/libvirt/machine.go
index 2c907ba5f..c38f63853 100644
--- a/pkg/machine/libvirt/machine.go
+++ b/pkg/machine/libvirt/machine.go
@@ -2,7 +2,7 @@ package libvirt
import "github.com/containers/podman/v3/pkg/machine"
-func (v *MachineVM) Create(name string, opts machine.CreateOptions) error {
+func (v *MachineVM) Init(name string, opts machine.InitOptions) error {
return nil
}
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index 504b64bd5..b97eb991a 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -27,9 +27,9 @@ var (
//qemuCommon = []string{"-cpu", "host", "-qmp", "tcp:localhost:4444,server,nowait"}
)
-// NewMachine creates an instance of a virtual machine based on the qemu
+// NewMachine initializes an instance of a virtual machine based on the qemu
// virtualization.
-func NewMachine(opts machine.CreateOptions) (machine.VM, error) {
+func NewMachine(opts machine.InitOptions) (machine.VM, error) {
vmConfigDir, err := machine.GetConfDir(vmtype)
if err != nil {
return nil, err
@@ -75,7 +75,7 @@ func NewMachine(opts machine.CreateOptions) (machine.VM, error) {
// Add memory
cmd = append(cmd, []string{"-m", strconv.Itoa(int(vm.Memory))}...)
// Add cpus
- // TODO
+ cmd = append(cmd, []string{"-smp", strconv.Itoa(int(vm.CPUs))}...)
// Add ignition file
cmd = append(cmd, []string{"-fw_cfg", "name=opt/com.coreos/config,file=" + vm.IgnitionFilePath}...)
// Add qmp socket
@@ -88,8 +88,8 @@ func NewMachine(opts machine.CreateOptions) (machine.VM, error) {
// Add network
cmd = append(cmd, "-nic", "user,model=virtio,hostfwd=tcp::"+strconv.Itoa(vm.Port)+"-:22")
+
vm.CmdLine = cmd
- fmt.Println("///")
return vm, nil
}
@@ -111,9 +111,9 @@ func LoadVMByName(name string) (machine.VM, error) {
return vm, err
}
-// Create writes the json configuration file to the filesystem for
+// Init writes the json configuration file to the filesystem for
// other verbs (start, stop)
-func (v *MachineVM) Create(opts machine.CreateOptions) error {
+func (v *MachineVM) Init(opts machine.InitOptions) error {
sshDir := filepath.Join(homedir.Get(), ".ssh")
// GetConfDir creates the directory so no need to check for
// its existence
@@ -172,7 +172,15 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
files := []*os.File{os.Stdin, os.Stdout, os.Stderr}
attr.Files = files
logrus.Debug(v.CmdLine)
- _, err = os.StartProcess(v.CmdLine[0], v.CmdLine, attr)
+ cmd := v.CmdLine
+
+ // Disable graphic window when not in debug mode
+ // Done in start, so we're not suck with the debug level we used on init
+ if logrus.GetLevel() != logrus.DebugLevel {
+ cmd = append(cmd, "-display", "none")
+ }
+
+ _, err = os.StartProcess(v.CmdLine[0], cmd, attr)
return err
}