driverapi.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package driverapi
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/docker/libnetwork/sandbox"
  6. "github.com/docker/libnetwork/types"
  7. )
  8. var (
  9. // ErrEndpointExists is returned if more than one endpoint is added to the network
  10. ErrEndpointExists = errors.New("Endpoint already exists (Only one endpoint allowed)")
  11. // ErrNoNetwork is returned if no network with the specified id exists
  12. ErrNoNetwork = errors.New("No network exists")
  13. // ErrNoEndpoint is returned if no endpoint with the specified id exists
  14. ErrNoEndpoint = errors.New("No endpoint exists")
  15. // ErrNotImplemented is returned when a Driver has not implemented an API yet
  16. ErrNotImplemented = errors.New("The API is not implemented yet")
  17. )
  18. // NetworkPluginEndpointType represents the Endpoint Type used by Plugin system
  19. const NetworkPluginEndpointType = "NetworkDriver"
  20. // Driver is an interface that every plugin driver needs to implement.
  21. type Driver interface {
  22. // Push driver specific config to the driver
  23. Config(options map[string]interface{}) error
  24. // CreateNetwork invokes the driver method to create a network passing
  25. // the network id and network specific config. The config mechanism will
  26. // eventually be replaced with labels which are yet to be introduced.
  27. CreateNetwork(nid types.UUID, options map[string]interface{}) error
  28. // DeleteNetwork invokes the driver method to delete network passing
  29. // the network id.
  30. DeleteNetwork(nid types.UUID) error
  31. // CreateEndpoint invokes the driver method to create an endpoint
  32. // passing the network id, endpoint id and driver
  33. // specific config. The config mechanism will eventually be replaced
  34. // with labels which are yet to be introduced.
  35. CreateEndpoint(nid, eid types.UUID, options map[string]interface{}) (*sandbox.Info, error)
  36. // DeleteEndpoint invokes the driver method to delete an endpoint
  37. // passing the network id and endpoint id.
  38. DeleteEndpoint(nid, eid types.UUID) error
  39. // EndpointInfo retrieves from the driver the operational data related to the specified endpoint
  40. EndpointInfo(nid, eid types.UUID) (map[string]interface{}, error)
  41. // Join method is invoked when a Sandbox is attached to an endpoint.
  42. Join(nid, eid types.UUID, sboxKey string, options map[string]interface{}) (*JoinInfo, error)
  43. // Leave method is invoked when a Sandbox detaches from an endpoint.
  44. Leave(nid, eid types.UUID, options map[string]interface{}) error
  45. // Type returns the the type of this driver, the network type this driver manages
  46. Type() string
  47. }
  48. // JoinInfo represents a set of resources that the driver has the ability to provide during
  49. // join time.
  50. type JoinInfo struct {
  51. HostsPath string
  52. }
  53. // ErrActiveRegistration represents an error when a driver is registered to a networkType that is previously registered
  54. type ErrActiveRegistration string
  55. // Error interface for ErrActiveRegistration
  56. func (ar ErrActiveRegistration) Error() string {
  57. return fmt.Sprintf("Driver already registered for type %q", string(ar))
  58. }
  59. // DriverCallback provides a Callback interface for Drivers into LibNetwork
  60. type DriverCallback interface {
  61. // RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
  62. RegisterDriver(name string, driver Driver) error
  63. }