summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-03-26 13:45:11 +0000
committerGitHub <noreply@github.com>2021-03-26 13:45:11 +0000
commit25525ff834cc979566bb09e5546ee0a72ef76a79 (patch)
tree382f7f94db7230225e2e4a23975045118b4a12da
parent7ae1d23a380ae0c9cf4edb64ba288a8464c3cf13 (diff)
parentf6638571037c3d92066540e32fa08b76ce7f1fd8 (diff)
downloadpodman-25525ff834cc979566bb09e5546ee0a72ef76a79.tar.gz
podman-25525ff834cc979566bb09e5546ee0a72ef76a79.tar.bz2
podman-25525ff834cc979566bb09e5546ee0a72ef76a79.zip
Merge pull request #9820 from ashley-cui/machineinit
[NO TESTS NEEDED] Rename podman machine create to init and clean up
-rw-r--r--cmd/podman/machine/create.go99
-rw-r--r--cmd/podman/machine/init.go99
-rw-r--r--docs/source/machine.rst2
-rw-r--r--docs/source/markdown/podman-machine-init.1.md (renamed from docs/source/markdown/podman-machine-create.1.md)16
-rw-r--r--docs/source/markdown/podman-machine.1.md14
-rw-r--r--pkg/machine/config.go4
-rw-r--r--pkg/machine/libvirt/machine.go2
-rw-r--r--pkg/machine/qemu/machine.go22
8 files changed, 133 insertions, 125 deletions
diff --git a/cmd/podman/machine/create.go b/cmd/podman/machine/create.go
deleted file mode 100644
index 1da34327a..000000000
--- a/cmd/podman/machine/create.go
+++ /dev/null
@@ -1,99 +0,0 @@
-// +build amd64,linux amd64,darwin arm64,darwin
-
-package machine
-
-import (
- "github.com/containers/common/pkg/completion"
- "github.com/containers/podman/v3/cmd/podman/registry"
- "github.com/containers/podman/v3/pkg/domain/entities"
- "github.com/containers/podman/v3/pkg/machine"
- "github.com/containers/podman/v3/pkg/machine/qemu"
- "github.com/spf13/cobra"
-)
-
-var (
- createCmd = &cobra.Command{
- Use: "create [options] [NAME]",
- Short: "Create a vm",
- Long: "Create a virtual machine for Podman to run on. Virtual machines are used to run Podman.",
- RunE: create,
- Args: cobra.MaximumNArgs(1),
- Example: `podman machine create myvm`,
- ValidArgsFunction: completion.AutocompleteNone,
- }
-)
-
-type CreateCLIOptions struct {
- CPUS uint64
- Memory uint64
- Devices []string
- ImagePath string
- IgnitionPath string
- Name string
-}
-
-var (
- createOpts = CreateCLIOptions{}
- defaultMachineName string = "podman-machine-default"
-)
-
-func init() {
- registry.Commands = append(registry.Commands, registry.CliCommand{
- Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: createCmd,
- Parent: machineCmd,
- })
- flags := createCmd.Flags()
-
- cpusFlagName := "cpus"
- flags.Uint64Var(
- &createOpts.CPUS,
- cpusFlagName, 1,
- "Number of CPUs. The default is 0.000 which means no limit",
- )
- _ = createCmd.RegisterFlagCompletionFunc(cpusFlagName, completion.AutocompleteNone)
-
- memoryFlagName := "memory"
- flags.Uint64VarP(
- &createOpts.Memory,
- memoryFlagName, "m", 2048,
- "Memory (in MB)",
- )
- _ = createCmd.RegisterFlagCompletionFunc(memoryFlagName, completion.AutocompleteNone)
-
- ImagePathFlagName := "image-path"
- flags.StringVar(&createOpts.ImagePath, ImagePathFlagName, "", "Path to qcow image")
- _ = createCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault)
-
- IgnitionPathFlagName := "ignition-path"
- flags.StringVar(&createOpts.IgnitionPath, IgnitionPathFlagName, "", "Path to ignition file")
- _ = createCmd.RegisterFlagCompletionFunc(IgnitionPathFlagName, completion.AutocompleteDefault)
-}
-
-// TODO should we allow for a users to append to the qemu cmdline?
-func create(cmd *cobra.Command, args []string) error {
- createOpts.Name = defaultMachineName
- if len(args) > 0 {
- createOpts.Name = args[0]
- }
- vmOpts := machine.CreateOptions{
- CPUS: createOpts.CPUS,
- Memory: createOpts.Memory,
- IgnitionPath: createOpts.IgnitionPath,
- ImagePath: createOpts.ImagePath,
- Name: createOpts.Name,
- }
- var (
- vm machine.VM
- vmType string
- err error
- )
- switch vmType {
- default: // qemu is the default
- vm, err = qemu.NewMachine(vmOpts)
- }
- if err != nil {
- return err
- }
- return vm.Create(vmOpts)
-}
diff --git a/cmd/podman/machine/init.go b/cmd/podman/machine/init.go
new file mode 100644
index 000000000..900f67e2f
--- /dev/null
+++ b/cmd/podman/machine/init.go
@@ -0,0 +1,99 @@
+// +build amd64,linux amd64,darwin arm64,darwin
+
+package machine
+
+import (
+ "github.com/containers/common/pkg/completion"
+ "github.com/containers/podman/v3/cmd/podman/registry"
+ "github.com/containers/podman/v3/pkg/domain/entities"
+ "github.com/containers/podman/v3/pkg/machine"
+ "github.com/containers/podman/v3/pkg/machine/qemu"
+ "github.com/spf13/cobra"
+)
+
+var (
+ initCmd = &cobra.Command{
+ Use: "init [options] [NAME]",
+ Short: "initialize a vm",
+ Long: "initialize a virtual machine for Podman to run on. Virtual machines are used to run Podman.",
+ RunE: initMachine,
+ Args: cobra.MaximumNArgs(1),
+ Example: `podman machine init myvm`,
+ ValidArgsFunction: completion.AutocompleteNone,
+ }
+)
+
+type InitCLIOptions struct {
+ CPUS uint64
+ Memory uint64
+ Devices []string
+ ImagePath string
+ IgnitionPath string
+ Name string
+}
+
+var (
+ initOpts = InitCLIOptions{}
+ defaultMachineName string = "podman-machine-default"
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ Command: initCmd,
+ Parent: machineCmd,
+ })
+ flags := initCmd.Flags()
+
+ cpusFlagName := "cpus"
+ flags.Uint64Var(
+ &initOpts.CPUS,
+ cpusFlagName, 1,
+ "Number of CPUs. The default is 1.",
+ )
+ _ = initCmd.RegisterFlagCompletionFunc(cpusFlagName, completion.AutocompleteNone)
+
+ memoryFlagName := "memory"
+ flags.Uint64VarP(
+ &initOpts.Memory,
+ memoryFlagName, "m", 2048,
+ "Memory (in MB)",
+ )
+ _ = initCmd.RegisterFlagCompletionFunc(memoryFlagName, completion.AutocompleteNone)
+
+ ImagePathFlagName := "image-path"
+ flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, "", "Path to qcow image")
+ _ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault)
+
+ IgnitionPathFlagName := "ignition-path"
+ flags.StringVar(&initOpts.IgnitionPath, IgnitionPathFlagName, "", "Path to ignition file")
+ _ = initCmd.RegisterFlagCompletionFunc(IgnitionPathFlagName, completion.AutocompleteDefault)
+}
+
+// TODO should we allow for a users to append to the qemu cmdline?
+func initMachine(cmd *cobra.Command, args []string) error {
+ initOpts.Name = defaultMachineName
+ if len(args) > 0 {
+ initOpts.Name = args[0]
+ }
+ vmOpts := machine.InitOptions{
+ CPUS: initOpts.CPUS,
+ Memory: initOpts.Memory,
+ IgnitionPath: initOpts.IgnitionPath,
+ ImagePath: initOpts.ImagePath,
+ Name: initOpts.Name,
+ }
+ var (
+ vm machine.VM
+ vmType string
+ err error
+ )
+ switch vmType {
+ default: // qemu is the default
+ vm, err = qemu.NewMachine(vmOpts)
+ }
+ if err != nil {
+ return err
+ }
+ return vm.Init(vmOpts)
+}
diff --git a/docs/source/machine.rst b/docs/source/machine.rst
index cf7f72cce..55df29667 100644
--- a/docs/source/machine.rst
+++ b/docs/source/machine.rst
@@ -2,7 +2,7 @@ Machine
======
-:doc:`create <markdown/podman-machine-create.1>` Create a new virtual machine
+:doc:`init <markdown/podman-machine-init.1>` Initialize a new virtual machine
:doc:`remove <markdown/podman-machine-remove.1>` Remove a virtual machine
:doc:`ssh <markdown/podman-machine-ssh.1>` SSH into a virtual machine
:doc:`start <markdown/podman-machine-start.1>` Start a virtual machine
diff --git a/docs/source/markdown/podman-machine-create.1.md b/docs/source/markdown/podman-machine-init.1.md
index eb498f2dd..5ff07de03 100644
--- a/docs/source/markdown/podman-machine-create.1.md
+++ b/docs/source/markdown/podman-machine-init.1.md
@@ -1,20 +1,20 @@
-% podman-machine-create(1)
+% podman-machine-init(1)
## NAME
-podman\-machine\-create - Create a new virtual machine
+podman\-machine\-init - Initialize a new virtual machine
## SYNOPSIS
-**podman machine create** [*options*] [*name*]
+**podman machine init** [*options*] [*name*]
## DESCRIPTION
-Creates a new virtual machine for Podman.
+Initialize a new virtual machine for Podman.
Podman on MacOS requires a virtual machine. This is because containers are Linux -
containers do not run on any other OS because containers' core functionality are
tied to the Linux kernel.
-**podman machine create** creates a new Linux virtual machine where containers are run.
+**podman machine init** initializes a new Linux virtual machine where containers are run.
## OPTIONS
@@ -41,9 +41,9 @@ Print usage statement.
## EXAMPLES
```
-$ podman machine create myvm
-$ podman machine create --device=/dev/xvdc:rw myvm
-$ podman machine create --memory=1024 myvm
+$ podman machine init myvm
+$ podman machine init --device=/dev/xvdc:rw myvm
+$ podman machine init --memory=1024 myvm
```
## SEE ALSO
diff --git a/docs/source/markdown/podman-machine.1.md b/docs/source/markdown/podman-machine.1.md
index 52f212cdd..0e3c1ca34 100644
--- a/docs/source/markdown/podman-machine.1.md
+++ b/docs/source/markdown/podman-machine.1.md
@@ -11,13 +11,13 @@ podman\-machine - Manage Podman's virtual machine
## SUBCOMMANDS
-| Command | Man Page | Description |
-| ------- | ------------------------------------------------------- | ----------------------------- |
-| create | [podman-machine-create(1)](podman-machine-create.1.md) | Create a new virtual machine |
-| remove | [podman-machine-destroy(1)](podman-machine-remove.1.md)| Remove a virtual machine |
-| ssh | [podman-machine-ssh.1.md(1)](podman-machine-ssh.1.md) | SSH into a virtual machine |
-| start | [podman-machine-start(1)](podman-machine-start.1.md) | Start a virtual machine |
-| stop | [podman-machine-stop(1)](podman-machine-stop.1.md) | Stop a virtual machine |
+| Command | Man Page | Description |
+| ------- | ------------------------------------------------------- | --------------------------------- |
+| init | [podman-machine-init(1)](podman-machine-init.1.md) | Initialize a new virtual machine |
+| remove | [podman-machine-remove(1)](podman-machine-remove.1.md) | Remove a virtual machine |
+| ssh | [podman-machine-ssh(1)](podman-machine-ssh.1.md) | SSH into a virtual machine |
+| start | [podman-machine-start(1)](podman-machine-start.1.md) | Start a virtual machine |
+| stop | [podman-machine-stop(1)](podman-machine-stop.1.md) | Stop a virtual machine |
## SEE ALSO
podman(1)
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
}