summaryrefslogtreecommitdiff
path: root/cmd
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 /cmd
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
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/machine/create.go99
-rw-r--r--cmd/podman/machine/init.go99
2 files changed, 99 insertions, 99 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)
+}