driverapi.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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{}, ipV4Data, ipV6Data []IPAMData) 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, ifInfo InterfaceInfo, 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. // InterfaceInfo provides a go interface for drivers to retrive
  40. // network information to interface resources.
  41. type InterfaceInfo interface {
  42. // SetMacAddress allows the driver to set the mac address to the endpoint interface
  43. // during the call to CreateEndpoint, if the mac address is not already set.
  44. SetMacAddress(mac net.HardwareAddr) error
  45. // SetIPAddress allows the driver to set the ip address to the endpoint interface
  46. // during the call to CreateEndpoint, if the address is not already set.
  47. // The API is to be used to assign both the IPv4 and IPv6 address types.
  48. SetIPAddress(ip *net.IPNet) error
  49. // MacAddress returns the MAC address.
  50. MacAddress() net.HardwareAddr
  51. // Address returns the IPv4 address.
  52. Address() *net.IPNet
  53. // AddressIPv6 returns the IPv6 address.
  54. AddressIPv6() *net.IPNet
  55. }
  56. // InterfaceNameInfo provides a go interface for the drivers to assign names
  57. // to interfaces.
  58. type InterfaceNameInfo interface {
  59. // SetNames method assigns the srcName and dstPrefix for the interface.
  60. SetNames(srcName, dstPrefix string) error
  61. }
  62. // JoinInfo represents a set of resources that the driver has the ability to provide during
  63. // join time.
  64. type JoinInfo interface {
  65. // InterfaceName returns a InterfaceNameInfo go interface to facilitate
  66. // setting the names for the interface.
  67. InterfaceName() InterfaceNameInfo
  68. // SetGateway sets the default IPv4 gateway when a container joins the endpoint.
  69. SetGateway(net.IP) error
  70. // SetGatewayIPv6 sets the default IPv6 gateway when a container joins the endpoint.
  71. SetGatewayIPv6(net.IP) error
  72. // AddStaticRoute adds a routes to the sandbox.
  73. // It may be used in addtion to or instead of a default gateway (as above).
  74. AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error
  75. }
  76. // DriverCallback provides a Callback interface for Drivers into LibNetwork
  77. type DriverCallback interface {
  78. // RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
  79. RegisterDriver(name string, driver Driver, capability Capability) error
  80. }
  81. // Capability represents the high level capabilities of the drivers which libnetwork can make use of
  82. type Capability struct {
  83. DataScope datastore.DataScope
  84. }
  85. // DiscoveryType represents the type of discovery element the DiscoverNew function is invoked on
  86. type DiscoveryType int
  87. const (
  88. // NodeDiscovery represents Node join/leave events provided by discovery
  89. NodeDiscovery = iota + 1
  90. )
  91. // NodeDiscoveryData represents the structure backing the node discovery data json string
  92. type NodeDiscoveryData struct {
  93. Address string
  94. Self bool
  95. }
  96. // IPAMData represents the per-network ip related
  97. // operational information libnetwork will send
  98. // to the network driver during CreateNetwork()
  99. type IPAMData struct {
  100. AddressSpace string
  101. Pool *net.IPNet
  102. Gateway *net.IPNet
  103. AuxAddresses map[string]*net.IPNet
  104. }