Skip to content

Commit

Permalink
Allow publishing of additional information to IPAM
Browse files Browse the repository at this point in the history
Adds an IPAM driver capability that allows libnetwork
to send additional information during subnet and address
allocation.

Signed-off-by: John Belamaric <[email protected]>
  • Loading branch information
johnbelamaric committed Feb 27, 2016
1 parent 9994ce1 commit d19315c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ipamapi/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@ type Ipam interface {

// Capability represents the requirements and capabilities of the IPAM driver
type Capability struct {
RequiresMACAddress bool
RequiresMACAddress bool
RequiresEndpointInfo bool
RequiresNetworkInfo bool
}
9 changes: 7 additions & 2 deletions ipams/remote/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ func (r *Response) GetError() string {
// GetCapabilityResponse is the response of GetCapability request
type GetCapabilityResponse struct {
Response
RequiresMACAddress bool
RequiresMACAddress bool
RequiresEndpointInfo bool
RequiresNetworkInfo bool
}

// ToCapability converts the capability response into the internal ipam driver capaility structure
func (capRes GetCapabilityResponse) ToCapability() *ipamapi.Capability {
return &ipamapi.Capability{RequiresMACAddress: capRes.RequiresMACAddress}
return &ipamapi.Capability{
RequiresMACAddress: capRes.RequiresMACAddress,
RequiresEndpointInfo: capRes.RequiresEndpointInfo,
RequiresNetworkInfo: capRes.RequiresNetworkInfo}
}

// GetAddressSpacesResponse is the response to the ``get default address spaces`` request message
Expand Down
15 changes: 15 additions & 0 deletions netlabel/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ const (
// MacAddress constant represents Mac Address config of a Container
MacAddress = Prefix + ".endpoint.macaddress"

// NetworkName constant represents the network name
NetworkName = Prefix + ".name"

// NetworkID constant represents the network ID
NetworkID = Prefix + ".id"

// NetworkType constant represents the network type/driver name
NetworkType = Prefix + ".type"

// EndpointName constant represents the endpoint/container name
EndpointName = Prefix + ".endpoint.name"

// EndpointHost constant represents the cluster host ID
EndpointHost = Prefix + ".endpoint.cluster_host_id"

// ExposedPorts constant represents the container's Exposed Ports
ExposedPorts = Prefix + ".endpoint.exposedports"

Expand Down
23 changes: 23 additions & 0 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,15 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoi
ep.ipamOptions[netlabel.MacAddress] = ep.iface.mac.String()
}

if ipam.capability.RequiresEndpointInfo {
if ep.ipamOptions == nil {
ep.ipamOptions = make(map[string]string)
}
log.Debugf("Endpoint: %s", ep)
ep.ipamOptions[netlabel.EndpointName] = name
ep.ipamOptions[netlabel.EndpointHost] = ep.locator
}

if err = ep.assignAddress(ipam.driver, true, !n.postIPv6); err != nil {
return nil, err
}
Expand Down Expand Up @@ -1009,6 +1018,20 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {

*infoList = make([]*IpamInfo, len(*cfgList))

id, err := n.getController().getIPAM(n.ipamType)
if err != nil {
return err
}

if id.capability.RequiresNetworkInfo {
if n.ipamOptions == nil {
n.ipamOptions = make(map[string]string)
}
n.ipamOptions[netlabel.NetworkName] = n.Name()
n.ipamOptions[netlabel.NetworkID] = n.ID()
n.ipamOptions[netlabel.NetworkType] = n.Type()
}

log.Debugf("Allocating IPv%d pools for network %s (%s)", ipVer, n.Name(), n.ID())

for i, cfg := range *cfgList {
Expand Down

0 comments on commit d19315c

Please sign in to comment.