host.go 2.9 KB

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