2016-06-06 08:28:52 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
|
|
|
type disconnectOptions struct {
|
|
|
|
network string
|
|
|
|
container string
|
|
|
|
force bool
|
|
|
|
}
|
|
|
|
|
2016-09-08 17:11:39 +00:00
|
|
|
func newDisconnectCommand(dockerCli *command.DockerCli) *cobra.Command {
|
2016-06-06 08:28:52 +00:00
|
|
|
opts := disconnectOptions{}
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "disconnect [OPTIONS] NETWORK CONTAINER",
|
2016-06-30 12:13:28 +00:00
|
|
|
Short: "Disconnect a container from a network",
|
2016-06-06 08:28:52 +00:00
|
|
|
Args: cli.ExactArgs(2),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
opts.network = args[0]
|
|
|
|
opts.container = args[1]
|
|
|
|
return runDisconnect(dockerCli, opts)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
flags := cmd.Flags()
|
|
|
|
flags.BoolVarP(&opts.force, "force", "f", false, "Force the container to disconnect from a network")
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-09-08 17:11:39 +00:00
|
|
|
func runDisconnect(dockerCli *command.DockerCli, opts disconnectOptions) error {
|
2016-06-06 08:28:52 +00:00
|
|
|
client := dockerCli.Client()
|
|
|
|
|
|
|
|
return client.NetworkDisconnect(context.Background(), opts.network, opts.container, opts.force)
|
|
|
|
}
|