Skip to content

Commit fa8d96e

Browse files
dongluochencalavera
authored andcommitted
Add container package for container APIs.
Signed-off-by: Dong Chen <dongluo.chen@docker.com>
1 parent a5bf10f commit fa8d96e

File tree

9 files changed

+245
-97
lines changed

9 files changed

+245
-97
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// +build !windows
2+
3+
package container
4+
5+
import (
6+
"io"
7+
"time"
8+
9+
"github.com/docker/docker/api/types"
10+
"github.com/docker/docker/api/types/versions/v1p19"
11+
"github.com/docker/docker/api/types/versions/v1p20"
12+
"github.com/docker/docker/daemon"
13+
"github.com/docker/docker/pkg/archive"
14+
"github.com/docker/docker/runconfig"
15+
)
16+
17+
// Backend is all the methods that need to be implemented to provide
18+
// container specific functionality
19+
type Backend interface {
20+
ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error)
21+
ContainerAttachWithLogs(prefixOrName string, c *daemon.ContainerAttachWithLogsConfig) error
22+
ContainerChanges(name string) ([]archive.Change, error)
23+
ContainerCopy(name string, res string) (io.ReadCloser, error)
24+
ContainerCreate(params *daemon.ContainerCreateConfig) (types.ContainerCreateResponse, error)
25+
ContainerExecCreate(config *runconfig.ExecConfig) (string, error)
26+
ContainerExecInspect(id string) (*daemon.ExecConfig, error)
27+
ContainerExecResize(name string, height, width int) error
28+
ContainerExecStart(name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error
29+
ContainerExport(name string, out io.Writer) error
30+
ContainerExtractToDir(name, path string, noOverwriteDirNonDir bool, content io.Reader) error
31+
ContainerInspect(name string, size bool) (*types.ContainerJSON, error)
32+
ContainerInspect120(name string) (*v1p20.ContainerJSON, error)
33+
// unix version
34+
ContainerInspectPre120(name string) (*v1p19.ContainerJSON, error)
35+
// windows version
36+
//ContainerInspectPre120(name string) (*types.ContainerJSON, error)
37+
ContainerKill(name string, sig uint64) error
38+
ContainerLogs(containerName string, config *daemon.ContainerLogsConfig) error
39+
ContainerPause(name string) error
40+
ContainerRename(oldName, newName string) error
41+
ContainerResize(name string, height, width int) error
42+
ContainerRestart(name string, seconds int) error
43+
ContainerRm(name string, config *daemon.ContainerRmConfig) error
44+
Containers(config *daemon.ContainersConfig) ([]*types.Container, error)
45+
ContainerStart(name string, hostConfig *runconfig.HostConfig) error
46+
ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error)
47+
ContainerStats(prefixOrName string, config *daemon.ContainerStatsConfig) error
48+
ContainerStop(name string, seconds int) error
49+
ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error)
50+
ContainerUnpause(name string) error
51+
ContainerWait(name string, timeout time.Duration) (int, error)
52+
ContainerWsAttachWithLogs(prefixOrName string, c *daemon.ContainerWsAttachWithLogsConfig) error
53+
ExecExists(name string) (bool, error)
54+
Exists(id string) bool
55+
IsPaused(id string) bool
56+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// +build windows
2+
3+
package container
4+
5+
import (
6+
"io"
7+
"time"
8+
9+
"github.com/docker/docker/api/types"
10+
"github.com/docker/docker/api/types/versions/v1p20"
11+
"github.com/docker/docker/daemon"
12+
"github.com/docker/docker/pkg/archive"
13+
"github.com/docker/docker/runconfig"
14+
)
15+
16+
// Backend is all the methods that need to be implemented to provide
17+
// container specific functionality
18+
type Backend interface {
19+
ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error)
20+
ContainerAttachWithLogs(prefixOrName string, c *daemon.ContainerAttachWithLogsConfig) error
21+
ContainerChanges(name string) ([]archive.Change, error)
22+
ContainerCopy(name string, res string) (io.ReadCloser, error)
23+
ContainerCreate(params *daemon.ContainerCreateConfig) (types.ContainerCreateResponse, error)
24+
ContainerExecCreate(config *runconfig.ExecConfig) (string, error)
25+
ContainerExecInspect(id string) (*daemon.ExecConfig, error)
26+
ContainerExecResize(name string, height, width int) error
27+
ContainerExecStart(name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error
28+
ContainerExport(name string, out io.Writer) error
29+
ContainerExtractToDir(name, path string, noOverwriteDirNonDir bool, content io.Reader) error
30+
ContainerInspect(name string, size bool) (*types.ContainerJSON, error)
31+
ContainerInspect120(name string) (*v1p20.ContainerJSON, error)
32+
// unix version
33+
//ContainerInspectPre120(name string) (*v1p19.ContainerJSON, error)
34+
// windows version
35+
ContainerInspectPre120(name string) (*types.ContainerJSON, error)
36+
ContainerKill(name string, sig uint64) error
37+
ContainerLogs(containerName string, config *daemon.ContainerLogsConfig) error
38+
ContainerPause(name string) error
39+
ContainerRename(oldName, newName string) error
40+
ContainerResize(name string, height, width int) error
41+
ContainerRestart(name string, seconds int) error
42+
ContainerRm(name string, config *daemon.ContainerRmConfig) error
43+
Containers(config *daemon.ContainersConfig) ([]*types.Container, error)
44+
ContainerStart(name string, hostConfig *runconfig.HostConfig) error
45+
ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error)
46+
ContainerStats(prefixOrName string, config *daemon.ContainerStatsConfig) error
47+
ContainerStop(name string, seconds int) error
48+
ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error)
49+
ContainerUnpause(name string) error
50+
ContainerWait(name string, timeout time.Duration) (int, error)
51+
ContainerWsAttachWithLogs(prefixOrName string, c *daemon.ContainerWsAttachWithLogsConfig) error
52+
ExecExists(name string) (bool, error)
53+
Exists(id string) bool
54+
IsPaused(id string) bool
55+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package container
2+
3+
import (
4+
"github.com/docker/docker/api/server/router"
5+
"github.com/docker/docker/api/server/router/local"
6+
)
7+
8+
// containerRouter is a router to talk with the container controller
9+
type containerRouter struct {
10+
backend Backend
11+
routes []router.Route
12+
}
13+
14+
// NewRouter initializes a new container router
15+
func NewRouter(b Backend) router.Router {
16+
r := &containerRouter{
17+
backend: b,
18+
}
19+
r.initRoutes()
20+
return r
21+
}
22+
23+
// Routes returns the available routers to the container controller
24+
func (r *containerRouter) Routes() []router.Route {
25+
return r.routes
26+
}
27+
28+
// initRoutes initializes the routes in container router
29+
func (r *containerRouter) initRoutes() {
30+
r.routes = []router.Route{
31+
// HEAD
32+
local.NewHeadRoute("/containers/{name:.*}/archive", r.headContainersArchive),
33+
// GET
34+
local.NewGetRoute("/containers/json", r.getContainersJSON),
35+
local.NewGetRoute("/containers/{name:.*}/export", r.getContainersExport),
36+
local.NewGetRoute("/containers/{name:.*}/changes", r.getContainersChanges),
37+
local.NewGetRoute("/containers/{name:.*}/json", r.getContainersByName),
38+
local.NewGetRoute("/containers/{name:.*}/top", r.getContainersTop),
39+
local.NewGetRoute("/containers/{name:.*}/logs", r.getContainersLogs),
40+
local.NewGetRoute("/containers/{name:.*}/stats", r.getContainersStats),
41+
local.NewGetRoute("/containers/{name:.*}/attach/ws", r.wsContainersAttach),
42+
local.NewGetRoute("/exec/{id:.*}/json", r.getExecByID),
43+
local.NewGetRoute("/containers/{name:.*}/archive", r.getContainersArchive),
44+
// POST
45+
local.NewPostRoute("/containers/create", r.postContainersCreate),
46+
local.NewPostRoute("/containers/{name:.*}/kill", r.postContainersKill),
47+
local.NewPostRoute("/containers/{name:.*}/pause", r.postContainersPause),
48+
local.NewPostRoute("/containers/{name:.*}/unpause", r.postContainersUnpause),
49+
local.NewPostRoute("/containers/{name:.*}/restart", r.postContainersRestart),
50+
local.NewPostRoute("/containers/{name:.*}/start", r.postContainersStart),
51+
local.NewPostRoute("/containers/{name:.*}/stop", r.postContainersStop),
52+
local.NewPostRoute("/containers/{name:.*}/wait", r.postContainersWait),
53+
local.NewPostRoute("/containers/{name:.*}/resize", r.postContainersResize),
54+
local.NewPostRoute("/containers/{name:.*}/attach", r.postContainersAttach),
55+
local.NewPostRoute("/containers/{name:.*}/copy", r.postContainersCopy),
56+
local.NewPostRoute("/containers/{name:.*}/exec", r.postContainerExecCreate),
57+
local.NewPostRoute("/exec/{name:.*}/start", r.postContainerExecStart),
58+
local.NewPostRoute("/exec/{name:.*}/resize", r.postContainerExecResize),
59+
local.NewPostRoute("/containers/{name:.*}/rename", r.postContainerRename),
60+
// PUT
61+
local.NewPutRoute("/containers/{name:.*}/archive", r.putContainersArchive),
62+
// DELETE
63+
local.NewDeleteRoute("/containers/{name:.*}", r.deleteContainers),
64+
}
65+
}

0 commit comments

Comments
 (0)