null.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
  22. return nil, types.NotImplementedErrorf("not implemented")
  23. }
  24. func (d *driver) NetworkFree(id string) error {
  25. return types.NotImplementedErrorf("not implemented")
  26. }
  27. func (d *driver) CreateNetwork(id string, option map[string]interface{}, ipV4Data, ipV6Data []driverapi.IPAMData) error {
  28. d.Lock()
  29. defer d.Unlock()
  30. if d.network != "" {
  31. return types.ForbiddenErrorf("only one instance of \"%s\" network is allowed", networkType)
  32. }
  33. d.network = id
  34. return nil
  35. }
  36. func (d *driver) DeleteNetwork(nid string) error {
  37. return types.ForbiddenErrorf("network of type \"%s\" cannot be deleted", networkType)
  38. }
  39. func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
  40. return nil
  41. }
  42. func (d *driver) DeleteEndpoint(nid, eid string) error {
  43. return nil
  44. }
  45. func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
  46. return make(map[string]interface{}, 0), nil
  47. }
  48. // Join method is invoked when a Sandbox is attached to an endpoint.
  49. func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error {
  50. return nil
  51. }
  52. // Leave method is invoked when a Sandbox detaches from an endpoint.
  53. func (d *driver) Leave(nid, eid string) error {
  54. return nil
  55. }
  56. func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
  57. return nil
  58. }
  59. func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
  60. return nil
  61. }
  62. func (d *driver) Type() string {
  63. return networkType
  64. }
  65. // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
  66. func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
  67. return nil
  68. }
  69. // DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster
  70. func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
  71. return nil
  72. }