api.go 3.4 KB

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