summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2021-03-25 10:35:43 -0500
committerbaude <bbaude@redhat.com>2021-03-27 10:08:11 -0500
commit7a79f708a4521ba7c42da83a204a01ace010ace3 (patch)
tree42e4128908fa127d158ad0673b033740d416d1f4 /cmd/podman
parentec47312eebf11abcf74b5bf06df19ee2fb7b8afd (diff)
downloadpodman-7a79f708a4521ba7c42da83a204a01ace010ace3.tar.gz
podman-7a79f708a4521ba7c42da83a204a01ace010ace3.tar.bz2
podman-7a79f708a4521ba7c42da83a204a01ace010ace3.zip
Podman machine enhancements
Podman machine remove is now called `rm`. Podman machine create now supports resizing the image to the value of --disk-size as provided. The default is to 10G. Added systemd unit file on guest via ignition that sends a Ready message to the host over a virtio-socket so that we know when the VM is booted and ready for use. Podman machine commands no longer require a VM name as an argument. A default VM name is defined and if no VM name is provided as a arg, the default will be used. [NO TESTS NEEDED] Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/machine/init.go43
-rw-r--r--cmd/podman/machine/rm.go (renamed from cmd/podman/machine/remove.go)28
-rw-r--r--cmd/podman/machine/ssh.go12
-rw-r--r--cmd/podman/machine/start.go12
-rw-r--r--cmd/podman/machine/stop.go12
5 files changed, 60 insertions, 47 deletions
diff --git a/cmd/podman/machine/init.go b/cmd/podman/machine/init.go
index 900f67e2f..05474fd89 100644
--- a/cmd/podman/machine/init.go
+++ b/cmd/podman/machine/init.go
@@ -8,6 +8,7 @@ import (
"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/pkg/errors"
"github.com/spf13/cobra"
)
@@ -23,17 +24,8 @@ var (
}
)
-type InitCLIOptions struct {
- CPUS uint64
- Memory uint64
- Devices []string
- ImagePath string
- IgnitionPath string
- Name string
-}
-
var (
- initOpts = InitCLIOptions{}
+ initOpts = machine.InitOptions{}
defaultMachineName string = "podman-machine-default"
)
@@ -53,6 +45,15 @@ func init() {
)
_ = initCmd.RegisterFlagCompletionFunc(cpusFlagName, completion.AutocompleteNone)
+ diskSizeFlagName := "disk-size"
+ flags.Uint64Var(
+ &initOpts.DiskSize,
+ diskSizeFlagName, 10,
+ "Disk size in GB",
+ )
+
+ _ = initCmd.RegisterFlagCompletionFunc(diskSizeFlagName, completion.AutocompleteNone)
+
memoryFlagName := "memory"
flags.Uint64VarP(
&initOpts.Memory,
@@ -72,28 +73,24 @@ func init() {
// 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
)
+ initOpts.Name = defaultMachineName
+ if len(args) > 0 {
+ initOpts.Name = args[0]
+ }
switch vmType {
default: // qemu is the default
- vm, err = qemu.NewMachine(vmOpts)
+ if _, err := qemu.LoadVMByName(initOpts.Name); err == nil {
+ return errors.Wrap(machine.ErrVMAlreadyExists, initOpts.Name)
+ }
+ vm, err = qemu.NewMachine(initOpts)
}
if err != nil {
return err
}
- return vm.Init(vmOpts)
+ return vm.Init(initOpts)
}
diff --git a/cmd/podman/machine/remove.go b/cmd/podman/machine/rm.go
index f6ce9e326..cd2cc84f2 100644
--- a/cmd/podman/machine/remove.go
+++ b/cmd/podman/machine/rm.go
@@ -17,13 +17,13 @@ import (
)
var (
- removeCmd = &cobra.Command{
- Use: "remove [options] NAME",
+ rmCmd = &cobra.Command{
+ Use: "rm [options] [NAME]",
Short: "Remove an existing machine",
Long: "Remove an existing machine ",
- RunE: remove,
- Args: cobra.ExactArgs(1),
- Example: `podman machine remove myvm`,
+ RunE: rm,
+ Args: cobra.MaximumNArgs(1),
+ Example: `podman machine rm myvm`,
ValidArgsFunction: completion.AutocompleteNone,
}
)
@@ -35,13 +35,13 @@ var (
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
- Command: removeCmd,
+ Command: rmCmd,
Parent: machineCmd,
})
- flags := removeCmd.Flags()
+ flags := rmCmd.Flags()
formatFlagName := "force"
- flags.BoolVar(&destoryOptions.Force, formatFlagName, false, "Do not prompt before removeing")
+ flags.BoolVar(&destoryOptions.Force, formatFlagName, false, "Do not prompt before rming")
keysFlagName := "save-keys"
flags.BoolVar(&destoryOptions.SaveKeys, keysFlagName, false, "Do not delete SSH keys")
@@ -53,20 +53,24 @@ func init() {
flags.BoolVar(&destoryOptions.SaveImage, imageFlagName, false, "Do not delete the image file")
}
-func remove(cmd *cobra.Command, args []string) error {
+func rm(cmd *cobra.Command, args []string) error {
var (
err error
vm machine.VM
vmType string
)
+ vmName := defaultMachineName
+ if len(args) > 0 && len(args[0]) > 0 {
+ vmName = args[0]
+ }
switch vmType {
default:
- vm, err = qemu.LoadVMByName(args[0])
+ vm, err = qemu.LoadVMByName(vmName)
}
if err != nil {
return err
}
- confirmationMessage, doIt, err := vm.Remove(args[0], machine.RemoveOptions{})
+ confirmationMessage, remove, err := vm.Remove(vmName, machine.RemoveOptions{})
if err != nil {
return err
}
@@ -84,5 +88,5 @@ func remove(cmd *cobra.Command, args []string) error {
return nil
}
}
- return doIt()
+ return remove()
}
diff --git a/cmd/podman/machine/ssh.go b/cmd/podman/machine/ssh.go
index a7111a195..879122a14 100644
--- a/cmd/podman/machine/ssh.go
+++ b/cmd/podman/machine/ssh.go
@@ -14,11 +14,11 @@ import (
var (
sshCmd = &cobra.Command{
- Use: "ssh [options] NAME [COMMAND [ARG ...]]",
+ Use: "ssh [options] [NAME] [COMMAND [ARG ...]]",
Short: "SSH into a virtual machine",
Long: "SSH into a virtual machine ",
RunE: ssh,
- Args: cobra.MinimumNArgs(1),
+ Args: cobra.MaximumNArgs(1),
Example: `podman machine ssh myvm
podman machine ssh -e myvm echo hello`,
@@ -48,6 +48,10 @@ func ssh(cmd *cobra.Command, args []string) error {
vm machine.VM
vmType string
)
+ vmName := defaultMachineName
+ if len(args) > 0 && len(args[0]) > 1 {
+ vmName = args[0]
+ }
sshOpts.Args = args[1:]
// Error if no execute but args given
@@ -61,10 +65,10 @@ func ssh(cmd *cobra.Command, args []string) error {
switch vmType {
default:
- vm, err = qemu.LoadVMByName(args[0])
+ vm, err = qemu.LoadVMByName(vmName)
}
if err != nil {
return errors.Wrapf(err, "vm %s not found", args[0])
}
- return vm.SSH(args[0], sshOpts)
+ return vm.SSH(vmName, sshOpts)
}
diff --git a/cmd/podman/machine/start.go b/cmd/podman/machine/start.go
index 44ade2850..80fd77102 100644
--- a/cmd/podman/machine/start.go
+++ b/cmd/podman/machine/start.go
@@ -13,11 +13,11 @@ import (
var (
startCmd = &cobra.Command{
- Use: "start NAME",
+ Use: "start [NAME]",
Short: "Start an existing machine",
Long: "Start an existing machine ",
RunE: start,
- Args: cobra.ExactArgs(1),
+ Args: cobra.MaximumNArgs(1),
Example: `podman machine start myvm`,
ValidArgsFunction: completion.AutocompleteNone,
}
@@ -37,12 +37,16 @@ func start(cmd *cobra.Command, args []string) error {
vm machine.VM
vmType string
)
+ vmName := defaultMachineName
+ if len(args) > 0 && len(args[0]) > 0 {
+ vmName = args[0]
+ }
switch vmType {
default:
- vm, err = qemu.LoadVMByName(args[0])
+ vm, err = qemu.LoadVMByName(vmName)
}
if err != nil {
return err
}
- return vm.Start(args[0], machine.StartOptions{})
+ return vm.Start(vmName, machine.StartOptions{})
}
diff --git a/cmd/podman/machine/stop.go b/cmd/podman/machine/stop.go
index 35fd4ff95..4fcb065a3 100644
--- a/cmd/podman/machine/stop.go
+++ b/cmd/podman/machine/stop.go
@@ -13,11 +13,11 @@ import (
var (
stopCmd = &cobra.Command{
- Use: "stop NAME",
+ Use: "stop [NAME]",
Short: "Stop an existing machine",
Long: "Stop an existing machine ",
RunE: stop,
- Args: cobra.ExactArgs(1),
+ Args: cobra.MaximumNArgs(1),
Example: `podman machine stop myvm`,
ValidArgsFunction: completion.AutocompleteNone,
}
@@ -38,12 +38,16 @@ func stop(cmd *cobra.Command, args []string) error {
vm machine.VM
vmType string
)
+ vmName := defaultMachineName
+ if len(args) > 0 && len(args[0]) > 0 {
+ vmName = args[0]
+ }
switch vmType {
default:
- vm, err = qemu.LoadVMByName(args[0])
+ vm, err = qemu.LoadVMByName(vmName)
}
if err != nil {
return err
}
- return vm.Stop(args[0], machine.StopOptions{})
+ return vm.Stop(vmName, machine.StopOptions{})
}