Browse code

Move versioned references of inspect functions to the daemon.

Leaving only one versioned main function that a backend must implement.

Signed-off-by: David Calavera <david.calavera@gmail.com>

David Calavera authored on 2015/11/25 02:55:45
Showing 7 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,51 @@
0
+// +build !windows
1
+
2
+package container
3
+
4
+import (
5
+	"io"
6
+	"time"
7
+
8
+	"github.com/docker/docker/api/types"
9
+	"github.com/docker/docker/daemon"
10
+	"github.com/docker/docker/daemon/exec"
11
+	"github.com/docker/docker/pkg/archive"
12
+	"github.com/docker/docker/pkg/version"
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) (*exec.Config, 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, version version.Version) (interface{}, error)
31
+	ContainerKill(name string, sig uint64) error
32
+	ContainerLogs(containerName string, config *daemon.ContainerLogsConfig) error
33
+	ContainerPause(name string) error
34
+	ContainerRename(oldName, newName string) error
35
+	ContainerResize(name string, height, width int) error
36
+	ContainerRestart(name string, seconds int) error
37
+	ContainerRm(name string, config *daemon.ContainerRmConfig) error
38
+	Containers(config *daemon.ContainersConfig) ([]*types.Container, error)
39
+	ContainerStart(name string, hostConfig *runconfig.HostConfig) error
40
+	ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error)
41
+	ContainerStats(prefixOrName string, config *daemon.ContainerStatsConfig) error
42
+	ContainerStop(name string, seconds int) error
43
+	ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error)
44
+	ContainerUnpause(name string) error
45
+	ContainerWait(name string, timeout time.Duration) (int, error)
46
+	ContainerWsAttachWithLogs(prefixOrName string, c *daemon.ContainerWsAttachWithLogsConfig) error
47
+	ExecExists(name string) (bool, error)
48
+	Exists(id string) bool
49
+	IsPaused(id string) bool
50
+}
0 51
deleted file mode 100644
... ...
@@ -1,56 +0,0 @@
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
-}
57 1
deleted file mode 100644
... ...
@@ -1,55 +0,0 @@
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
-}
... ...
@@ -11,20 +11,8 @@ import (
11 11
 func (s *containerRouter) getContainersByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
12 12
 	displaySize := httputils.BoolValue(r, "size")
13 13
 
14
-	var json interface{}
15
-	var err error
16
-
17 14
 	version := httputils.VersionFromContext(ctx)
18
-
19
-	switch {
20
-	case version.LessThan("1.20"):
21
-		json, err = s.backend.ContainerInspectPre120(vars["name"])
22
-	case version.Equal("1.20"):
23
-		json, err = s.backend.ContainerInspect120(vars["name"])
24
-	default:
25
-		json, err = s.backend.ContainerInspect(vars["name"], displaySize)
26
-	}
27
-
15
+	json, err := s.backend.ContainerInspect(vars["name"], displaySize, version)
28 16
 	if err != nil {
29 17
 		return err
30 18
 	}
... ...
@@ -9,12 +9,23 @@ import (
9 9
 	"github.com/docker/docker/daemon/exec"
10 10
 	"github.com/docker/docker/daemon/network"
11 11
 	"github.com/docker/docker/layer"
12
+	"github.com/docker/docker/pkg/version"
12 13
 )
13 14
 
14 15
 // ContainerInspect returns low-level information about a
15 16
 // container. Returns an error if the container cannot be found, or if
16 17
 // there is an error getting the data.
17
-func (daemon *Daemon) ContainerInspect(name string, size bool) (*types.ContainerJSON, error) {
18
+func (daemon *Daemon) ContainerInspect(name string, size bool, version version.Version) (interface{}, error) {
19
+	switch {
20
+	case version.LessThan("1.20"):
21
+		return daemon.containerInspectPre120(name)
22
+	case version.Equal("1.20"):
23
+		return daemon.containerInspect120(name)
24
+	}
25
+	return daemon.containerInspectCurrent(name, size)
26
+}
27
+
28
+func (daemon *Daemon) containerInspectCurrent(name string, size bool) (*types.ContainerJSON, error) {
18 29
 	container, err := daemon.Get(name)
19 30
 	if err != nil {
20 31
 		return nil, err
... ...
@@ -53,8 +64,8 @@ func (daemon *Daemon) ContainerInspect(name string, size bool) (*types.Container
53 53
 	}, nil
54 54
 }
55 55
 
56
-// ContainerInspect120 serializes the master version of a container into a json type.
57
-func (daemon *Daemon) ContainerInspect120(name string) (*v1p20.ContainerJSON, error) {
56
+// containerInspect120 serializes the master version of a container into a json type.
57
+func (daemon *Daemon) containerInspect120(name string) (*v1p20.ContainerJSON, error) {
58 58
 	container, err := daemon.Get(name)
59 59
 	if err != nil {
60 60
 		return nil, err
... ...
@@ -17,8 +17,8 @@ func setPlatformSpecificContainerFields(container *Container, contJSONBase *type
17 17
 	return contJSONBase
18 18
 }
19 19
 
20
-// ContainerInspectPre120 gets containers for pre 1.20 APIs.
21
-func (daemon *Daemon) ContainerInspectPre120(name string) (*v1p19.ContainerJSON, error) {
20
+// containerInspectPre120 gets containers for pre 1.20 APIs.
21
+func (daemon *Daemon) containerInspectPre120(name string) (*v1p19.ContainerJSON, error) {
22 22
 	container, err := daemon.Get(name)
23 23
 	if err != nil {
24 24
 		return nil, err
... ...
@@ -21,7 +21,7 @@ func addMountPoints(container *Container) []types.MountPoint {
21 21
 	return mountPoints
22 22
 }
23 23
 
24
-// ContainerInspectPre120 get containers for pre 1.20 APIs.
25
-func (daemon *Daemon) ContainerInspectPre120(name string) (*types.ContainerJSON, error) {
26
-	return daemon.ContainerInspect(name, false)
24
+// containerInspectPre120 get containers for pre 1.20 APIs.
25
+func (daemon *Daemon) containerInspectPre120(name string) (*types.ContainerJSON, error) {
26
+	return daemon.containerInspectCurrent(name, false)
27 27
 }