driverapi.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // Driver is an interface that every plugin driver needs to implement.
  19. type Driver interface {
  20. // Push driver specific config to the driver
  21. Config(options map[string]interface{}) error
  22. // CreateNetwork invokes the driver method to create a network passing
  23. // the network id and network specific config. The config mechanism will
  24. // eventually be replaced with labels which are yet to be introduced.
  25. CreateNetwork(nid types.UUID, options map[string]interface{}) error
  26. // DeleteNetwork invokes the driver method to delete network passing
  27. // the network id.
  28. DeleteNetwork(nid types.UUID) error
  29. // CreateEndpoint invokes the driver method to create an endpoint
  30. // passing the network id, endpoint id and driver
  31. // specific config. The config mechanism will eventually be replaced
  32. // with labels which are yet to be introduced.
  33. CreateEndpoint(nid, eid types.UUID, options map[string]interface{}) (*sandbox.Info, error)
  34. // DeleteEndpoint invokes the driver method to delete an endpoint
  35. // passing the network id and endpoint id.
  36. DeleteEndpoint(nid, eid types.UUID) error
  37. // EndpointInfo retrieves from the driver the operational data related to the specified endpoint
  38. EndpointInfo(nid, eid types.UUID) (map[string]interface{}, error)
  39. // Join method is invoked when a Sandbox is attached to an endpoint.
  40. Join(nid, eid types.UUID, sboxKey string, options map[string]interface{}) (*JoinInfo, error)
  41. // Leave method is invoked when a Sandbox detaches from an endpoint.
  42. Leave(nid, eid types.UUID, options map[string]interface{}) error
  43. // Type returns the the type of this driver, the network type this driver manages
  44. Type() string
  45. }
  46. // JoinInfo represents a set of resources that the driver has the ability to provide during
  47. // join time.
  48. type JoinInfo struct {
  49. HostsPath string
  50. }
  51. // ErrActiveRegistration represents an error when a driver is registered to a networkType that is previously registered
  52. type ErrActiveRegistration string
  53. // Error interface for ErrActiveRegistration
  54. func (ar ErrActiveRegistration) Error() string {
  55. return fmt.Sprintf("Driver already registered for type %q", string(ar))
  56. }
  57. // DriverCallback provides a Callback interface for Drivers into LibNetwork
  58. type DriverCallback interface {
  59. // RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
  60. RegisterDriver(name string, driver Driver) error
  61. }