null.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package null
  2. import (
  3. "sync"
  4. "github.com/docker/libnetwork/datastore"
  5. "github.com/docker/libnetwork/driverapi"
  6. "github.com/docker/libnetwork/types"
  7. )
  8. const networkType = "null"
  9. type driver struct {
  10. network string
  11. sync.Mutex
  12. }
  13. // Init registers a new instance of null driver
  14. func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
  15. c := driverapi.Capability{
  16. DataScope: datastore.LocalScope,
  17. }
  18. return dc.RegisterDriver(networkType, &driver{}, c)
  19. }
  20. func (d *driver) CreateNetwork(id string, option map[string]interface{}, ipV4Data, ipV6Data []driverapi.IPAMData) error {
  21. d.Lock()
  22. defer d.Unlock()
  23. if d.network != "" {
  24. return types.ForbiddenErrorf("only one instance of \"%s\" network is allowed", networkType)
  25. }
  26. d.network = id
  27. return nil
  28. }
  29. func (d *driver) DeleteNetwork(nid string) error {
  30. return types.ForbiddenErrorf("network of type \"%s\" cannot be deleted", networkType)
  31. }
  32. func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
  33. return nil
  34. }
  35. func (d *driver) DeleteEndpoint(nid, eid string) error {
  36. return nil
  37. }
  38. func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
  39. return make(map[string]interface{}, 0), nil
  40. }
  41. // Join method is invoked when a Sandbox is attached to an endpoint.
  42. func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error {
  43. return nil
  44. }
  45. // Leave method is invoked when a Sandbox detaches from an endpoint.
  46. func (d *driver) Leave(nid, eid string) error {
  47. return nil
  48. }
  49. func (d *driver) Type() string {
  50. return networkType
  51. }
  52. // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
  53. func (d *driver) DiscoverNew(dType driverapi.DiscoveryType, data interface{}) error {
  54. return nil
  55. }
  56. // DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster
  57. func (d *driver) DiscoverDelete(dType driverapi.DiscoveryType, data interface{}) error {
  58. return nil
  59. }