2015-04-30 01:56:59 -04:00
|
|
|
package null
|
|
|
|
|
|
|
|
import (
|
2015-06-08 11:24:43 -04:00
|
|
|
"sync"
|
|
|
|
|
2015-04-30 01:56:59 -04:00
|
|
|
"github.com/docker/libnetwork/driverapi"
|
|
|
|
"github.com/docker/libnetwork/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
const networkType = "null"
|
|
|
|
|
2015-06-08 11:24:43 -04:00
|
|
|
type driver struct {
|
|
|
|
network types.UUID
|
|
|
|
sync.Mutex
|
|
|
|
}
|
2015-04-30 01:56:59 -04:00
|
|
|
|
Make driver packages register themselves via DriverCallback
In the present code, each driver package provides a `New()` method
which constructs a driver of its type, which is then registered with
the controller.
However, this is not suitable for the `drivers/remote` package, since
it does not provide a (singleton) driver, but a mechanism for drivers
to be added dynamically. As a result, the implementation is oddly
dual-purpose, and a spurious `"remote"` driver is added to the
controller's list of available drivers.
Instead, it is better to provide the registration callback to each
package and let it register its own driver or drivers. That way, the
singleton driver packages can construct one and register it, and the
remote package can hook the callback up with whatever the dynamic
driver mechanism turns out to be.
NB there are some method signature changes; in particular to
controller.New, which can return an error if the built-in driver
packages fail to initialise.
Signed-off-by: Michael Bridgen <mikeb@squaremobius.net>
2015-05-11 08:46:29 -04:00
|
|
|
// Init registers a new instance of null driver
|
|
|
|
func Init(dc driverapi.DriverCallback) error {
|
|
|
|
return dc.RegisterDriver(networkType, &driver{})
|
2015-04-30 01:56:59 -04:00
|
|
|
}
|
|
|
|
|
2015-04-30 20:57:06 -04:00
|
|
|
func (d *driver) Config(option map[string]interface{}) error {
|
2015-04-30 01:56:59 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-30 20:57:06 -04:00
|
|
|
func (d *driver) CreateNetwork(id types.UUID, option map[string]interface{}) error {
|
2015-06-08 11:24:43 -04:00
|
|
|
d.Lock()
|
|
|
|
defer d.Unlock()
|
|
|
|
|
|
|
|
if d.network != "" {
|
|
|
|
return types.ForbiddenErrorf("only one instance of \"%s\" network is allowed", networkType)
|
|
|
|
}
|
|
|
|
|
|
|
|
d.network = id
|
|
|
|
|
2015-04-30 01:56:59 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) DeleteNetwork(nid types.UUID) error {
|
2015-06-08 11:24:43 -04:00
|
|
|
return types.ForbiddenErrorf("network of type \"%s\" cannot be deleted", networkType)
|
2015-04-30 01:56:59 -04:00
|
|
|
}
|
|
|
|
|
2015-05-14 02:23:45 -04:00
|
|
|
func (d *driver) CreateEndpoint(nid, eid types.UUID, epInfo driverapi.EndpointInfo, epOptions map[string]interface{}) error {
|
|
|
|
return nil
|
2015-04-30 01:56:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *driver) DeleteEndpoint(nid, eid types.UUID) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-05-14 02:23:45 -04:00
|
|
|
func (d *driver) EndpointOperInfo(nid, eid types.UUID) (map[string]interface{}, error) {
|
2015-05-04 14:49:53 -04:00
|
|
|
return make(map[string]interface{}, 0), nil
|
|
|
|
}
|
|
|
|
|
2015-04-30 17:52:46 -04:00
|
|
|
// Join method is invoked when a Sandbox is attached to an endpoint.
|
2015-05-14 02:23:45 -04:00
|
|
|
func (d *driver) Join(nid, eid types.UUID, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error {
|
|
|
|
return nil
|
2015-04-30 17:52:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Leave method is invoked when a Sandbox detaches from an endpoint.
|
2015-05-14 02:23:45 -04:00
|
|
|
func (d *driver) Leave(nid, eid types.UUID) error {
|
2015-04-30 17:52:46 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-30 01:56:59 -04:00
|
|
|
func (d *driver) Type() string {
|
|
|
|
return networkType
|
|
|
|
}
|