api.go 3.5 KB

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