summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/libpod/networks.go
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-01-30 12:40:19 -0600
committerBrent Baude <bbaude@redhat.com>2020-01-31 08:38:25 -0600
commitf1eaccedfa08455d699d00dcda63b95aeb34833e (patch)
tree65d385fd683a66686b225827c760e5bc95f7e346 /pkg/api/handlers/libpod/networks.go
parent36af2833f954e1c822b917ecff45c05858188c2d (diff)
downloadpodman-f1eaccedfa08455d699d00dcda63b95aeb34833e.tar.gz
podman-f1eaccedfa08455d699d00dcda63b95aeb34833e.tar.bz2
podman-f1eaccedfa08455d699d00dcda63b95aeb34833e.zip
fix longname handling for bindings
the api needs to account for image input where the image is encoded as a fqd image name. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/api/handlers/libpod/networks.go')
-rw-r--r--pkg/api/handlers/libpod/networks.go85
1 files changed, 85 insertions, 0 deletions
diff --git a/pkg/api/handlers/libpod/networks.go b/pkg/api/handlers/libpod/networks.go
new file mode 100644
index 000000000..e3dbe3b35
--- /dev/null
+++ b/pkg/api/handlers/libpod/networks.go
@@ -0,0 +1,85 @@
+package libpod
+
+import (
+ "net/http"
+
+ "github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/api/handlers/utils"
+ "github.com/containers/libpod/pkg/network"
+ "github.com/gorilla/schema"
+ "github.com/pkg/errors"
+)
+
+func CreateNetwork(w http.ResponseWriter, r *http.Request) {}
+func ListNetworks(w http.ResponseWriter, r *http.Request) {
+ runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ config, err := runtime.GetConfig()
+ if err != nil {
+ utils.InternalServerError(w, err)
+ return
+ }
+ configDir := config.CNIConfigDir
+ if len(configDir) < 1 {
+ configDir = network.CNIConfigDir
+ }
+ networks, err := network.LoadCNIConfsFromDir(configDir)
+ if err != nil {
+ utils.InternalServerError(w, err)
+ return
+ }
+ utils.WriteResponse(w, http.StatusOK, networks)
+}
+
+func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
+ // 200 ok
+ // 404 no such
+ // 500 internal
+ decoder := r.Context().Value("decoder").(*schema.Decoder)
+ query := struct {
+ Force bool `schema:"force"`
+ }{
+ // override any golang type defaults
+ }
+ if err := decoder.Decode(&query, r.URL.Query()); err != nil {
+ utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
+ errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
+ return
+ }
+ name := utils.GetName(r)
+ if err := network.RemoveNetwork(name); err != nil {
+ // If the network cannot be found, we return a 404.
+ if errors.Cause(err) == network.ErrNetworkNotFound {
+ utils.Error(w, "Something went wrong", http.StatusNotFound, err)
+ return
+ }
+ utils.InternalServerError(w, err)
+ return
+ }
+ utils.WriteResponse(w, http.StatusOK, "")
+}
+
+func InspectNetwork(w http.ResponseWriter, r *http.Request) {
+ decoder := r.Context().Value("decoder").(*schema.Decoder)
+ query := struct {
+ Force bool `schema:"force"`
+ }{
+ // override any golang type defaults
+ }
+ if err := decoder.Decode(&query, r.URL.Query()); err != nil {
+ utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
+ errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
+ return
+ }
+ name := utils.GetName(r)
+ n, err := network.InspectNetwork(name)
+ if err != nil {
+ // If the network cannot be found, we return a 404.
+ if errors.Cause(err) == network.ErrNetworkNotFound {
+ utils.Error(w, "Something went wrong", http.StatusNotFound, err)
+ return
+ }
+ utils.InternalServerError(w, err)
+ return
+ }
+ utils.WriteResponse(w, http.StatusOK, n)
+}