Skip to content

Commit

Permalink
Merge pull request #707 from rmb938/ipam_allocate_options
Browse files Browse the repository at this point in the history
Assigning Address driver options
  • Loading branch information
aboch committed Dec 4, 2015
2 parents e31b676 + 35f1a1f commit 077b076
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type endpoint struct {
anonymous bool
generic map[string]interface{}
joinLeaveDone chan struct{}
prefAddress net.IP
ipamOptions map[string]string
dbIndex uint64
dbExists bool
sync.Mutex
Expand Down Expand Up @@ -685,6 +687,14 @@ func EndpointOptionGeneric(generic map[string]interface{}) EndpointOption {
}
}

// CreateOptionIpam function returns an option setter for the ipam configuration for this endpoint
func CreateOptionIpam(prefAddress net.IP, ipamOptions map[string]string) EndpointOption {
return func(ep *endpoint) {
ep.prefAddress = prefAddress
ep.ipamOptions = ipamOptions
}
}

// CreateOptionExposedPorts function returns an option setter for the container exposed
// ports option to be passed to network.CreateEndpoint() method.
func CreateOptionExposedPorts(exposedPorts []types.TransportPort) EndpointOption {
Expand Down Expand Up @@ -799,7 +809,7 @@ func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
if *address != nil {
prefIP = (*address).IP
}
addr, _, err := ipam.RequestAddress(d.PoolID, prefIP, nil)
addr, _, err := ipam.RequestAddress(d.PoolID, prefIP, ep.ipamOptions)
if err == nil {
ep.Lock()
*address = addr
Expand Down
2 changes: 2 additions & 0 deletions ipamapi/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
DefaultIPAM = "default"
// PluginEndpointType represents the Endpoint Type used by Plugin system
PluginEndpointType = "IpamDriver"
// RequestAddressType represents the Address Type used when requesting an address
RequestAddressType = "RequestAddressType"
)

// Callback provides a Callback interface for registering an IPAM instance into LibNetwork
Expand Down
5 changes: 4 additions & 1 deletion network.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,10 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
// irrespective of whether ipam driver returned a gateway already.
// If none of the above is true, libnetwork will allocate one.
if cfg.Gateway != "" || d.Gateway == nil {
if d.Gateway, _, err = ipam.RequestAddress(d.PoolID, net.ParseIP(cfg.Gateway), nil); err != nil {
var gatewayOpts = map[string]string{
ipamapi.RequestAddressType: netlabel.Gateway,
}
if d.Gateway, _, err = ipam.RequestAddress(d.PoolID, net.ParseIP(cfg.Gateway), gatewayOpts); err != nil {
return types.InternalErrorf("failed to allocate gateway (%v): %v", cfg.Gateway, err)
}
}
Expand Down

0 comments on commit 077b076

Please sign in to comment.