diff options
author | baude <bbaude@redhat.com> | 2021-03-22 13:29:25 -0500 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2021-03-25 11:02:33 -0500 |
commit | 4ab8a6f67eb9de0de40d478cb0cbec05b1b725c0 (patch) | |
tree | 00743bf608cc5700fe8a7fca1bb3b0f3a4457b7d /cmd/podman/machine/remove.go | |
parent | e7661137373b5f87bf6ec45e32326821b172ce7b (diff) | |
download | podman-4ab8a6f67eb9de0de40d478cb0cbec05b1b725c0.tar.gz podman-4ab8a6f67eb9de0de40d478cb0cbec05b1b725c0.tar.bz2 podman-4ab8a6f67eb9de0de40d478cb0cbec05b1b725c0.zip |
Improvements for machine
clean up ci failures and add appropriate arch,os exclusion tags
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/machine/remove.go')
-rw-r--r-- | cmd/podman/machine/remove.go | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/cmd/podman/machine/remove.go b/cmd/podman/machine/remove.go new file mode 100644 index 000000000..f6ce9e326 --- /dev/null +++ b/cmd/podman/machine/remove.go @@ -0,0 +1,88 @@ +// +build amd64,linux amd64,darwin arm64,darwin + +package machine + +import ( + "bufio" + "fmt" + "os" + "strings" + + "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 ( + removeCmd = &cobra.Command{ + Use: "remove [options] NAME", + Short: "Remove an existing machine", + Long: "Remove an existing machine ", + RunE: remove, + Args: cobra.ExactArgs(1), + Example: `podman machine remove myvm`, + ValidArgsFunction: completion.AutocompleteNone, + } +) + +var ( + destoryOptions machine.RemoveOptions +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, + Command: removeCmd, + Parent: machineCmd, + }) + + flags := removeCmd.Flags() + formatFlagName := "force" + flags.BoolVar(&destoryOptions.Force, formatFlagName, false, "Do not prompt before removeing") + + keysFlagName := "save-keys" + flags.BoolVar(&destoryOptions.SaveKeys, keysFlagName, false, "Do not delete SSH keys") + + ignitionFlagName := "save-ignition" + flags.BoolVar(&destoryOptions.SaveIgnition, ignitionFlagName, false, "Do not delete ignition file") + + imageFlagName := "save-image" + flags.BoolVar(&destoryOptions.SaveImage, imageFlagName, false, "Do not delete the image file") +} + +func remove(cmd *cobra.Command, args []string) error { + var ( + err error + vm machine.VM + vmType string + ) + switch vmType { + default: + vm, err = qemu.LoadVMByName(args[0]) + } + if err != nil { + return err + } + confirmationMessage, doIt, err := vm.Remove(args[0], machine.RemoveOptions{}) + if err != nil { + return err + } + + if !destoryOptions.Force { + // Warn user + fmt.Println(confirmationMessage) + reader := bufio.NewReader(os.Stdin) + fmt.Print("Are you sure you want to continue? [y/N] ") + answer, err := reader.ReadString('\n') + if err != nil { + return err + } + if strings.ToLower(answer)[0] != 'y' { + return nil + } + } + return doIt() +} |