null.go 2.7 KB

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