Support driver labels
Add support for in-tree driver configuration labels by pushing the labels which has the appropriate prefix to the corresponding driver. Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
parent
ec68d342d1
commit
421ef35df2
|
@ -2,51 +2,52 @@
|
||||||
Package libnetwork provides the basic functionality and extension points to
|
Package libnetwork provides the basic functionality and extension points to
|
||||||
create network namespaces and allocate interfaces for containers to use.
|
create network namespaces and allocate interfaces for containers to use.
|
||||||
|
|
||||||
// Create a new controller instance
|
// Create a new controller instance
|
||||||
controller, _err := libnetwork.New(nil)
|
controller, _err := libnetwork.New(nil)
|
||||||
|
|
||||||
// Select and configure the network driver
|
// Select and configure the network driver
|
||||||
networkType := "bridge"
|
networkType := "bridge"
|
||||||
|
|
||||||
driverOptions := options.Generic{}
|
driverOptions := options.Generic{}
|
||||||
genericOption := make(map[string]interface{})
|
genericOption := make(map[string]interface{})
|
||||||
genericOption[netlabel.GenericData] = driverOptions
|
genericOption[netlabel.GenericData] = driverOptions
|
||||||
err := controller.ConfigureNetworkDriver(networkType, genericOption)
|
err := controller.ConfigureNetworkDriver(networkType, genericOption)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a network for containers to join.
|
// Create a network for containers to join.
|
||||||
// NewNetwork accepts Variadic optional arguments that libnetwork and Drivers can make of
|
// NewNetwork accepts Variadic optional arguments that libnetwork and Drivers can make of
|
||||||
network, err := controller.NewNetwork(networkType, "network1")
|
network, err := controller.NewNetwork(networkType, "network1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// For each new container: allocate IP and interfaces. The returned network
|
// For each new container: allocate IP and interfaces. The returned network
|
||||||
// settings will be used for container infos (inspect and such), as well as
|
// settings will be used for container infos (inspect and such), as well as
|
||||||
// iptables rules for port publishing. This info is contained or accessible
|
// iptables rules for port publishing. This info is contained or accessible
|
||||||
// from the returned endpoint.
|
// from the returned endpoint.
|
||||||
ep, err := network.CreateEndpoint("Endpoint1")
|
ep, err := network.CreateEndpoint("Endpoint1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// A container can join the endpoint by providing the container ID to the join
|
// A container can join the endpoint by providing the container ID to the join
|
||||||
// api.
|
// api.
|
||||||
// Join acceps Variadic arguments which will be made use of by libnetwork and Drivers
|
// Join acceps Variadic arguments which will be made use of by libnetwork and Drivers
|
||||||
err = ep.Join("container1",
|
err = ep.Join("container1",
|
||||||
libnetwork.JoinOptionHostname("test"),
|
libnetwork.JoinOptionHostname("test"),
|
||||||
libnetwork.JoinOptionDomainname("docker.io"))
|
libnetwork.JoinOptionDomainname("docker.io"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
package libnetwork
|
package libnetwork
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
@ -56,6 +57,7 @@ import (
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
"github.com/docker/libnetwork/driverapi"
|
"github.com/docker/libnetwork/driverapi"
|
||||||
"github.com/docker/libnetwork/hostdiscovery"
|
"github.com/docker/libnetwork/hostdiscovery"
|
||||||
|
"github.com/docker/libnetwork/netlabel"
|
||||||
"github.com/docker/libnetwork/sandbox"
|
"github.com/docker/libnetwork/sandbox"
|
||||||
"github.com/docker/libnetwork/types"
|
"github.com/docker/libnetwork/types"
|
||||||
)
|
)
|
||||||
|
@ -187,14 +189,41 @@ func (c *controller) ConfigureNetworkDriver(networkType string, options map[stri
|
||||||
|
|
||||||
func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
|
func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver, capability driverapi.Capability) error {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
|
||||||
if !config.IsValidName(networkType) {
|
if !config.IsValidName(networkType) {
|
||||||
|
c.Unlock()
|
||||||
return ErrInvalidName(networkType)
|
return ErrInvalidName(networkType)
|
||||||
}
|
}
|
||||||
if _, ok := c.drivers[networkType]; ok {
|
if _, ok := c.drivers[networkType]; ok {
|
||||||
|
c.Unlock()
|
||||||
return driverapi.ErrActiveRegistration(networkType)
|
return driverapi.ErrActiveRegistration(networkType)
|
||||||
}
|
}
|
||||||
c.drivers[networkType] = &driverData{driver, capability}
|
c.drivers[networkType] = &driverData{driver, capability}
|
||||||
|
|
||||||
|
if c.cfg == nil {
|
||||||
|
c.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
opt := make(map[string]interface{})
|
||||||
|
for _, label := range c.cfg.Daemon.Labels {
|
||||||
|
if strings.HasPrefix(label, netlabel.DriverPrefix+"."+networkType) {
|
||||||
|
opt[netlabel.Key(label)] = netlabel.Value(label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if capability.Scope == driverapi.GlobalScope {
|
||||||
|
opt[netlabel.KVProvider] = c.cfg.Datastore.Client.Provider
|
||||||
|
opt[netlabel.KVProviderURL] = c.cfg.Datastore.Client.Address
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Unlock()
|
||||||
|
|
||||||
|
if len(opt) != 0 {
|
||||||
|
if err := driver.Config(opt); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue