From e0ec0cc115a7b271defc7ab5680eb6836ef71c7a Mon Sep 17 00:00:00 2001 From: John Howard Date: Mon, 13 Jul 2015 12:34:58 -0700 Subject: [PATCH] Windows: Plumb through -b on daemon Signed-off-by: John Howard --- daemon/config.go | 1 + daemon/config_linux.go | 2 -- daemon/config_windows.go | 12 ++++++++++-- daemon/container_windows.go | 9 +-------- daemon/daemon_windows.go | 7 ++++++- daemon/execdriver/windows/run.go | 8 ++++---- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/daemon/config.go b/daemon/config.go index fbb05c3ac4..fe6dd5d06f 100644 --- a/daemon/config.go +++ b/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 diff --git a/daemon/config_linux.go b/daemon/config_linux.go index 46bcef31de..e1095e078c 100644 --- a/daemon/config_linux.go +++ b/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 diff --git a/daemon/config_windows.go b/daemon/config_windows.go index 4731767a7a..26bb8a7775 100644 --- a/daemon/config_windows.go +++ b/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") } diff --git a/daemon/container_windows.go b/daemon/container_windows.go index 718ca47ff5..bb72a3c675 100644 --- a/daemon/container_windows.go +++ b/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 } diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index 551c6c015c..3e160775b4 100644 --- a/daemon/daemon_windows.go +++ b/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 } diff --git a/daemon/execdriver/windows/run.go b/daemon/execdriver/windows/run.go index 930762e879..88eaa7f696 100644 --- a/daemon/execdriver/windows/run.go +++ b/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)