mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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>
This commit is contained in:
parent
fa8d96ebe2
commit
38abba9e2c
6 changed files with 25 additions and 86 deletions
|
@ -1,4 +1,4 @@
|
||||||
// +build windows
|
// +build !windows
|
||||||
|
|
||||||
package container
|
package container
|
||||||
|
|
||||||
|
@ -7,9 +7,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/versions/v1p20"
|
|
||||||
"github.com/docker/docker/daemon"
|
"github.com/docker/docker/daemon"
|
||||||
|
"github.com/docker/docker/daemon/exec"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
"github.com/docker/docker/pkg/version"
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,17 +23,12 @@ type Backend interface {
|
||||||
ContainerCopy(name string, res string) (io.ReadCloser, error)
|
ContainerCopy(name string, res string) (io.ReadCloser, error)
|
||||||
ContainerCreate(params *daemon.ContainerCreateConfig) (types.ContainerCreateResponse, error)
|
ContainerCreate(params *daemon.ContainerCreateConfig) (types.ContainerCreateResponse, error)
|
||||||
ContainerExecCreate(config *runconfig.ExecConfig) (string, error)
|
ContainerExecCreate(config *runconfig.ExecConfig) (string, error)
|
||||||
ContainerExecInspect(id string) (*daemon.ExecConfig, error)
|
ContainerExecInspect(id string) (*exec.Config, error)
|
||||||
ContainerExecResize(name string, height, width int) error
|
ContainerExecResize(name string, height, width int) error
|
||||||
ContainerExecStart(name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error
|
ContainerExecStart(name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error
|
||||||
ContainerExport(name string, out io.Writer) error
|
ContainerExport(name string, out io.Writer) error
|
||||||
ContainerExtractToDir(name, path string, noOverwriteDirNonDir bool, content io.Reader) error
|
ContainerExtractToDir(name, path string, noOverwriteDirNonDir bool, content io.Reader) error
|
||||||
ContainerInspect(name string, size bool) (*types.ContainerJSON, error)
|
ContainerInspect(name string, size bool, version version.Version) (interface{}, error)
|
||||||
ContainerInspect120(name string) (*v1p20.ContainerJSON, error)
|
|
||||||
// unix version
|
|
||||||
//ContainerInspectPre120(name string) (*v1p19.ContainerJSON, error)
|
|
||||||
// windows version
|
|
||||||
ContainerInspectPre120(name string) (*types.ContainerJSON, error)
|
|
||||||
ContainerKill(name string, sig uint64) error
|
ContainerKill(name string, sig uint64) error
|
||||||
ContainerLogs(containerName string, config *daemon.ContainerLogsConfig) error
|
ContainerLogs(containerName string, config *daemon.ContainerLogsConfig) error
|
||||||
ContainerPause(name string) error
|
ContainerPause(name string) error
|
|
@ -1,56 +0,0 @@
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package container
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
|
||||||
"github.com/docker/docker/api/types/versions/v1p19"
|
|
||||||
"github.com/docker/docker/api/types/versions/v1p20"
|
|
||||||
"github.com/docker/docker/daemon"
|
|
||||||
"github.com/docker/docker/pkg/archive"
|
|
||||||
"github.com/docker/docker/runconfig"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Backend is all the methods that need to be implemented to provide
|
|
||||||
// container specific functionality
|
|
||||||
type Backend interface {
|
|
||||||
ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error)
|
|
||||||
ContainerAttachWithLogs(prefixOrName string, c *daemon.ContainerAttachWithLogsConfig) error
|
|
||||||
ContainerChanges(name string) ([]archive.Change, error)
|
|
||||||
ContainerCopy(name string, res string) (io.ReadCloser, error)
|
|
||||||
ContainerCreate(params *daemon.ContainerCreateConfig) (types.ContainerCreateResponse, error)
|
|
||||||
ContainerExecCreate(config *runconfig.ExecConfig) (string, error)
|
|
||||||
ContainerExecInspect(id string) (*daemon.ExecConfig, error)
|
|
||||||
ContainerExecResize(name string, height, width int) error
|
|
||||||
ContainerExecStart(name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error
|
|
||||||
ContainerExport(name string, out io.Writer) error
|
|
||||||
ContainerExtractToDir(name, path string, noOverwriteDirNonDir bool, content io.Reader) error
|
|
||||||
ContainerInspect(name string, size bool) (*types.ContainerJSON, error)
|
|
||||||
ContainerInspect120(name string) (*v1p20.ContainerJSON, error)
|
|
||||||
// unix version
|
|
||||||
ContainerInspectPre120(name string) (*v1p19.ContainerJSON, error)
|
|
||||||
// windows version
|
|
||||||
//ContainerInspectPre120(name string) (*types.ContainerJSON, error)
|
|
||||||
ContainerKill(name string, sig uint64) error
|
|
||||||
ContainerLogs(containerName string, config *daemon.ContainerLogsConfig) error
|
|
||||||
ContainerPause(name string) error
|
|
||||||
ContainerRename(oldName, newName string) error
|
|
||||||
ContainerResize(name string, height, width int) error
|
|
||||||
ContainerRestart(name string, seconds int) error
|
|
||||||
ContainerRm(name string, config *daemon.ContainerRmConfig) error
|
|
||||||
Containers(config *daemon.ContainersConfig) ([]*types.Container, error)
|
|
||||||
ContainerStart(name string, hostConfig *runconfig.HostConfig) error
|
|
||||||
ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error)
|
|
||||||
ContainerStats(prefixOrName string, config *daemon.ContainerStatsConfig) error
|
|
||||||
ContainerStop(name string, seconds int) error
|
|
||||||
ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error)
|
|
||||||
ContainerUnpause(name string) error
|
|
||||||
ContainerWait(name string, timeout time.Duration) (int, error)
|
|
||||||
ContainerWsAttachWithLogs(prefixOrName string, c *daemon.ContainerWsAttachWithLogsConfig) error
|
|
||||||
ExecExists(name string) (bool, error)
|
|
||||||
Exists(id string) bool
|
|
||||||
IsPaused(id string) bool
|
|
||||||
}
|
|
|
@ -11,20 +11,8 @@ import (
|
||||||
func (s *containerRouter) getContainersByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func (s *containerRouter) getContainersByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
displaySize := httputils.BoolValue(r, "size")
|
displaySize := httputils.BoolValue(r, "size")
|
||||||
|
|
||||||
var json interface{}
|
|
||||||
var err error
|
|
||||||
|
|
||||||
version := httputils.VersionFromContext(ctx)
|
version := httputils.VersionFromContext(ctx)
|
||||||
|
json, err := s.backend.ContainerInspect(vars["name"], displaySize, version)
|
||||||
switch {
|
|
||||||
case version.LessThan("1.20"):
|
|
||||||
json, err = s.backend.ContainerInspectPre120(vars["name"])
|
|
||||||
case version.Equal("1.20"):
|
|
||||||
json, err = s.backend.ContainerInspect120(vars["name"])
|
|
||||||
default:
|
|
||||||
json, err = s.backend.ContainerInspect(vars["name"], displaySize)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,23 @@ import (
|
||||||
"github.com/docker/docker/daemon/exec"
|
"github.com/docker/docker/daemon/exec"
|
||||||
"github.com/docker/docker/daemon/network"
|
"github.com/docker/docker/daemon/network"
|
||||||
"github.com/docker/docker/layer"
|
"github.com/docker/docker/layer"
|
||||||
|
"github.com/docker/docker/pkg/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerInspect returns low-level information about a
|
// ContainerInspect returns low-level information about a
|
||||||
// container. Returns an error if the container cannot be found, or if
|
// container. Returns an error if the container cannot be found, or if
|
||||||
// there is an error getting the data.
|
// there is an error getting the data.
|
||||||
func (daemon *Daemon) ContainerInspect(name string, size bool) (*types.ContainerJSON, error) {
|
func (daemon *Daemon) ContainerInspect(name string, size bool, version version.Version) (interface{}, error) {
|
||||||
|
switch {
|
||||||
|
case version.LessThan("1.20"):
|
||||||
|
return daemon.containerInspectPre120(name)
|
||||||
|
case version.Equal("1.20"):
|
||||||
|
return daemon.containerInspect120(name)
|
||||||
|
}
|
||||||
|
return daemon.containerInspectCurrent(name, size)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (daemon *Daemon) containerInspectCurrent(name string, size bool) (*types.ContainerJSON, error) {
|
||||||
container, err := daemon.Get(name)
|
container, err := daemon.Get(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -53,8 +64,8 @@ func (daemon *Daemon) ContainerInspect(name string, size bool) (*types.Container
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerInspect120 serializes the master version of a container into a json type.
|
// containerInspect120 serializes the master version of a container into a json type.
|
||||||
func (daemon *Daemon) ContainerInspect120(name string) (*v1p20.ContainerJSON, error) {
|
func (daemon *Daemon) containerInspect120(name string) (*v1p20.ContainerJSON, error) {
|
||||||
container, err := daemon.Get(name)
|
container, err := daemon.Get(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -17,8 +17,8 @@ func setPlatformSpecificContainerFields(container *Container, contJSONBase *type
|
||||||
return contJSONBase
|
return contJSONBase
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerInspectPre120 gets containers for pre 1.20 APIs.
|
// containerInspectPre120 gets containers for pre 1.20 APIs.
|
||||||
func (daemon *Daemon) ContainerInspectPre120(name string) (*v1p19.ContainerJSON, error) {
|
func (daemon *Daemon) containerInspectPre120(name string) (*v1p19.ContainerJSON, error) {
|
||||||
container, err := daemon.Get(name)
|
container, err := daemon.Get(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -21,7 +21,7 @@ func addMountPoints(container *Container) []types.MountPoint {
|
||||||
return mountPoints
|
return mountPoints
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerInspectPre120 get containers for pre 1.20 APIs.
|
// containerInspectPre120 get containers for pre 1.20 APIs.
|
||||||
func (daemon *Daemon) ContainerInspectPre120(name string) (*types.ContainerJSON, error) {
|
func (daemon *Daemon) containerInspectPre120(name string) (*types.ContainerJSON, error) {
|
||||||
return daemon.ContainerInspect(name, false)
|
return daemon.containerInspectCurrent(name, false)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue