driverapi.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. // NetworkAllocate invokes the driver method to allocate network
  12. // specific resources passing network id and network specific config.
  13. // It returns a key,value pair of network specific driver allocations
  14. // to the caller.
  15. NetworkAllocate(nid string, options map[string]string, ipV4Data, ipV6Data []IPAMData) (map[string]string, error)
  16. // NetworkFree invokes the driver method to free network specific resources
  17. // associated with a given network id.
  18. NetworkFree(nid string) error
  19. // CreateNetwork invokes the driver method to create a network passing
  20. // the network id and network specific config. The config mechanism will
  21. // eventually be replaced with labels which are yet to be introduced.
  22. CreateNetwork(nid string, options map[string]interface{}, ipV4Data, ipV6Data []IPAMData) error
  23. // DeleteNetwork invokes the driver method to delete network passing
  24. // the network id.
  25. DeleteNetwork(nid string) error
  26. // CreateEndpoint invokes the driver method to create an endpoint
  27. // passing the network id, endpoint id endpoint information and driver
  28. // specific config. The endpoint information can be either consumed by
  29. // the driver or populated by the driver. The config mechanism will
  30. // eventually be replaced with labels which are yet to be introduced.
  31. CreateEndpoint(nid, eid string, ifInfo InterfaceInfo, options map[string]interface{}) error
  32. // DeleteEndpoint invokes the driver method to delete an endpoint
  33. // passing the network id and endpoint id.
  34. DeleteEndpoint(nid, eid string) error
  35. // EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint
  36. EndpointOperInfo(nid, eid string) (map[string]interface{}, error)
  37. // Join method is invoked when a Sandbox is attached to an endpoint.
  38. Join(nid, eid string, sboxKey string, jinfo JoinInfo, options map[string]interface{}) error
  39. // Leave method is invoked when a Sandbox detaches from an endpoint.
  40. Leave(nid, eid string) error
  41. // ProgramExternalConnectivity invokes the driver method which does the necessary
  42. // programming to allow the external connectivity dictated by the passed options
  43. ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error
  44. // RevokeExternalConnectivity aks the driver to remove any external connectivity
  45. // programming that was done so far
  46. RevokeExternalConnectivity(nid, eid string) error
  47. // Type returns the the type of this driver, the network type this driver manages
  48. Type() string
  49. }
  50. // InterfaceInfo provides a go interface for drivers to retrive
  51. // network information to interface resources.
  52. type InterfaceInfo interface {
  53. // SetMacAddress allows the driver to set the mac address to the endpoint interface
  54. // during the call to CreateEndpoint, if the mac address is not already set.
  55. SetMacAddress(mac net.HardwareAddr) error
  56. // SetIPAddress allows the driver to set the ip address to the endpoint interface
  57. // during the call to CreateEndpoint, if the address is not already set.
  58. // The API is to be used to assign both the IPv4 and IPv6 address types.
  59. SetIPAddress(ip *net.IPNet) error
  60. // MacAddress returns the MAC address.
  61. MacAddress() net.HardwareAddr
  62. // Address returns the IPv4 address.
  63. Address() *net.IPNet
  64. // AddressIPv6 returns the IPv6 address.
  65. AddressIPv6() *net.IPNet
  66. }
  67. // InterfaceNameInfo provides a go interface for the drivers to assign names
  68. // to interfaces.
  69. type InterfaceNameInfo interface {
  70. // SetNames method assigns the srcName and dstPrefix for the interface.
  71. SetNames(srcName, dstPrefix string) error
  72. }
  73. // JoinInfo represents a set of resources that the driver has the ability to provide during
  74. // join time.
  75. type JoinInfo interface {
  76. // InterfaceName returns a InterfaceNameInfo go interface to facilitate
  77. // setting the names for the interface.
  78. InterfaceName() InterfaceNameInfo
  79. // SetGateway sets the default IPv4 gateway when a container joins the endpoint.
  80. SetGateway(net.IP) error
  81. // SetGatewayIPv6 sets the default IPv6 gateway when a container joins the endpoint.
  82. SetGatewayIPv6(net.IP) error
  83. // AddStaticRoute adds a route to the sandbox.
  84. // It may be used in addition to or instead of a default gateway (as above).
  85. AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error
  86. // DisableGatewayService tells libnetwork not to provide Default GW for the container
  87. DisableGatewayService()
  88. }
  89. // DriverCallback provides a Callback interface for Drivers into LibNetwork
  90. type DriverCallback interface {
  91. // RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
  92. RegisterDriver(name string, driver Driver, capability Capability) error
  93. }
  94. // Capability represents the high level capabilities of the drivers which libnetwork can make use of
  95. type Capability struct {
  96. DataScope string
  97. }
  98. // IPAMData represents the per-network ip related
  99. // operational information libnetwork will send
  100. // to the network driver during CreateNetwork()
  101. type IPAMData struct {
  102. AddressSpace string
  103. Pool *net.IPNet
  104. Gateway *net.IPNet
  105. AuxAddresses map[string]*net.IPNet
  106. }