driverapi.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package driverapi
  2. import (
  3. "net"
  4. "github.com/docker/libnetwork/discoverapi"
  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. discoverapi.Discover
  11. // CreateNetwork invokes the driver method to create a network passing
  12. // the network id and network specific config. The config mechanism will
  13. // eventually be replaced with labels which are yet to be introduced.
  14. CreateNetwork(nid string, options map[string]interface{}, ipV4Data, ipV6Data []IPAMData) error
  15. // DeleteNetwork invokes the driver method to delete network passing
  16. // the network id.
  17. DeleteNetwork(nid string) error
  18. // CreateEndpoint invokes the driver method to create an endpoint
  19. // passing the network id, endpoint id endpoint information and driver
  20. // specific config. The endpoint information can be either consumed by
  21. // the driver or populated by the driver. The config mechanism will
  22. // eventually be replaced with labels which are yet to be introduced.
  23. CreateEndpoint(nid, eid string, ifInfo InterfaceInfo, options map[string]interface{}) error
  24. // DeleteEndpoint invokes the driver method to delete an endpoint
  25. // passing the network id and endpoint id.
  26. DeleteEndpoint(nid, eid string) error
  27. // EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint
  28. EndpointOperInfo(nid, eid string) (map[string]interface{}, error)
  29. // Join method is invoked when a Sandbox is attached to an endpoint.
  30. Join(nid, eid string, sboxKey string, jinfo JoinInfo, options map[string]interface{}) error
  31. // Leave method is invoked when a Sandbox detaches from an endpoint.
  32. Leave(nid, eid string) 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 route to the sandbox.
  70. // It may be used in addition 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. // IPAMData represents the per-network ip related
  85. // operational information libnetwork will send
  86. // to the network driver during CreateNetwork()
  87. type IPAMData struct {
  88. AddressSpace string
  89. Pool *net.IPNet
  90. Gateway *net.IPNet
  91. AuxAddresses map[string]*net.IPNet
  92. }