From 3fea79bfd835960e3f6c9972305e350ee2e256b2 Mon Sep 17 00:00:00 2001 From: John Howard Date: Thu, 30 Jul 2015 15:28:11 -0700 Subject: [PATCH] Windows: Address more todos Signed-off-by: John Howard --- daemon/daemon.go | 33 +++++++++++++++++++++++++++++++++ daemon/daemon_unix.go | 32 +++++--------------------------- daemon/daemon_windows.go | 8 +++++--- 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 81272c846f..0e41903dfe 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -29,6 +29,7 @@ import ( "github.com/docker/docker/pkg/graphdb" "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/namesgenerator" + "github.com/docker/docker/pkg/nat" "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/sysinfo" "github.com/docker/docker/pkg/system" @@ -967,3 +968,35 @@ func getDefaultRouteMtu() (int, error) { } return 0, errNoDefaultRoute } + +// verifyContainerSettings performs validation of the hostconfig and config +// structures. +func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) { + + // First perform verification of settings common across all platforms. + if config != nil { + if config.WorkingDir != "" && !filepath.IsAbs(config.WorkingDir) { + return nil, fmt.Errorf("The working directory '%s' is invalid. It needs to be an absolute path.", config.WorkingDir) + } + } + + if hostConfig == nil { + return nil, nil + } + + for port := range hostConfig.PortBindings { + _, portStr := nat.SplitProtoPort(string(port)) + if _, err := nat.ParsePort(portStr); err != nil { + return nil, fmt.Errorf("Invalid port specification: %q", portStr) + } + for _, pb := range hostConfig.PortBindings[port] { + _, err := nat.NewPort(nat.SplitProtoPort(pb.HostPort)) + if err != nil { + return nil, fmt.Errorf("Invalid port specification: %q", pb.HostPort) + } + } + } + + // Now do platform-specific verification + return verifyPlatformContainerSettings(daemon, hostConfig, config) +} diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index f33ffea457..6a13c3ff3d 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -16,7 +16,6 @@ import ( "github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/fileutils" - "github.com/docker/docker/pkg/nat" "github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/pkg/system" @@ -117,6 +116,8 @@ func checkKernel() error { return nil } +// adaptContainerSettings is called during container creation to modify any +// settings necessary in the HostConfig structure. func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig) { if hostConfig == nil { return @@ -127,34 +128,11 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig) { } } -func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) { +// verifyPlatformContainerSettings performs platform-specific validation of the +// hostconfig and config structures. +func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) { var warnings []string - if config != nil { - // The check for a valid workdir path is made on the server rather than in the - // client. This is because we don't know the type of path (Linux or Windows) - // to validate on the client. - if config.WorkingDir != "" && !filepath.IsAbs(config.WorkingDir) { - return warnings, fmt.Errorf("The working directory '%s' is invalid. It needs to be an absolute path.", config.WorkingDir) - } - } - - if hostConfig == nil { - return warnings, nil - } - - for port := range hostConfig.PortBindings { - _, portStr := nat.SplitProtoPort(string(port)) - if _, err := nat.ParsePort(portStr); err != nil { - return warnings, fmt.Errorf("Invalid port specification: %q", portStr) - } - for _, pb := range hostConfig.PortBindings[port] { - _, err := nat.NewPort(nat.SplitProtoPort(pb.HostPort)) - if err != nil { - return warnings, fmt.Errorf("Invalid port specification: %q", pb.HostPort) - } - } - } if hostConfig.LxcConf.Len() > 0 && !strings.Contains(daemon.ExecutionDriver().Name(), "lxc") { return warnings, fmt.Errorf("Cannot use --lxc-conf with execdriver: %s", daemon.ExecutionDriver().Name()) } diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index e89526d834..8b79dd540f 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -73,12 +73,14 @@ func checkKernel() error { return nil } +// adaptContainerSettings is called during container creation to modify any +// settings necessary in the HostConfig structure. func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig) { - // TODO Windows. } -func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) { - // TODO Windows. Verifications TBC +// verifyPlatformContainerSettings performs platform-specific validation of the +// hostconfig and config structures. +func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) { return nil, nil }