aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/networks/disconnect.go
blob: 51d1478bf539e080ad82c0931499deee688569f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package network

import (
	"github.com/containers/podman/v4/cmd/podman/common"
	"github.com/containers/podman/v4/cmd/podman/registry"
	"github.com/containers/podman/v4/pkg/domain/entities"
	"github.com/spf13/cobra"
	"github.com/spf13/pflag"
)

var (
	networkDisconnectDescription = `Remove container from a network`
	networkDisconnectCommand     = &cobra.Command{
		Use:               "disconnect [options] NETWORK CONTAINER",
		Short:             "network rm",
		Long:              networkDisconnectDescription,
		RunE:              networkDisconnect,
		Example:           `podman network disconnect web secondary`,
		Args:              cobra.ExactArgs(2),
		ValidArgsFunction: common.AutocompleteNetworkConnectCmd,
	}
)

var (
	networkDisconnectOptions entities.NetworkDisconnectOptions
)

func networkDisconnectFlags(flags *pflag.FlagSet) {
	flags.BoolVarP(&networkDisconnectOptions.Force, "force", "f", false, "force removal of container from network")
}

func init() {
	registry.Commands = append(registry.Commands, registry.CliCommand{
		Command: networkDisconnectCommand,
		Parent:  networkCmd,
	})
	flags := networkDisconnectCommand.Flags()
	networkDisconnectFlags(flags)
}

func networkDisconnect(cmd *cobra.Command, args []string) error {
	networkDisconnectOptions.Container = args[1]
	return registry.ContainerEngine().NetworkDisconnect(registry.Context(), args[0], networkDisconnectOptions)
}