driverapi.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package driverapi
  2. import (
  3. "net"
  4. "github.com/docker/libnetwork/datastore"
  5. )
  6. // NetworkPluginEndpointType represents the Endpoint Type used by Plugin system
  7. const NetworkPluginEndpointType = "NetworkDriver"
  8. // Driver is an interface that every plugin driver needs to implement.
  9. type Driver interface {
  10. // CreateNetwork invokes the driver method to create a network passing
  11. // the network id and network specific config. The config mechanism will
  12. // eventually be replaced with labels which are yet to be introduced.
  13. CreateNetwork(nid string, options map[string]interface{}) error
  14. // DeleteNetwork invokes the driver method to delete network passing
  15. // the network id.
  16. DeleteNetwork(nid string) error
  17. // CreateEndpoint invokes the driver method to create an endpoint
  18. // passing the network id, endpoint id endpoint information and driver
  19. // specific config. The endpoint information can be either consumed by
  20. // the driver or populated by the driver. The config mechanism will
  21. // eventually be replaced with labels which are yet to be introduced.
  22. CreateEndpoint(nid, eid string, epInfo EndpointInfo, options map[string]interface{}) error
  23. // DeleteEndpoint invokes the driver method to delete an endpoint
  24. // passing the network id and endpoint id.
  25. DeleteEndpoint(nid, eid string) error
  26. // EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint
  27. EndpointOperInfo(nid, eid string) (map[string]interface{}, error)
  28. // Join method is invoked when a Sandbox is attached to an endpoint.
  29. Join(nid, eid string, sboxKey string, jinfo JoinInfo, options map[string]interface{}) error
  30. // Leave method is invoked when a Sandbox detaches from an endpoint.
  31. Leave(nid, eid string) error
  32. // DiscoverNew is a notification for a new discovery event, Example:a new node joining a cluster
  33. DiscoverNew(dType DiscoveryType, data interface{}) error
  34. // DiscoverDelete is a notification for a discovery delete event, Example:a node leaving a cluster
  35. DiscoverDelete(dType DiscoveryType, data interface{}) error
  36. // Type returns the the type of this driver, the network type this driver manages
  37. Type() string
  38. }
  39. // EndpointInfo provides a go interface to fetch or populate endpoint assigned network resources.
  40. type EndpointInfo interface {
  41. // Interface returns the interface bound to the endpoint.
  42. // If the value is not nil the driver is only expected to consume the interface.
  43. // It is an error to try to add interface if the passed down value is non-nil
  44. // If the value is nil the driver is expected to add an interface
  45. Interface() InterfaceInfo
  46. // AddInterface is used by the driver to add an interface for the endpoint.
  47. // This method will return an error if the driver attempts to add interface
  48. // if the Interface() method returned a non-nil value.
  49. AddInterface(mac net.HardwareAddr, ipv4 net.IPNet, ipv6 net.IPNet) error
  50. }
  51. // InterfaceInfo provides a go interface for drivers to retrive
  52. // network information to interface resources.
  53. type InterfaceInfo interface {
  54. // MacAddress returns the MAC address.
  55. MacAddress() net.HardwareAddr
  56. // Address returns the IPv4 address.
  57. Address() net.IPNet
  58. // AddressIPv6 returns the IPv6 address.
  59. AddressIPv6() net.IPNet
  60. }
  61. // InterfaceNameInfo provides a go interface for the drivers to assign names
  62. // to interfaces.
  63. type InterfaceNameInfo interface {
  64. // SetNames method assigns the srcName and dstPrefix for the interface.
  65. SetNames(srcName, dstPrefix string) error
  66. }
  67. // JoinInfo represents a set of resources that the driver has the ability to provide during
  68. // join time.
  69. type JoinInfo interface {
  70. // InterfaceName returns a InterfaceNameInfo go interface to facilitate
  71. // setting the names for the interface.
  72. InterfaceName() InterfaceNameInfo
  73. // SetGateway sets the default IPv4 gateway when a container joins the endpoint.
  74. SetGateway(net.IP) error
  75. // SetGatewayIPv6 sets the default IPv6 gateway when a container joins the endpoint.
  76. SetGatewayIPv6(net.IP) error
  77. // AddStaticRoute adds a routes to the sandbox.
  78. // It may be used in addtion to or instead of a default gateway (as above).
  79. AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error
  80. }
  81. // DriverCallback provides a Callback interface for Drivers into LibNetwork
  82. type DriverCallback interface {
  83. // RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
  84. RegisterDriver(name string, driver Driver, capability Capability) error
  85. }
  86. // Capability represents the high level capabilities of the drivers which libnetwork can make use of
  87. type Capability struct {
  88. DataScope datastore.DataScope
  89. }
  90. // DiscoveryType represents the type of discovery element the DiscoverNew function is invoked on
  91. type DiscoveryType int
  92. const (
  93. // NodeDiscovery represents Node join/leave events provided by discovery
  94. NodeDiscovery = iota + 1
  95. )
  96. // NodeDiscoveryData represents the structure backing the node discovery data json string
  97. type NodeDiscoveryData struct {
  98. Address string
  99. Self bool
  100. }