aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-01-14 22:03:01 -0500
committerGitHub <noreply@github.com>2021-01-14 22:03:01 -0500
commit3fcf346890c0437611fc18c30d58cc2d9f61fe6c (patch)
treea948999192d2089474214f4307eb454a9d0c2c59 /pkg/api/handlers/compat
parent8ce9995951b14a0a4d7252cdd97597411fd5f980 (diff)
parent997de2f8e9e5453a99108bde012aa6c41d7323ec (diff)
downloadpodman-3fcf346890c0437611fc18c30d58cc2d9f61fe6c.tar.gz
podman-3fcf346890c0437611fc18c30d58cc2d9f61fe6c.tar.bz2
podman-3fcf346890c0437611fc18c30d58cc2d9f61fe6c.zip
Merge pull request #8955 from mheon/rename
Container Rename
Diffstat (limited to 'pkg/api/handlers/compat')
-rw-r--r--pkg/api/handlers/compat/containers.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go
index 0f89c859e..6e1945db1 100644
--- a/pkg/api/handlers/compat/containers.go
+++ b/pkg/api/handlers/compat/containers.go
@@ -465,3 +465,34 @@ func formatCapabilities(slice []string) {
slice[i] = strings.TrimPrefix(slice[i], "CAP_")
}
}
+
+func RenameContainer(w http.ResponseWriter, r *http.Request) {
+ runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ decoder := r.Context().Value("decoder").(*schema.Decoder)
+
+ name := utils.GetName(r)
+ query := struct {
+ Name string `schema:"name"`
+ }{}
+ if err := decoder.Decode(&query, r.URL.Query()); err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ return
+ }
+
+ ctr, err := runtime.LookupContainer(name)
+ if err != nil {
+ utils.ContainerNotFound(w, name, err)
+ return
+ }
+
+ if _, err := runtime.RenameContainer(r.Context(), ctr, query.Name); err != nil {
+ if errors.Cause(err) == define.ErrPodExists || errors.Cause(err) == define.ErrCtrExists {
+ utils.Error(w, "Something went wrong.", http.StatusConflict, err)
+ return
+ }
+ utils.InternalServerError(w, err)
+ return
+ }
+
+ utils.WriteResponse(w, http.StatusNoContent, nil)
+}