api.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. Package api represents all requests and responses suitable for conversation
  3. with a remote driver.
  4. */
  5. package api
  6. import (
  7. "net"
  8. "github.com/docker/libnetwork/driverapi"
  9. )
  10. // Response is the basic response structure used in all responses.
  11. type Response struct {
  12. Err string
  13. }
  14. // GetError returns the error from the response, if any.
  15. func (r *Response) GetError() string {
  16. return r.Err
  17. }
  18. // GetCapabilityResponse is the response of GetCapability request
  19. type GetCapabilityResponse struct {
  20. Response
  21. Scope string
  22. }
  23. // CreateNetworkRequest requests a new network.
  24. type CreateNetworkRequest struct {
  25. // A network ID that remote plugins are expected to store for future
  26. // reference.
  27. NetworkID string
  28. // A free form map->object interface for communication of options.
  29. Options map[string]interface{}
  30. }
  31. // CreateNetworkResponse is the response to the CreateNetworkRequest.
  32. type CreateNetworkResponse struct {
  33. Response
  34. }
  35. // DeleteNetworkRequest is the request to delete an existing network.
  36. type DeleteNetworkRequest struct {
  37. // The ID of the network to delete.
  38. NetworkID string
  39. }
  40. // DeleteNetworkResponse is the response to a request for deleting a network.
  41. type DeleteNetworkResponse struct {
  42. Response
  43. }
  44. // CreateEndpointRequest is the request to create an endpoint within a network.
  45. type CreateEndpointRequest struct {
  46. // Provided at create time, this will be the network id referenced.
  47. NetworkID string
  48. // The ID of the endpoint for later reference.
  49. EndpointID string
  50. Interface *EndpointInterface
  51. Options map[string]interface{}
  52. }
  53. // EndpointInterface represents an interface endpoint.
  54. type EndpointInterface struct {
  55. Address string
  56. AddressIPv6 string
  57. MacAddress string
  58. }
  59. // CreateEndpointResponse is the response to the CreateEndpoint action.
  60. type CreateEndpointResponse struct {
  61. Response
  62. Interface *EndpointInterface
  63. }
  64. // Interface is the representation of a linux interface.
  65. type Interface struct {
  66. Address *net.IPNet
  67. AddressIPv6 *net.IPNet
  68. MacAddress net.HardwareAddr
  69. }
  70. // DeleteEndpointRequest describes the API for deleting an endpoint.
  71. type DeleteEndpointRequest struct {
  72. NetworkID string
  73. EndpointID string
  74. }
  75. // DeleteEndpointResponse is the response to the DeleteEndpoint action.
  76. type DeleteEndpointResponse struct {
  77. Response
  78. }
  79. // EndpointInfoRequest retrieves information about the endpoint from the network driver.
  80. type EndpointInfoRequest struct {
  81. NetworkID string
  82. EndpointID string
  83. }
  84. // EndpointInfoResponse is the response to an EndpointInfoRequest.
  85. type EndpointInfoResponse struct {
  86. Response
  87. Value map[string]interface{}
  88. }
  89. // JoinRequest describes the API for joining an endpoint to a sandbox.
  90. type JoinRequest struct {
  91. NetworkID string
  92. EndpointID string
  93. SandboxKey string
  94. Options map[string]interface{}
  95. }
  96. // InterfaceName is the struct represetation of a pair of devices with source
  97. // and destination, for the purposes of putting an endpoint into a container.
  98. type InterfaceName struct {
  99. SrcName string
  100. DstName string
  101. DstPrefix string
  102. }
  103. // StaticRoute is the plain JSON representation of a static route.
  104. type StaticRoute struct {
  105. Destination string
  106. RouteType int
  107. NextHop string
  108. }
  109. // JoinResponse is the response to a JoinRequest.
  110. type JoinResponse struct {
  111. Response
  112. InterfaceName *InterfaceName
  113. Gateway string
  114. GatewayIPv6 string
  115. StaticRoutes []StaticRoute
  116. }
  117. // LeaveRequest describes the API for detaching an endpoint from a sandbox.
  118. type LeaveRequest struct {
  119. NetworkID string
  120. EndpointID string
  121. }
  122. // LeaveResponse is the answer to LeaveRequest.
  123. type LeaveResponse struct {
  124. Response
  125. }
  126. // DiscoveryNotification represents a discovery notification
  127. type DiscoveryNotification struct {
  128. DiscoveryType driverapi.DiscoveryType
  129. DiscoveryData interface{}
  130. }
  131. // DiscoveryResponse is used by libnetwork to log any plugin error processing the discovery notifications
  132. type DiscoveryResponse struct {
  133. Response
  134. }