diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-11-19 16:54:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-19 16:54:29 +0100 |
commit | e239bfa15ba7e5718b511e0f949679ba5b7037c4 (patch) | |
tree | 0f95118000b8ef5bd4ddb293c9a20b0c4d5f2afa /cmd/podman/networks/connect.go | |
parent | 70f91fb96d11adb86be955e8a39f9c9096d48638 (diff) | |
parent | a3e0b7d117251944375fd32449f6b26d65edf367 (diff) | |
download | podman-e239bfa15ba7e5718b511e0f949679ba5b7037c4.tar.gz podman-e239bfa15ba7e5718b511e0f949679ba5b7037c4.tar.bz2 podman-e239bfa15ba7e5718b511e0f949679ba5b7037c4.zip |
Merge pull request #8391 from baude/networkconnectdisconnect
add network connect|disconnect compat endpoints
Diffstat (limited to 'cmd/podman/networks/connect.go')
-rw-r--r-- | cmd/podman/networks/connect.go | 47 |
1 files changed, 47 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) +} |