소스 검색

Merge pull request #14604 from Microsoft/10662-addbridge

Windows: Plumb through -b on daemon
Alexander Morozov 10 년 전
부모
커밋
97515a35ca
6개의 변경된 파일22개의 추가작업 그리고 17개의 파일을 삭제
  1. 1 0
      daemon/config.go
  2. 0 2
      daemon/config_linux.go
  3. 10 2
      daemon/config_windows.go
  4. 1 8
      daemon/container_windows.go
  5. 6 1
      daemon/daemon_windows.go
  6. 4 4
      daemon/execdriver/windows/run.go

+ 1 - 0
daemon/config.go

@@ -15,6 +15,7 @@ const (
 // common across platforms.
 type CommonConfig struct {
 	AutoRestart    bool
+	Bridge         bridgeConfig // Bridge holds bridge network specific configuration.
 	Context        map[string][]string
 	CorsHeaders    string
 	DisableBridge  bool

+ 0 - 2
daemon/config_linux.go

@@ -22,8 +22,6 @@ type Config struct {
 
 	// Fields below here are platform specific.
 
-	// Bridge holds bridge network specific configuration.
-	Bridge               bridgeConfig
 	EnableSelinuxSupport bool
 	SocketGroup          string
 	Ulimits              map[string]*ulimit.Ulimit

+ 10 - 2
daemon/config_windows.go

@@ -2,6 +2,8 @@ package daemon
 
 import (
 	"os"
+
+	flag "github.com/docker/docker/pkg/mflag"
 )
 
 var (
@@ -10,6 +12,12 @@ var (
 	defaultExec    = "windows"
 )
 
+// bridgeConfig stores all the bridge driver specific
+// configuration.
+type bridgeConfig struct {
+	VirtualSwitchName string
+}
+
 // Config defines the configuration of a docker daemon.
 // These are the configuration settings that you pass
 // to the docker daemon when you launch it with say: `docker -d -e windows`
@@ -28,6 +36,6 @@ func (config *Config) InstallFlags() {
 	// First handle install flags which are consistent cross-platform
 	config.InstallCommonFlags()
 
-	// Then platform-specific install flags. There are none presently on Windows
-
+	// Then platform-specific install flags.
+	flag.StringVar(&config.Bridge.VirtualSwitchName, []string{"b", "-bridge"}, "", "Attach containers to a virtual switch")
 }

+ 1 - 8
daemon/container_windows.go

@@ -80,6 +80,7 @@ func populateCommand(c *Container, env []string) error {
 			network := c.NetworkSettings
 			en.Interface = &execdriver.NetworkInterface{
 				MacAddress: network.MacAddress,
+				Bridge:     c.daemon.config.Bridge.VirtualSwitchName,
 			}
 		}
 	default:
@@ -156,12 +157,6 @@ func (container *Container) GetSize() (int64, int64) {
 }
 
 func (container *Container) AllocateNetwork() error {
-
-	// TODO Windows. This needs reworking with libnetwork. In the
-	// proof-of-concept for //build conference, the Windows daemon
-	// invoked eng.Job("allocate_interface) passing through
-	// RequestedMac.
-
 	return nil
 }
 
@@ -174,11 +169,9 @@ func (container *Container) ExportRw() (archive.Archive, error) {
 }
 
 func (container *Container) ReleaseNetwork() {
-	// TODO Windows. Rework with libnetwork
 }
 
 func (container *Container) RestoreNetwork() error {
-	// TODO Windows. Rework with libnetwork
 	return nil
 }
 

+ 6 - 1
daemon/daemon_windows.go

@@ -15,6 +15,8 @@ import (
 	"github.com/microsoft/hcsshim"
 )
 
+const DefaultVirtualSwitch = "Virtual Switch"
+
 func (daemon *Daemon) Changes(container *Container) ([]archive.Change, error) {
 	return daemon.driver.Changes(container.ID, container.ImageID)
 }
@@ -125,7 +127,10 @@ func isBridgeNetworkDisabled(config *Config) bool {
 }
 
 func initNetworkController(config *Config) (libnetwork.NetworkController, error) {
-	// TODO Windows
+	// Set the name of the virtual switch if not specified by -b on daemon start
+	if config.Bridge.VirtualSwitchName == "" {
+		config.Bridge.VirtualSwitchName = DefaultVirtualSwitch
+	}
 	return nil, nil
 }
 

+ 4 - 4
daemon/execdriver/windows/run.go

@@ -81,10 +81,6 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
 	}
 
 	if c.Network.Interface != nil {
-
-		// TODO Windows: Temporary
-		c.Network.Interface.Bridge = "Virtual Switch"
-
 		dev := device{
 			DeviceType: "Network",
 			Connection: &networkConnection{
@@ -101,7 +97,11 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
 			}
 		}
 
+		logrus.Debugf("Virtual switch '%s', mac='%s'", c.Network.Interface.Bridge, c.Network.Interface.MacAddress)
+
 		cu.Devices = append(cu.Devices, dev)
+	} else {
+		logrus.Debugln("No network interface")
 	}
 
 	configurationb, err := json.Marshal(cu)