summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/images/build.go17
-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
6 files changed, 68 insertions, 56 deletions
diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go
index 7db927e55..da6d556b1 100644
--- a/cmd/podman/images/build.go
+++ b/cmd/podman/images/build.go
@@ -8,7 +8,6 @@ import (
"strings"
"time"
- "github.com/containers/buildah"
"github.com/containers/buildah/define"
buildahCLI "github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/parse"
@@ -159,11 +158,11 @@ func buildFlags(cmd *cobra.Command) {
flags.SetNormalizeFunc(buildahCLI.AliasFlags)
if registry.IsRemote() {
flag = flags.Lookup("isolation")
- buildOpts.Isolation = buildah.OCI
- if err := flag.Value.Set(buildah.OCI); err != nil {
- logrus.Errorf("unable to set --isolation to %v: %v", buildah.OCI, err)
+ buildOpts.Isolation = define.OCI
+ if err := flag.Value.Set(define.OCI); err != nil {
+ logrus.Errorf("unable to set --isolation to %v: %v", define.OCI, err)
}
- flag.DefValue = buildah.OCI
+ flag.DefValue = define.OCI
_ = flags.MarkHidden("disable-content-trust")
_ = flags.MarkHidden("cache-from")
_ = flags.MarkHidden("sign-by")
@@ -427,10 +426,10 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
format := ""
flags.Format = strings.ToLower(flags.Format)
switch {
- case strings.HasPrefix(flags.Format, buildah.OCI):
- format = buildah.OCIv1ImageManifest
- case strings.HasPrefix(flags.Format, buildah.DOCKER):
- format = buildah.Dockerv2ImageManifest
+ case strings.HasPrefix(flags.Format, define.OCI):
+ format = define.OCIv1ImageManifest
+ case strings.HasPrefix(flags.Format, define.DOCKER):
+ format = define.Dockerv2ImageManifest
default:
return nil, errors.Errorf("unrecognized image type %q", flags.Format)
}
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{})
}