api.go 5.8 KB

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