summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2020-11-11 09:45:07 -0600
committerbaude <bbaude@redhat.com>2020-11-19 08:16:19 -0600
commita3e0b7d117251944375fd32449f6b26d65edf367 (patch)
tree824e4acb1529fb72276630fdd4d57127c07aadc8 /cmd
parent286d356db03a2511722155022c19855f8aee73cf (diff)
downloadpodman-a3e0b7d117251944375fd32449f6b26d65edf367.tar.gz
podman-a3e0b7d117251944375fd32449f6b26d65edf367.tar.bz2
podman-a3e0b7d117251944375fd32449f6b26d65edf367.zip
add network connect|disconnect compat endpoints
this enables the ability to connect and disconnect a container from a given network. it is only for the compatibility layer. some code had to be refactored to avoid circular imports. additionally, tests are being deferred temporarily due to some incompatibility/bug in either docker-py or our stack. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/networks/connect.go47
-rw-r--r--cmd/podman/networks/disconnect.go45
2 files changed, 92 insertions, 0 deletions
diff --git a/cmd/podman/networks/connect.go b/cmd/podman/networks/connect.go
new file mode 100644
index 000000000..a7636688c
--- /dev/null
+++ b/cmd/podman/networks/connect.go
@@ -0,0 +1,47 @@
+package network
+
+import (
+ "github.com/containers/common/pkg/completion"
+ "github.com/containers/podman/v2/cmd/podman/common"
+ "github.com/containers/podman/v2/cmd/podman/registry"
+ "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/spf13/cobra"
+)
+
+var (
+ networkConnectDescription = `Add container to a network`
+ networkConnectCommand = &cobra.Command{
+ Use: "connect [options] NETWORK CONTAINER",
+ Short: "network connect",
+ Long: networkConnectDescription,
+ RunE: networkConnect,
+ Example: `podman network connect web secondary`,
+ Args: cobra.ExactArgs(2),
+ ValidArgsFunction: common.AutocompleteNetworks,
+ }
+)
+
+var (
+ networkConnectOptions entities.NetworkConnectOptions
+)
+
+func networkConnectFlags(cmd *cobra.Command) {
+ flags := cmd.Flags()
+ aliasFlagName := "alias"
+ flags.StringSliceVar(&networkConnectOptions.Aliases, aliasFlagName, []string{}, "network scoped alias for container")
+ _ = cmd.RegisterFlagCompletionFunc(aliasFlagName, completion.AutocompleteNone)
+}
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ Command: networkConnectCommand,
+ Parent: networkCmd,
+ })
+ networkConnectFlags(networkConnectCommand)
+}
+
+func networkConnect(cmd *cobra.Command, args []string) error {
+ networkConnectOptions.Container = args[1]
+ return registry.ContainerEngine().NetworkConnect(registry.Context(), args[0], networkConnectOptions)
+}
diff --git a/cmd/podman/networks/disconnect.go b/cmd/podman/networks/disconnect.go
new file mode 100644
index 000000000..598c23a1c
--- /dev/null
+++ b/cmd/podman/networks/disconnect.go
@@ -0,0 +1,45 @@
+package network
+
+import (
+ "github.com/containers/podman/v2/cmd/podman/common"
+ "github.com/containers/podman/v2/cmd/podman/registry"
+ "github.com/containers/podman/v2/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.AutocompleteNetworks,
+ }
+)
+
+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{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ 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)
+}