api.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. Interfaces []*EndpointInterface
  43. Options map[string]interface{}
  44. }
  45. // EndpointInterface represents an interface endpoint.
  46. type EndpointInterface struct {
  47. ID int
  48. Address string
  49. AddressIPv6 string
  50. MacAddress string
  51. }
  52. // CreateEndpointResponse is the response to the CreateEndpoint action.
  53. type CreateEndpointResponse struct {
  54. Response
  55. Interfaces []*EndpointInterface
  56. }
  57. // Interface is the representation of a linux interface.
  58. type Interface struct {
  59. ID int
  60. Address *net.IPNet
  61. AddressIPv6 *net.IPNet
  62. MacAddress net.HardwareAddr
  63. }
  64. // DeleteEndpointRequest describes the API for deleting an endpoint.
  65. type DeleteEndpointRequest struct {
  66. NetworkID string
  67. EndpointID string
  68. }
  69. // DeleteEndpointResponse is the response to the DeleteEndpoint action.
  70. type DeleteEndpointResponse struct {
  71. Response
  72. }
  73. // EndpointInfoRequest retrieves information about the endpoint from the network driver.
  74. type EndpointInfoRequest struct {
  75. NetworkID string
  76. EndpointID string
  77. }
  78. // EndpointInfoResponse is the response to an EndpointInfoRequest.
  79. type EndpointInfoResponse struct {
  80. Response
  81. Value map[string]interface{}
  82. }
  83. // JoinRequest describes the API for joining an endpoint to a sandbox.
  84. type JoinRequest struct {
  85. NetworkID string
  86. EndpointID string
  87. SandboxKey string
  88. Options map[string]interface{}
  89. }
  90. // InterfaceName is the struct represetation of a pair of devices with source
  91. // and destination, for the purposes of putting an endpoint into a container.
  92. type InterfaceName struct {
  93. SrcName string
  94. DstName string
  95. DstPrefix string
  96. }
  97. // StaticRoute is the plain JSON representation of a static route.
  98. type StaticRoute struct {
  99. Destination string
  100. RouteType int
  101. NextHop string
  102. InterfaceID int
  103. }
  104. // JoinResponse is the response to a JoinRequest.
  105. type JoinResponse struct {
  106. Response
  107. InterfaceNames []*InterfaceName
  108. Gateway string
  109. GatewayIPv6 string
  110. HostsPath string
  111. ResolvConfPath 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. }