null.go 2.1 KB

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