aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/handlers/libpod
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/api/handlers/libpod')
-rw-r--r--pkg/api/handlers/libpod/containers.go9
-rw-r--r--pkg/api/handlers/libpod/healthcheck.go6
-rw-r--r--pkg/api/handlers/libpod/images.go12
-rw-r--r--pkg/api/handlers/libpod/networks.go85
-rw-r--r--pkg/api/handlers/libpod/pods.go27
-rw-r--r--pkg/api/handlers/libpod/volumes.go7
6 files changed, 105 insertions, 41 deletions
diff --git a/pkg/api/handlers/libpod/containers.go b/pkg/api/handlers/libpod/containers.go
index db1cf26ff..54acdbd36 100644
--- a/pkg/api/handlers/libpod/containers.go
+++ b/pkg/api/handlers/libpod/containers.go
@@ -9,7 +9,6 @@ import (
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/api/handlers"
"github.com/containers/libpod/pkg/api/handlers/utils"
- "github.com/gorilla/mux"
"github.com/gorilla/schema"
"github.com/pkg/errors"
)
@@ -20,7 +19,7 @@ func StopContainer(w http.ResponseWriter, r *http.Request) {
func ContainerExists(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
_, err := runtime.LookupContainer(name)
if err != nil {
utils.ContainerNotFound(w, name, err)
@@ -105,7 +104,7 @@ func GetContainer(w http.ResponseWriter, r *http.Request) {
return
}
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
container, err := runtime.LookupContainer(name)
if err != nil {
utils.ContainerNotFound(w, name, err)
@@ -147,7 +146,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
func UnmountContainer(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
conn, err := runtime.LookupContainer(name)
if err != nil {
utils.ContainerNotFound(w, name, err)
@@ -163,7 +162,7 @@ func UnmountContainer(w http.ResponseWriter, r *http.Request) {
}
func MountContainer(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
conn, err := runtime.LookupContainer(name)
if err != nil {
utils.ContainerNotFound(w, name, err)
diff --git a/pkg/api/handlers/libpod/healthcheck.go b/pkg/api/handlers/libpod/healthcheck.go
index 0d7bf3ea7..6c74500b9 100644
--- a/pkg/api/handlers/libpod/healthcheck.go
+++ b/pkg/api/handlers/libpod/healthcheck.go
@@ -5,15 +5,11 @@ import (
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/api/handlers/utils"
- "github.com/gorilla/mux"
)
func RunHealthCheck(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 404 no such
- // 500 internal
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
status, err := runtime.HealthCheck(name)
if err != nil {
if status == libpod.HealthCheckContainerNotFound {
diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go
index 9f0876618..202ed5eaa 100644
--- a/pkg/api/handlers/libpod/images.go
+++ b/pkg/api/handlers/libpod/images.go
@@ -11,7 +11,6 @@ import (
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/api/handlers"
"github.com/containers/libpod/pkg/api/handlers/utils"
- "github.com/gorilla/mux"
"github.com/gorilla/schema"
"github.com/pkg/errors"
)
@@ -28,11 +27,8 @@ import (
// create
func ImageExists(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 404 no such
- // 500 internal
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
_, err := runtime.ImageRuntime().NewFromLocal(name)
if err != nil {
@@ -45,7 +41,7 @@ func ImageExists(w http.ResponseWriter, r *http.Request) {
func ImageTree(w http.ResponseWriter, r *http.Request) {
// tree is a bit of a mess ... logic is in adapter and therefore not callable from here. needs rework
- // name := mux.Vars(r)["name"]
+ // name := utils.GetName(r)
// _, layerInfoMap, _, err := s.Runtime.Tree(name)
// if err != nil {
// Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrapf(err, "Failed to find image information for %q", name))
@@ -57,7 +53,7 @@ func ImageTree(w http.ResponseWriter, r *http.Request) {
}
func GetImage(w http.ResponseWriter, r *http.Request) {
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
newImage, err := handlers.GetImage(r, name)
if err != nil {
utils.Error(w, "Something went wrong.", http.StatusNotFound, errors.Wrapf(err, "Failed to find image %s", name))
@@ -160,7 +156,7 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "unable to close tempfile"))
return
}
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
newImage, err := runtime.ImageRuntime().NewFromLocal(name)
if err != nil {
utils.ImageNotFound(w, name, err)
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)
+}
diff --git a/pkg/api/handlers/libpod/pods.go b/pkg/api/handlers/libpod/pods.go
index 50d763338..091368985 100644
--- a/pkg/api/handlers/libpod/pods.go
+++ b/pkg/api/handlers/libpod/pods.go
@@ -19,8 +19,6 @@ import (
)
func PodCreate(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 500 internal
var (
runtime = r.Context().Value("runtime").(*libpod.Runtime)
options []libpod.PodCreateOption
@@ -141,7 +139,7 @@ func Pods(w http.ResponseWriter, r *http.Request) {
func PodInspect(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
pod, err := runtime.LookupPod(name)
if err != nil {
utils.PodNotFound(w, name, err)
@@ -156,10 +154,6 @@ func PodInspect(w http.ResponseWriter, r *http.Request) {
}
func PodStop(w http.ResponseWriter, r *http.Request) {
- // 200
- // 304 not modified
- // 404 no such
- // 500 internal
var (
stopError error
runtime = r.Context().Value("runtime").(*libpod.Runtime)
@@ -177,7 +171,7 @@ func PodStop(w http.ResponseWriter, r *http.Request) {
return
}
allContainersStopped := true
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
pod, err := runtime.LookupPod(name)
if err != nil {
utils.PodNotFound(w, name, err)
@@ -224,7 +218,7 @@ func PodStop(w http.ResponseWriter, r *http.Request) {
func PodStart(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
allContainersRunning := true
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
pod, err := runtime.LookupPod(name)
if err != nil {
utils.PodNotFound(w, name, err)
@@ -278,7 +272,7 @@ func PodDelete(w http.ResponseWriter, r *http.Request) {
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
return
}
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
pod, err := runtime.LookupPod(name)
if err != nil {
utils.PodNotFound(w, name, err)
@@ -293,7 +287,7 @@ func PodDelete(w http.ResponseWriter, r *http.Request) {
func PodRestart(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
pod, err := runtime.LookupPod(name)
if err != nil {
utils.PodNotFound(w, name, err)
@@ -321,7 +315,7 @@ func PodPrune(w http.ResponseWriter, r *http.Request) {
func PodPause(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
pod, err := runtime.LookupPod(name)
if err != nil {
utils.PodNotFound(w, name, err)
@@ -336,11 +330,8 @@ func PodPause(w http.ResponseWriter, r *http.Request) {
}
func PodUnpause(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 404 no such
- // 500 internal
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
pod, err := runtime.LookupPod(name)
if err != nil {
utils.PodNotFound(w, name, err)
@@ -379,7 +370,7 @@ func PodKill(w http.ResponseWriter, r *http.Request) {
if err != nil {
utils.InternalServerError(w, errors.Wrapf(err, "unable to parse signal value"))
}
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
pod, err := runtime.LookupPod(name)
if err != nil {
utils.PodNotFound(w, name, err)
@@ -412,7 +403,7 @@ func PodKill(w http.ResponseWriter, r *http.Request) {
func PodExists(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
_, err := runtime.LookupPod(name)
if err != nil {
utils.PodNotFound(w, name, err)
diff --git a/pkg/api/handlers/libpod/volumes.go b/pkg/api/handlers/libpod/volumes.go
index 3e0e597c6..7e7e46718 100644
--- a/pkg/api/handlers/libpod/volumes.go
+++ b/pkg/api/handlers/libpod/volumes.go
@@ -8,15 +8,12 @@ import (
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/api/handlers"
"github.com/containers/libpod/pkg/api/handlers/utils"
- "github.com/gorilla/mux"
"github.com/gorilla/schema"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
func CreateVolume(w http.ResponseWriter, r *http.Request) {
- // 200 ok
- // 500 internal
var (
volumeOptions []libpod.VolumeCreateOption
runtime = r.Context().Value("runtime").(*libpod.Runtime)
@@ -66,7 +63,7 @@ func InspectVolume(w http.ResponseWriter, r *http.Request) {
var (
runtime = r.Context().Value("runtime").(*libpod.Runtime)
)
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
vol, err := runtime.GetVolume(name)
if err != nil {
utils.VolumeNotFound(w, name, err)
@@ -132,7 +129,7 @@ func RemoveVolume(w http.ResponseWriter, r *http.Request) {
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
return
}
- name := mux.Vars(r)["name"]
+ name := utils.GetName(r)
vol, err := runtime.LookupVolume(name)
if err != nil {
utils.VolumeNotFound(w, name, err)