Browse Source

Windows: Address more todos

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard 10 years ago
parent
commit
3fea79bfd8
3 changed files with 43 additions and 30 deletions
  1. 33 0
      daemon/daemon.go
  2. 5 27
      daemon/daemon_unix.go
  3. 5 3
      daemon/daemon_windows.go

+ 33 - 0
daemon/daemon.go

@@ -29,6 +29,7 @@ import (
 	"github.com/docker/docker/pkg/graphdb"
 	"github.com/docker/docker/pkg/graphdb"
 	"github.com/docker/docker/pkg/ioutils"
 	"github.com/docker/docker/pkg/ioutils"
 	"github.com/docker/docker/pkg/namesgenerator"
 	"github.com/docker/docker/pkg/namesgenerator"
+	"github.com/docker/docker/pkg/nat"
 	"github.com/docker/docker/pkg/stringid"
 	"github.com/docker/docker/pkg/stringid"
 	"github.com/docker/docker/pkg/sysinfo"
 	"github.com/docker/docker/pkg/sysinfo"
 	"github.com/docker/docker/pkg/system"
 	"github.com/docker/docker/pkg/system"
@@ -967,3 +968,35 @@ func getDefaultRouteMtu() (int, error) {
 	}
 	}
 	return 0, errNoDefaultRoute
 	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)
+}

+ 5 - 27
daemon/daemon_unix.go

@@ -16,7 +16,6 @@ import (
 	"github.com/docker/docker/daemon/graphdriver"
 	"github.com/docker/docker/daemon/graphdriver"
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/fileutils"
 	"github.com/docker/docker/pkg/fileutils"
-	"github.com/docker/docker/pkg/nat"
 	"github.com/docker/docker/pkg/parsers"
 	"github.com/docker/docker/pkg/parsers"
 	"github.com/docker/docker/pkg/parsers/kernel"
 	"github.com/docker/docker/pkg/parsers/kernel"
 	"github.com/docker/docker/pkg/system"
 	"github.com/docker/docker/pkg/system"
@@ -117,6 +116,8 @@ func checkKernel() error {
 	return nil
 	return nil
 }
 }
 
 
+// adaptContainerSettings is called during container creation to modify any
+// settings necessary in the HostConfig structure.
 func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig) {
 func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig) {
 	if hostConfig == nil {
 	if hostConfig == nil {
 		return
 		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
 	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") {
 	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())
 		return warnings, fmt.Errorf("Cannot use --lxc-conf with execdriver: %s", daemon.ExecutionDriver().Name())
 	}
 	}

+ 5 - 3
daemon/daemon_windows.go

@@ -73,12 +73,14 @@ func checkKernel() error {
 	return nil
 	return nil
 }
 }
 
 
+// adaptContainerSettings is called during container creation to modify any
+// settings necessary in the HostConfig structure.
 func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig) {
 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
 	return nil, nil
 }
 }