driverapi.go 5.0 KB

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