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 /pkg/api/handlers | |
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 'pkg/api/handlers')
-rw-r--r-- | pkg/api/handlers/libpod/networks.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/api/handlers/libpod/networks.go b/pkg/api/handlers/libpod/networks.go index 78e525f1f..f1578f829 100644 --- a/pkg/api/handlers/libpod/networks.go +++ b/pkg/api/handlers/libpod/networks.go @@ -131,3 +131,29 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) { } utils.WriteResponse(w, http.StatusOK, reports) } + +// Connect adds a container to a network +func Connect(w http.ResponseWriter, r *http.Request) { + runtime := r.Context().Value("runtime").(*libpod.Runtime) + + var netConnect entities.NetworkConnectOptions + if err := json.NewDecoder(r.Body).Decode(&netConnect); err != nil { + utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()")) + return + } + name := utils.GetName(r) + err := runtime.ConnectContainerToNetwork(netConnect.Container, name, netConnect.Aliases) + if err != nil { + if errors.Cause(err) == define.ErrNoSuchCtr { + utils.ContainerNotFound(w, netConnect.Container, err) + return + } + if errors.Cause(err) == define.ErrNoSuchNetwork { + utils.Error(w, "network not found", http.StatusNotFound, err) + return + } + utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err) + return + } + utils.WriteResponse(w, http.StatusOK, "OK") +} |