null.go 2.9 KB

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