api.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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/discoverapi"
  9. "github.com/docker/libnetwork/driverapi"
  10. )
  11. // Response is the basic response structure used in all responses.
  12. type Response struct {
  13. Err string
  14. }
  15. // GetError returns the error from the response, if any.
  16. func (r *Response) GetError() string {
  17. return r.Err
  18. }
  19. // GetCapabilityResponse is the response of GetCapability request
  20. type GetCapabilityResponse struct {
  21. Response
  22. Scope string
  23. ConnectivityScope string
  24. }
  25. // AllocateNetworkRequest requests allocation of new network by manager
  26. type AllocateNetworkRequest struct {
  27. // A network ID that remote plugins are expected to store for future
  28. // reference.
  29. NetworkID string
  30. // A free form map->object interface for communication of options.
  31. Options map[string]string
  32. // IPAMData contains the address pool information for this network
  33. IPv4Data, IPv6Data []driverapi.IPAMData
  34. }
  35. // AllocateNetworkResponse is the response to the AllocateNetworkRequest.
  36. type AllocateNetworkResponse struct {
  37. Response
  38. // A free form plugin specific string->string object to be sent in
  39. // CreateNetworkRequest call in the libnetwork agents
  40. Options map[string]string
  41. }
  42. // FreeNetworkRequest is the request to free allocated network in the manager
  43. type FreeNetworkRequest struct {
  44. // The ID of the network to be freed.
  45. NetworkID string
  46. }
  47. // FreeNetworkResponse is the response to a request for freeing a network.
  48. type FreeNetworkResponse struct {
  49. Response
  50. }
  51. // CreateNetworkRequest requests a new network.
  52. type CreateNetworkRequest struct {
  53. // A network ID that remote plugins are expected to store for future
  54. // reference.
  55. NetworkID string
  56. // A free form map->object interface for communication of options.
  57. Options map[string]interface{}
  58. // IPAMData contains the address pool information for this network
  59. IPv4Data, IPv6Data []driverapi.IPAMData
  60. }
  61. // CreateNetworkResponse is the response to the CreateNetworkRequest.
  62. type CreateNetworkResponse struct {
  63. Response
  64. }
  65. // DeleteNetworkRequest is the request to delete an existing network.
  66. type DeleteNetworkRequest struct {
  67. // The ID of the network to delete.
  68. NetworkID string
  69. }
  70. // DeleteNetworkResponse is the response to a request for deleting a network.
  71. type DeleteNetworkResponse struct {
  72. Response
  73. }
  74. // CreateEndpointRequest is the request to create an endpoint within a network.
  75. type CreateEndpointRequest struct {
  76. // Provided at create time, this will be the network id referenced.
  77. NetworkID string
  78. // The ID of the endpoint for later reference.
  79. EndpointID string
  80. Interface *EndpointInterface
  81. Options map[string]interface{}
  82. }
  83. // EndpointInterface represents an interface endpoint.
  84. type EndpointInterface struct {
  85. Address string
  86. AddressIPv6 string
  87. MacAddress string
  88. }
  89. // CreateEndpointResponse is the response to the CreateEndpoint action.
  90. type CreateEndpointResponse struct {
  91. Response
  92. Interface *EndpointInterface
  93. }
  94. // Interface is the representation of a linux interface.
  95. type Interface struct {
  96. Address *net.IPNet
  97. AddressIPv6 *net.IPNet
  98. MacAddress net.HardwareAddr
  99. }
  100. // DeleteEndpointRequest describes the API for deleting an endpoint.
  101. type DeleteEndpointRequest struct {
  102. NetworkID string
  103. EndpointID string
  104. }
  105. // DeleteEndpointResponse is the response to the DeleteEndpoint action.
  106. type DeleteEndpointResponse struct {
  107. Response
  108. }
  109. // EndpointInfoRequest retrieves information about the endpoint from the network driver.
  110. type EndpointInfoRequest struct {
  111. NetworkID string
  112. EndpointID string
  113. }
  114. // EndpointInfoResponse is the response to an EndpointInfoRequest.
  115. type EndpointInfoResponse struct {
  116. Response
  117. Value map[string]interface{}
  118. }
  119. // JoinRequest describes the API for joining an endpoint to a sandbox.
  120. type JoinRequest struct {
  121. NetworkID string
  122. EndpointID string
  123. SandboxKey string
  124. Options map[string]interface{}
  125. }
  126. // InterfaceName is the struct represetation of a pair of devices with source
  127. // and destination, for the purposes of putting an endpoint into a container.
  128. type InterfaceName struct {
  129. SrcName string
  130. DstName string
  131. DstPrefix string
  132. }
  133. // StaticRoute is the plain JSON representation of a static route.
  134. type StaticRoute struct {
  135. Destination string
  136. RouteType int
  137. NextHop string
  138. }
  139. // JoinResponse is the response to a JoinRequest.
  140. type JoinResponse struct {
  141. Response
  142. InterfaceName *InterfaceName
  143. Gateway string
  144. GatewayIPv6 string
  145. StaticRoutes []StaticRoute
  146. DisableGatewayService bool
  147. }
  148. // LeaveRequest describes the API for detaching an endpoint from a sandbox.
  149. type LeaveRequest struct {
  150. NetworkID string
  151. EndpointID string
  152. }
  153. // LeaveResponse is the answer to LeaveRequest.
  154. type LeaveResponse struct {
  155. Response
  156. }
  157. // ProgramExternalConnectivityRequest describes the API for programming the external connectivity for the given endpoint.
  158. type ProgramExternalConnectivityRequest struct {
  159. NetworkID string
  160. EndpointID string
  161. Options map[string]interface{}
  162. }
  163. // ProgramExternalConnectivityResponse is the answer to ProgramExternalConnectivityRequest.
  164. type ProgramExternalConnectivityResponse struct {
  165. Response
  166. }
  167. // RevokeExternalConnectivityRequest describes the API for revoking the external connectivity for the given endpoint.
  168. type RevokeExternalConnectivityRequest struct {
  169. NetworkID string
  170. EndpointID string
  171. }
  172. // RevokeExternalConnectivityResponse is the answer to RevokeExternalConnectivityRequest.
  173. type RevokeExternalConnectivityResponse struct {
  174. Response
  175. }
  176. // DiscoveryNotification represents a discovery notification
  177. type DiscoveryNotification struct {
  178. DiscoveryType discoverapi.DiscoveryType
  179. DiscoveryData interface{}
  180. }
  181. // DiscoveryResponse is used by libnetwork to log any plugin error processing the discovery notifications
  182. type DiscoveryResponse struct {
  183. Response
  184. }