driverapi.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package driverapi
  2. import (
  3. "net"
  4. "github.com/docker/libnetwork/types"
  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. // Push driver specific config to the driver
  11. Config(options map[string]interface{}) error
  12. // CreateNetwork invokes the driver method to create a network passing
  13. // the network id and network specific config. The config mechanism will
  14. // eventually be replaced with labels which are yet to be introduced.
  15. CreateNetwork(nid types.UUID, options map[string]interface{}) error
  16. // DeleteNetwork invokes the driver method to delete network passing
  17. // the network id.
  18. DeleteNetwork(nid types.UUID) error
  19. // CreateEndpoint invokes the driver method to create an endpoint
  20. // passing the network id, endpoint id endpoint information and driver
  21. // specific config. The endpoint information can be either consumed by
  22. // the driver or populated by the driver. The config mechanism will
  23. // eventually be replaced with labels which are yet to be introduced.
  24. CreateEndpoint(nid, eid types.UUID, epInfo EndpointInfo, options map[string]interface{}) error
  25. // DeleteEndpoint invokes the driver method to delete an endpoint
  26. // passing the network id and endpoint id.
  27. DeleteEndpoint(nid, eid types.UUID) error
  28. // EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint
  29. EndpointOperInfo(nid, eid types.UUID) (map[string]interface{}, error)
  30. // Join method is invoked when a Sandbox is attached to an endpoint.
  31. Join(nid, eid types.UUID, sboxKey string, jinfo JoinInfo, options map[string]interface{}) error
  32. // Leave method is invoked when a Sandbox detaches from an endpoint.
  33. Leave(nid, eid types.UUID) error
  34. // Type returns the the type of this driver, the network type this driver manages
  35. Type() string
  36. }
  37. // EndpointInfo provides a go interface to fetch or populate endpoint assigned network resources.
  38. type EndpointInfo interface {
  39. // Interfaces returns a list of interfaces bound to the endpoint.
  40. // If the list is not empty the driver is only expected to consume the interfaces.
  41. // It is an error to try to add interfaces to a non-empty list.
  42. // If the list is empty the driver is expected to populate with 0 or more interfaces.
  43. Interfaces() []InterfaceInfo
  44. // AddInterface is used by the driver to add an interface to the interface list.
  45. // This method will return an error if the driver attempts to add interfaces
  46. // if the Interfaces() method returned a non-empty list.
  47. // ID field need only have significance within the endpoint so it can be a simple
  48. // monotonically increasing number
  49. AddInterface(ID int, mac net.HardwareAddr, ipv4 net.IPNet, ipv6 net.IPNet) error
  50. }
  51. // InterfaceInfo provides a go interface for drivers to retrive
  52. // network information to interface resources.
  53. type InterfaceInfo interface {
  54. // MacAddress returns the MAC address.
  55. MacAddress() net.HardwareAddr
  56. // Address returns the IPv4 address.
  57. Address() net.IPNet
  58. // AddressIPv6 returns the IPv6 address.
  59. AddressIPv6() net.IPNet
  60. // ID returns the numerical id of the interface and has significance only within
  61. // the endpoint.
  62. ID() int
  63. }
  64. // InterfaceNameInfo provides a go interface for the drivers to assign names
  65. // to interfaces.
  66. type InterfaceNameInfo interface {
  67. // SetNames method assigns the srcName and dstName for the interface.
  68. SetNames(srcName, dstName string) error
  69. // ID returns the numerical id that was assigned to the interface by the driver
  70. // CreateEndpoint.
  71. ID() int
  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. // InterfaceNames returns a list of InterfaceNameInfo go interface to facilitate
  77. // setting the names for the interfaces.
  78. InterfaceNames() []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. // SetHostsPath sets the overriding /etc/hosts path to use for the container.
  84. SetHostsPath(string) error
  85. // SetResolvConfPath sets the overriding /etc/resolv.conf path to use for the container.
  86. SetResolvConfPath(string) error
  87. }
  88. // DriverCallback provides a Callback interface for Drivers into LibNetwork
  89. type DriverCallback interface {
  90. // RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
  91. RegisterDriver(name string, driver Driver) error
  92. }