2018-02-05 16:05:59 -05:00
|
|
|
package container // import "github.com/docker/docker/api/server/router/container"
|
2015-11-04 20:38:05 -05:00
|
|
|
|
2016-03-28 14:22:23 -04:00
|
|
|
import (
|
|
|
|
"github.com/docker/docker/api/server/httputils"
|
|
|
|
"github.com/docker/docker/api/server/router"
|
|
|
|
)
|
2015-11-04 20:38:05 -05:00
|
|
|
|
|
|
|
// containerRouter is a router to talk with the container controller
|
|
|
|
type containerRouter struct {
|
|
|
|
backend Backend
|
2016-03-28 14:22:23 -04:00
|
|
|
decoder httputils.ContainerDecoder
|
2015-11-04 20:38:05 -05:00
|
|
|
routes []router.Route
|
2020-06-05 04:59:52 -04:00
|
|
|
cgroup2 bool
|
2015-11-04 20:38:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewRouter initializes a new container router
|
2020-06-05 04:59:52 -04:00
|
|
|
func NewRouter(b Backend, decoder httputils.ContainerDecoder, cgroup2 bool) router.Router {
|
2015-11-04 20:38:05 -05:00
|
|
|
r := &containerRouter{
|
|
|
|
backend: b,
|
2016-03-28 14:22:23 -04:00
|
|
|
decoder: decoder,
|
2020-06-05 04:59:52 -04:00
|
|
|
cgroup2: cgroup2,
|
2015-11-04 20:38:05 -05:00
|
|
|
}
|
|
|
|
r.initRoutes()
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2015-12-30 12:20:41 -05:00
|
|
|
// Routes returns the available routes to the container controller
|
2015-11-04 20:38:05 -05:00
|
|
|
func (r *containerRouter) Routes() []router.Route {
|
|
|
|
return r.routes
|
|
|
|
}
|
|
|
|
|
|
|
|
// initRoutes initializes the routes in container router
|
|
|
|
func (r *containerRouter) initRoutes() {
|
|
|
|
r.routes = []router.Route{
|
|
|
|
// HEAD
|
2015-12-30 12:20:41 -05:00
|
|
|
router.NewHeadRoute("/containers/{name:.*}/archive", r.headContainersArchive),
|
2015-11-04 20:38:05 -05:00
|
|
|
// GET
|
2015-12-30 12:20:41 -05:00
|
|
|
router.NewGetRoute("/containers/json", r.getContainersJSON),
|
|
|
|
router.NewGetRoute("/containers/{name:.*}/export", r.getContainersExport),
|
|
|
|
router.NewGetRoute("/containers/{name:.*}/changes", r.getContainersChanges),
|
|
|
|
router.NewGetRoute("/containers/{name:.*}/json", r.getContainersByName),
|
|
|
|
router.NewGetRoute("/containers/{name:.*}/top", r.getContainersTop),
|
2018-11-27 17:13:43 -05:00
|
|
|
router.NewGetRoute("/containers/{name:.*}/logs", r.getContainersLogs),
|
|
|
|
router.NewGetRoute("/containers/{name:.*}/stats", r.getContainersStats),
|
2015-12-30 12:20:41 -05:00
|
|
|
router.NewGetRoute("/containers/{name:.*}/attach/ws", r.wsContainersAttach),
|
|
|
|
router.NewGetRoute("/exec/{id:.*}/json", r.getExecByID),
|
|
|
|
router.NewGetRoute("/containers/{name:.*}/archive", r.getContainersArchive),
|
2015-11-04 20:38:05 -05:00
|
|
|
// POST
|
2015-12-30 12:20:41 -05:00
|
|
|
router.NewPostRoute("/containers/create", r.postContainersCreate),
|
|
|
|
router.NewPostRoute("/containers/{name:.*}/kill", r.postContainersKill),
|
|
|
|
router.NewPostRoute("/containers/{name:.*}/pause", r.postContainersPause),
|
|
|
|
router.NewPostRoute("/containers/{name:.*}/unpause", r.postContainersUnpause),
|
|
|
|
router.NewPostRoute("/containers/{name:.*}/restart", r.postContainersRestart),
|
|
|
|
router.NewPostRoute("/containers/{name:.*}/start", r.postContainersStart),
|
|
|
|
router.NewPostRoute("/containers/{name:.*}/stop", r.postContainersStop),
|
2018-11-27 17:13:43 -05:00
|
|
|
router.NewPostRoute("/containers/{name:.*}/wait", r.postContainersWait),
|
2015-12-30 12:20:41 -05:00
|
|
|
router.NewPostRoute("/containers/{name:.*}/resize", r.postContainersResize),
|
|
|
|
router.NewPostRoute("/containers/{name:.*}/attach", r.postContainersAttach),
|
2016-06-03 13:38:03 -04:00
|
|
|
router.NewPostRoute("/containers/{name:.*}/copy", r.postContainersCopy), // Deprecated since 1.8, Errors out since 1.12
|
2015-12-30 12:20:41 -05:00
|
|
|
router.NewPostRoute("/containers/{name:.*}/exec", r.postContainerExecCreate),
|
|
|
|
router.NewPostRoute("/exec/{name:.*}/start", r.postContainerExecStart),
|
|
|
|
router.NewPostRoute("/exec/{name:.*}/resize", r.postContainerExecResize),
|
|
|
|
router.NewPostRoute("/containers/{name:.*}/rename", r.postContainerRename),
|
|
|
|
router.NewPostRoute("/containers/{name:.*}/update", r.postContainerUpdate),
|
2018-11-27 17:13:43 -05:00
|
|
|
router.NewPostRoute("/containers/prune", r.postContainersPrune),
|
2018-02-07 15:33:20 -05:00
|
|
|
router.NewPostRoute("/commit", r.postCommit),
|
2015-11-04 20:38:05 -05:00
|
|
|
// PUT
|
2015-12-30 12:20:41 -05:00
|
|
|
router.NewPutRoute("/containers/{name:.*}/archive", r.putContainersArchive),
|
2015-11-04 20:38:05 -05:00
|
|
|
// DELETE
|
2015-12-30 12:20:41 -05:00
|
|
|
router.NewDeleteRoute("/containers/{name:.*}", r.deleteContainers),
|
2015-11-04 20:38:05 -05:00
|
|
|
}
|
|
|
|
}
|