1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

chang the type of ports form PortBinding to TransportPort in link.go

Signed-off-by: Mingzhen Feng <fmzhen@zju.edu.cn>
This commit is contained in:
Mingzhen Feng 2015-05-05 10:46:18 +08:00 committed by Alessandro Boch
parent ac5e6d30ef
commit 8265de6325
3 changed files with 18 additions and 7 deletions

View file

@ -50,6 +50,7 @@ type Configuration struct {
type EndpointConfiguration struct { type EndpointConfiguration struct {
MacAddress net.HardwareAddr MacAddress net.HardwareAddr
PortBindings []netutils.PortBinding PortBindings []netutils.PortBinding
ExposedPorts []netutils.TransportPort
} }
// ContainerConfiguration represents the user specified configuration for a container // 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 return nil
} }
if endpoint.config != nil && endpoint.config.PortBindings != nil { if endpoint.config != nil && endpoint.config.ExposedPorts != nil {
for _, p := range cc.ParentEndpoints { for _, p := range cc.ParentEndpoints {
var parentEndpoint *bridgeEndpoint var parentEndpoint *bridgeEndpoint
parentEndpoint, err = network.getEndpoint(types.UUID(p)) 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(), l := newLink(parentEndpoint.intf.Address.IP.String(),
endpoint.intf.Address.IP.String(), endpoint.intf.Address.IP.String(),
endpoint.config.PortBindings, d.config.BridgeName) endpoint.config.ExposedPorts, d.config.BridgeName)
if enable { if enable {
err = l.Enable() err = l.Enable()
if err != nil { if err != nil {
@ -704,12 +705,12 @@ func (d *driver) link(nid, eid types.UUID, options map[string]interface{}, enabl
err = InvalidEndpointIDError(c) err = InvalidEndpointIDError(c)
return err return err
} }
if childEndpoint.config == nil || childEndpoint.config.PortBindings == nil { if childEndpoint.config == nil || childEndpoint.config.ExposedPorts == nil {
continue continue
} }
l := newLink(endpoint.intf.Address.IP.String(), l := newLink(endpoint.intf.Address.IP.String(),
childEndpoint.intf.Address.IP.String(), childEndpoint.intf.Address.IP.String(),
childEndpoint.config.PortBindings, d.config.BridgeName) childEndpoint.config.ExposedPorts, d.config.BridgeName)
if enable { if enable {
err = l.Enable() err = l.Enable()
if err != nil { 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 return ec, nil
} }

View file

@ -12,7 +12,7 @@ import (
type link struct { type link struct {
parentIP string parentIP string
childIP string childIP string
ports []netutils.PortBinding ports []netutils.TransportPort
bridge string 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) 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{ return &link{
childIP: childIP, childIP: childIP,
parentIP: parentIP, parentIP: parentIP,
@ -45,7 +45,7 @@ func (l *link) Disable() {
// that returns typed errors // 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 { ignoreErrors bool) error {
var nfAction iptables.Action var nfAction iptables.Action

View file

@ -14,6 +14,8 @@ const (
PortMap = "io.docker.network.endpoint.portmap" PortMap = "io.docker.network.endpoint.portmap"
// MacAddress constant represents Mac Address config of a Container // MacAddress constant represents Mac Address config of a Container
MacAddress = "io.docker.network.endpoint.macaddress" 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 // NoSuchFieldError is the error returned when the generic parameters hold a