diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-10-22 16:19:11 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-22 16:19:11 -0400 |
commit | a53a660313c6539c3e4a3558beb49836ca76d46f (patch) | |
tree | 3b887656f560a4d997a7456572738088e5ad8892 /pkg/api/handlers/compat/networks.go | |
parent | d340f8523c9610644c8a195d1e3e9b3a5d32c5b3 (diff) | |
parent | 68419365257f1fcaa638605576a0583ef282a5a5 (diff) | |
download | podman-a53a660313c6539c3e4a3558beb49836ca76d46f.tar.gz podman-a53a660313c6539c3e4a3558beb49836ca76d46f.tar.bz2 podman-a53a660313c6539c3e4a3558beb49836ca76d46f.zip |
Merge pull request #8078 from baude/networkdisconnect
APIv2 compatibility network connect|disconnect
Diffstat (limited to 'pkg/api/handlers/compat/networks.go')
-rw-r--r-- | pkg/api/handlers/compat/networks.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/pkg/api/handlers/compat/networks.go b/pkg/api/handlers/compat/networks.go index 629ca565e..8011c0a04 100644 --- a/pkg/api/handlers/compat/networks.go +++ b/pkg/api/handlers/compat/networks.go @@ -20,6 +20,7 @@ import ( dockerNetwork "github.com/docker/docker/api/types/network" "github.com/gorilla/schema" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) func InspectNetwork(w http.ResponseWriter, r *http.Request) { @@ -315,3 +316,81 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) { } utils.WriteResponse(w, http.StatusNoContent, "") } + +// Connect adds a container to a network +// TODO: For now this func is a no-op that checks the container name, network name, and +// responds with a 200. This allows the call to remain intact. We need to decide how +// we make this work with CNI networking and setup/teardown. +func Connect(w http.ResponseWriter, r *http.Request) { + runtime := r.Context().Value("runtime").(*libpod.Runtime) + + var netConnect types.NetworkConnect + if err := json.NewDecoder(r.Body).Decode(&netConnect); err != nil { + utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()")) + return + } + config, err := runtime.GetConfig() + if err != nil { + utils.InternalServerError(w, err) + return + } + name := utils.GetName(r) + exists, err := network.Exists(config, name) + if err != nil { + utils.InternalServerError(w, err) + return + } + if !exists { + utils.Error(w, "network not found", http.StatusNotFound, define.ErrNoSuchNetwork) + return + } + if _, err = runtime.LookupContainer(netConnect.Container); err != nil { + if errors.Cause(err) == define.ErrNoSuchCtr { + utils.ContainerNotFound(w, netConnect.Container, err) + return + } + utils.Error(w, "unable to lookup container", http.StatusInternalServerError, err) + return + } + logrus.Warnf("network connect endpoint is not fully implemented - tried to connect container %s to network %s", netConnect.Container, name) + utils.WriteResponse(w, http.StatusOK, "OK") +} + +// Disconnect removes a container from a network +// TODO: For now this func is a no-op that checks the container name, network name, and +// responds with a 200. This allows the call to remain intact. We need to decide how +// we make this work with CNI networking and setup/teardown. +func Disconnect(w http.ResponseWriter, r *http.Request) { + runtime := r.Context().Value("runtime").(*libpod.Runtime) + + var netDisconnect types.NetworkDisconnect + if err := json.NewDecoder(r.Body).Decode(&netDisconnect); err != nil { + utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()")) + return + } + config, err := runtime.GetConfig() + if err != nil { + utils.InternalServerError(w, err) + return + } + name := utils.GetName(r) + exists, err := network.Exists(config, name) + if err != nil { + utils.InternalServerError(w, err) + return + } + if !exists { + utils.Error(w, "network not found", http.StatusNotFound, define.ErrNoSuchNetwork) + return + } + if _, err = runtime.LookupContainer(netDisconnect.Container); err != nil { + if errors.Cause(err) == define.ErrNoSuchCtr { + utils.ContainerNotFound(w, netDisconnect.Container, err) + return + } + utils.Error(w, "unable to lookup container", http.StatusInternalServerError, err) + return + } + logrus.Warnf("network disconnect endpoint is not fully implemented - tried to connect container %s to network %s", netDisconnect.Container, name) + utils.WriteResponse(w, http.StatusOK, "OK") +} |