host.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package host
  2. import (
  3. "sync"
  4. "github.com/docker/docker/libnetwork/datastore"
  5. "github.com/docker/docker/libnetwork/discoverapi"
  6. "github.com/docker/docker/libnetwork/driverapi"
  7. "github.com/docker/docker/libnetwork/types"
  8. )
  9. const networkType = "host"
  10. type driver struct {
  11. network string
  12. sync.Mutex
  13. }
  14. // Init registers a new instance of host driver.
  15. //
  16. // Deprecated: use [Register].
  17. func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
  18. return Register(dc, config)
  19. }
  20. func Register(r driverapi.Registerer, config map[string]interface{}) error {
  21. c := driverapi.Capability{
  22. DataScope: datastore.LocalScope,
  23. ConnectivityScope: datastore.LocalScope,
  24. }
  25. return r.RegisterDriver(networkType, &driver{}, c)
  26. }
  27. func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
  28. return nil, types.NotImplementedErrorf("not implemented")
  29. }
  30. func (d *driver) NetworkFree(id string) error {
  31. return types.NotImplementedErrorf("not implemented")
  32. }
  33. func (d *driver) EventNotify(etype driverapi.EventType, nid, tableName, key string, value []byte) {
  34. }
  35. func (d *driver) DecodeTableEntry(tablename string, key string, value []byte) (string, map[string]string) {
  36. return "", nil
  37. }
  38. func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
  39. d.Lock()
  40. defer d.Unlock()
  41. if d.network != "" {
  42. return types.ForbiddenErrorf("only one instance of \"%s\" network is allowed", networkType)
  43. }
  44. d.network = id
  45. return nil
  46. }
  47. func (d *driver) DeleteNetwork(nid string) error {
  48. return types.ForbiddenErrorf("network of type \"%s\" cannot be deleted", networkType)
  49. }
  50. func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
  51. return nil
  52. }
  53. func (d *driver) DeleteEndpoint(nid, eid string) error {
  54. return nil
  55. }
  56. func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
  57. return make(map[string]interface{}), nil
  58. }
  59. // Join method is invoked when a Sandbox is attached to an endpoint.
  60. func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error {
  61. return nil
  62. }
  63. // Leave method is invoked when a Sandbox detaches from an endpoint.
  64. func (d *driver) Leave(nid, eid string) error {
  65. return nil
  66. }
  67. func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error {
  68. return nil
  69. }
  70. func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
  71. return nil
  72. }
  73. func (d *driver) Type() string {
  74. return networkType
  75. }
  76. func (d *driver) IsBuiltIn() bool {
  77. return true
  78. }
  79. // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
  80. func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
  81. return nil
  82. }
  83. // DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster
  84. func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error {
  85. return nil
  86. }