2016-06-06 08:28:52 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
|
|
|
"github.com/docker/docker/cli"
|
2016-09-08 17:11:39 +00:00
|
|
|
"github.com/docker/docker/cli/command"
|
2016-06-06 08:28:52 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2016-09-08 17:11:39 +00:00
|
|
|
func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
|
2016-06-06 08:28:52 +00:00
|
|
|
return &cobra.Command{
|
2016-07-29 17:41:52 +00:00
|
|
|
Use: "rm NETWORK [NETWORK...]",
|
2016-06-06 08:28:52 +00:00
|
|
|
Aliases: []string{"remove"},
|
2016-07-29 17:41:52 +00:00
|
|
|
Short: "Remove one or more networks",
|
2016-06-06 08:28:52 +00:00
|
|
|
Args: cli.RequiresMinArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runRemove(dockerCli, args)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-09 19:52:25 +00:00
|
|
|
const ingressWarning = "WARNING! Before removing the routing-mesh network, " +
|
|
|
|
"make sure all the nodes in your swarm run the same docker engine version. " +
|
|
|
|
"Otherwise, removal may not be effective and functionality of newly create " +
|
|
|
|
"ingress networks will be impaired.\nAre you sure you want to continue?"
|
|
|
|
|
2016-09-08 17:11:39 +00:00
|
|
|
func runRemove(dockerCli *command.DockerCli, networks []string) error {
|
2016-06-06 08:28:52 +00:00
|
|
|
client := dockerCli.Client()
|
|
|
|
ctx := context.Background()
|
|
|
|
status := 0
|
|
|
|
|
|
|
|
for _, name := range networks {
|
2017-03-09 19:52:25 +00:00
|
|
|
if nw, _, err := client.NetworkInspectWithRaw(ctx, name, false); err == nil &&
|
|
|
|
nw.Ingress &&
|
|
|
|
!command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), ingressWarning) {
|
|
|
|
continue
|
|
|
|
}
|
2016-06-06 08:28:52 +00:00
|
|
|
if err := client.NetworkRemove(ctx, name); err != nil {
|
|
|
|
fmt.Fprintf(dockerCli.Err(), "%s\n", err)
|
|
|
|
status = 1
|
|
|
|
continue
|
|
|
|
}
|
2016-07-04 04:02:56 +00:00
|
|
|
fmt.Fprintf(dockerCli.Out(), "%s\n", name)
|
2016-06-06 08:28:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != 0 {
|
|
|
|
return cli.StatusError{StatusCode: status}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|