From 417093c3f5be52183e4d9a7207b9c9fa79ac2a3a Mon Sep 17 00:00:00 2001 From: Mingzhen Feng Date: Tue, 5 May 2015 10:46:18 +0800 Subject: [PATCH] chang the type of ports form PortBinding to TransportPort in link.go Signed-off-by: Mingzhen Feng --- drivers/bridge/bridge.go | 17 +++++++++++++---- drivers/bridge/link.go | 6 +++--- pkg/options/options.go | 2 ++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/bridge/bridge.go b/drivers/bridge/bridge.go index b307667..9461abc 100644 --- a/drivers/bridge/bridge.go +++ b/drivers/bridge/bridge.go @@ -50,6 +50,7 @@ type Configuration struct { type EndpointConfiguration struct { MacAddress net.HardwareAddr PortBindings []netutils.PortBinding + ExposedPorts []netutils.TransportPort } // ContainerConfiguration represents the user specified configuration for a container @@ -663,7 +664,7 @@ func (d *driver) link(nid, eid types.UUID, options map[string]interface{}, enabl return nil } - if endpoint.config != nil && endpoint.config.PortBindings != nil { + if endpoint.config != nil && endpoint.config.ExposedPorts != nil { for _, p := range cc.ParentEndpoints { var parentEndpoint *bridgeEndpoint parentEndpoint, err = network.getEndpoint(types.UUID(p)) @@ -677,7 +678,7 @@ func (d *driver) link(nid, eid types.UUID, options map[string]interface{}, enabl l := newLink(parentEndpoint.intf.Address.IP.String(), endpoint.intf.Address.IP.String(), - endpoint.config.PortBindings, d.config.BridgeName) + endpoint.config.ExposedPorts, d.config.BridgeName) if enable { err = l.Enable() if err != nil { @@ -704,12 +705,12 @@ func (d *driver) link(nid, eid types.UUID, options map[string]interface{}, enabl err = InvalidEndpointIDError(c) return err } - if childEndpoint.config == nil || childEndpoint.config.PortBindings == nil { + if childEndpoint.config == nil || childEndpoint.config.ExposedPorts == nil { continue } l := newLink(endpoint.intf.Address.IP.String(), childEndpoint.intf.Address.IP.String(), - childEndpoint.config.PortBindings, d.config.BridgeName) + childEndpoint.config.ExposedPorts, d.config.BridgeName) if enable { err = l.Enable() if err != nil { @@ -754,6 +755,14 @@ func parseEndpointOptions(epOptions map[string]interface{}) (*EndpointConfigurat } } + if opt, ok := epOptions[options.ExposedPorts]; ok { + if ports, ok := opt.([]netutils.TransportPort); ok { + ec.ExposedPorts = ports + } else { + return nil, ErrInvalidEndpointConfig + } + } + return ec, nil } diff --git a/drivers/bridge/link.go b/drivers/bridge/link.go index 774cd89..20ecca0 100644 --- a/drivers/bridge/link.go +++ b/drivers/bridge/link.go @@ -12,7 +12,7 @@ import ( type link struct { parentIP string childIP string - ports []netutils.PortBinding + ports []netutils.TransportPort bridge string } @@ -20,7 +20,7 @@ func (l *link) String() string { return fmt.Sprintf("%s <-> %s [%v] on %s", l.parentIP, l.childIP, l.ports, l.bridge) } -func newLink(parentIP, childIP string, ports []netutils.PortBinding, bridge string) *link { +func newLink(parentIP, childIP string, ports []netutils.TransportPort, bridge string) *link { return &link{ childIP: childIP, parentIP: parentIP, @@ -45,7 +45,7 @@ func (l *link) Disable() { // that returns typed errors } -func linkContainers(action, parentIP, childIP string, ports []netutils.PortBinding, bridge string, +func linkContainers(action, parentIP, childIP string, ports []netutils.TransportPort, bridge string, ignoreErrors bool) error { var nfAction iptables.Action diff --git a/pkg/options/options.go b/pkg/options/options.go index 846d1ea..673da56 100644 --- a/pkg/options/options.go +++ b/pkg/options/options.go @@ -14,6 +14,8 @@ const ( PortMap = "io.docker.network.endpoint.portmap" // MacAddress constant represents Mac Address config of a Container MacAddress = "io.docker.network.endpoint.macaddress" + // ExposedPorts constant represents exposedports of a Container + ExposedPorts = "io.docker.network.endpoint.exposedports" ) // NoSuchFieldError is the error returned when the generic parameters hold a