api.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. // IPAMData contains the address pool information for this network
  31. IPv4Data, IPv6Data []driverapi.IPAMData
  32. }
  33. // CreateNetworkResponse is the response to the CreateNetworkRequest.
  34. type CreateNetworkResponse struct {
  35. Response
  36. }
  37. // DeleteNetworkRequest is the request to delete an existing network.
  38. type DeleteNetworkRequest struct {
  39. // The ID of the network to delete.
  40. NetworkID string
  41. }
  42. // DeleteNetworkResponse is the response to a request for deleting a network.
  43. type DeleteNetworkResponse struct {
  44. Response
  45. }
  46. // CreateEndpointRequest is the request to create an endpoint within a network.
  47. type CreateEndpointRequest struct {
  48. // Provided at create time, this will be the network id referenced.
  49. NetworkID string
  50. // The ID of the endpoint for later reference.
  51. EndpointID string
  52. Interface *EndpointInterface
  53. Options map[string]interface{}
  54. }
  55. // EndpointInterface represents an interface endpoint.
  56. type EndpointInterface struct {
  57. Address string
  58. AddressIPv6 string
  59. MacAddress string
  60. }
  61. // CreateEndpointResponse is the response to the CreateEndpoint action.
  62. type CreateEndpointResponse struct {
  63. Response
  64. Interface *EndpointInterface
  65. }
  66. // Interface is the representation of a linux interface.
  67. type Interface struct {
  68. Address *net.IPNet
  69. AddressIPv6 *net.IPNet
  70. MacAddress net.HardwareAddr
  71. }
  72. // DeleteEndpointRequest describes the API for deleting an endpoint.
  73. type DeleteEndpointRequest struct {
  74. NetworkID string
  75. EndpointID string
  76. }
  77. // DeleteEndpointResponse is the response to the DeleteEndpoint action.
  78. type DeleteEndpointResponse struct {
  79. Response
  80. }
  81. // EndpointInfoRequest retrieves information about the endpoint from the network driver.
  82. type EndpointInfoRequest struct {
  83. NetworkID string
  84. EndpointID string
  85. }
  86. // EndpointInfoResponse is the response to an EndpointInfoRequest.
  87. type EndpointInfoResponse struct {
  88. Response
  89. Value map[string]interface{}
  90. }
  91. // JoinRequest describes the API for joining an endpoint to a sandbox.
  92. type JoinRequest struct {
  93. NetworkID string
  94. EndpointID string
  95. SandboxKey string
  96. Options map[string]interface{}
  97. }
  98. // InterfaceName is the struct represetation of a pair of devices with source
  99. // and destination, for the purposes of putting an endpoint into a container.
  100. type InterfaceName struct {
  101. SrcName string
  102. DstName string
  103. DstPrefix string
  104. }
  105. // StaticRoute is the plain JSON representation of a static route.
  106. type StaticRoute struct {
  107. Destination string
  108. RouteType int
  109. NextHop string
  110. }
  111. // JoinResponse is the response to a JoinRequest.
  112. type JoinResponse struct {
  113. Response
  114. InterfaceName *InterfaceName
  115. Gateway string
  116. GatewayIPv6 string
  117. StaticRoutes []StaticRoute
  118. }
  119. // LeaveRequest describes the API for detaching an endpoint from a sandbox.
  120. type LeaveRequest struct {
  121. NetworkID string
  122. EndpointID string
  123. }
  124. // LeaveResponse is the answer to LeaveRequest.
  125. type LeaveResponse struct {
  126. Response
  127. }
  128. // DiscoveryNotification represents a discovery notification
  129. type DiscoveryNotification struct {
  130. DiscoveryType driverapi.DiscoveryType
  131. DiscoveryData interface{}
  132. }
  133. // DiscoveryResponse is used by libnetwork to log any plugin error processing the discovery notifications
  134. type DiscoveryResponse struct {
  135. Response
  136. }