diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-05-01 18:27:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-01 18:27:16 +0200 |
commit | 226e0da6fe12bf8a023f67ce6cebacd54ec65fdc (patch) | |
tree | a42bfedb583873d9d9e9d8830b6f688b138e0d08 /cmd/podman/networks/rm.go | |
parent | 49107a5a2ee98793b4ecfaa0e1a6cacfdf5ccdd0 (diff) | |
parent | 98e71583a4e7a0bf1f4a00fcab8bafa4915eb14a (diff) | |
download | podman-226e0da6fe12bf8a023f67ce6cebacd54ec65fdc.tar.gz podman-226e0da6fe12bf8a023f67ce6cebacd54ec65fdc.tar.bz2 podman-226e0da6fe12bf8a023f67ce6cebacd54ec65fdc.zip |
Merge pull request #6057 from baude/v2networking
v2networking enable commands
Diffstat (limited to 'cmd/podman/networks/rm.go')
-rw-r--r-- | cmd/podman/networks/rm.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/cmd/podman/networks/rm.go b/cmd/podman/networks/rm.go new file mode 100644 index 000000000..dc1eb9909 --- /dev/null +++ b/cmd/podman/networks/rm.go @@ -0,0 +1,63 @@ +package network + +import ( + "fmt" + + "github.com/containers/libpod/cmd/podman/registry" + "github.com/containers/libpod/cmd/podman/utils" + "github.com/containers/libpod/pkg/domain/entities" + "github.com/spf13/cobra" + "github.com/spf13/pflag" +) + +var ( + networkrmDescription = `Remove networks` + networkrmCommand = &cobra.Command{ + Use: "rm [flags] NETWORK [NETWORK...]", + Short: "network rm", + Long: networkrmDescription, + RunE: networkRm, + Example: `podman network rm podman`, + Args: cobra.MinimumNArgs(1), + Annotations: map[string]string{ + registry.ParentNSRequired: "", + }, + } +) + +var ( + networkRmOptions entities.NetworkRmOptions +) + +func networkRmFlags(flags *pflag.FlagSet) { + flags.BoolVarP(&networkRmOptions.Force, "force", "f", false, "remove any containers using network") +} + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Mode: []entities.EngineMode{entities.ABIMode}, + Command: networkrmCommand, + Parent: networkCmd, + }) + flags := networkrmCommand.Flags() + networkRmFlags(flags) +} + +func networkRm(cmd *cobra.Command, args []string) error { + var ( + errs utils.OutputErrors + ) + + responses, err := registry.ContainerEngine().NetworkRm(registry.Context(), args, networkRmOptions) + if err != nil { + return err + } + for _, r := range responses { + if r.Err == nil { + fmt.Println(r.Name) + } else { + errs = append(errs, r.Err) + } + } + return errs.PrintErrors() +} |