driverapi.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. // Push driver specific config to the driver
  8. Config(options map[string]interface{}) error
  9. // CreateNetwork invokes the driver method to create a network passing
  10. // the network id and network specific config. The config mechanism will
  11. // eventually be replaced with labels which are yet to be introduced.
  12. CreateNetwork(nid string, options map[string]interface{}) error
  13. // DeleteNetwork invokes the driver method to delete network passing
  14. // the network id.
  15. DeleteNetwork(nid string) error
  16. // CreateEndpoint invokes the driver method to create an endpoint
  17. // passing the network id, endpoint id endpoint information and driver
  18. // specific config. The endpoint information can be either consumed by
  19. // the driver or populated by the driver. The config mechanism will
  20. // eventually be replaced with labels which are yet to be introduced.
  21. CreateEndpoint(nid, eid string, epInfo EndpointInfo, options map[string]interface{}) error
  22. // DeleteEndpoint invokes the driver method to delete an endpoint
  23. // passing the network id and endpoint id.
  24. DeleteEndpoint(nid, eid string) error
  25. // EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint
  26. EndpointOperInfo(nid, eid string) (map[string]interface{}, error)
  27. // Join method is invoked when a Sandbox is attached to an endpoint.
  28. Join(nid, eid string, sboxKey string, jinfo JoinInfo, options map[string]interface{}) error
  29. // Leave method is invoked when a Sandbox detaches from an endpoint.
  30. Leave(nid, eid string) error
  31. // Type returns the the type of this driver, the network type this driver manages
  32. Type() string
  33. }
  34. // EndpointInfo provides a go interface to fetch or populate endpoint assigned network resources.
  35. type EndpointInfo interface {
  36. // Interfaces returns a list of interfaces bound to the endpoint.
  37. // If the list is not empty the driver is only expected to consume the interfaces.
  38. // It is an error to try to add interfaces to a non-empty list.
  39. // If the list is empty the driver is expected to populate with 0 or more interfaces.
  40. Interfaces() []InterfaceInfo
  41. // AddInterface is used by the driver to add an interface to the interface list.
  42. // This method will return an error if the driver attempts to add interfaces
  43. // if the Interfaces() method returned a non-empty list.
  44. // ID field need only have significance within the endpoint so it can be a simple
  45. // monotonically increasing number
  46. AddInterface(ID int, mac net.HardwareAddr, ipv4 net.IPNet, ipv6 net.IPNet) error
  47. }
  48. // InterfaceInfo provides a go interface for drivers to retrive
  49. // network information to interface resources.
  50. type InterfaceInfo interface {
  51. // MacAddress returns the MAC address.
  52. MacAddress() net.HardwareAddr
  53. // Address returns the IPv4 address.
  54. Address() net.IPNet
  55. // AddressIPv6 returns the IPv6 address.
  56. AddressIPv6() net.IPNet
  57. // ID returns the numerical id of the interface and has significance only within
  58. // the endpoint.
  59. ID() int
  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. // ID returns the numerical id that was assigned to the interface by the driver
  67. // CreateEndpoint.
  68. ID() int
  69. }
  70. // JoinInfo represents a set of resources that the driver has the ability to provide during
  71. // join time.
  72. type JoinInfo interface {
  73. // InterfaceNames returns a list of InterfaceNameInfo go interface to facilitate
  74. // setting the names for the interfaces.
  75. InterfaceNames() []InterfaceNameInfo
  76. // SetGateway sets the default IPv4 gateway when a container joins the endpoint.
  77. SetGateway(net.IP) error
  78. // SetGatewayIPv6 sets the default IPv6 gateway when a container joins the endpoint.
  79. SetGatewayIPv6(net.IP) error
  80. // AddStaticRoute adds a routes to the sandbox.
  81. // It may be used in addtion to or instead of a default gateway (as above).
  82. AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP, interfaceID int) error
  83. }
  84. // DriverCallback provides a Callback interface for Drivers into LibNetwork
  85. type DriverCallback interface {
  86. // RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
  87. RegisterDriver(name string, driver Driver, capability Capability) error
  88. }
  89. // Scope indicates the drivers scope capability
  90. type Scope int
  91. const (
  92. // LocalScope represents the driver capable of providing networking services for containers in a single host
  93. LocalScope Scope = iota
  94. // GlobalScope represents the driver capable of providing networking services for containers across hosts
  95. GlobalScope
  96. )
  97. // Capability represents the high level capabilities of the drivers which libnetwork can make use of
  98. type Capability struct {
  99. Scope Scope
  100. }