api.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Package api defines the data structure to be used in the request/response
  2. // messages between libnetwork and the remote ipam plugin
  3. package api
  4. import "github.com/docker/libnetwork/ipamapi"
  5. // Response is the basic response structure used in all responses
  6. type Response struct {
  7. Error string
  8. }
  9. // IsSuccess returns wheter the plugin response is successful
  10. func (r *Response) IsSuccess() bool {
  11. return r.Error == ""
  12. }
  13. // GetError returns the error from the response, if any.
  14. func (r *Response) GetError() string {
  15. return r.Error
  16. }
  17. // GetCapabilityResponse is the response of GetCapability request
  18. type GetCapabilityResponse struct {
  19. Response
  20. RequiresMACAddress bool
  21. RequiresRequestReplay bool
  22. }
  23. // ToCapability converts the capability response into the internal ipam driver capability structure
  24. func (capRes GetCapabilityResponse) ToCapability() *ipamapi.Capability {
  25. return &ipamapi.Capability{
  26. RequiresMACAddress: capRes.RequiresMACAddress,
  27. RequiresRequestReplay: capRes.RequiresRequestReplay,
  28. }
  29. }
  30. // GetAddressSpacesResponse is the response to the ``get default address spaces`` request message
  31. type GetAddressSpacesResponse struct {
  32. Response
  33. LocalDefaultAddressSpace string
  34. GlobalDefaultAddressSpace string
  35. }
  36. // RequestPoolRequest represents the expected data in a ``request address pool`` request message
  37. type RequestPoolRequest struct {
  38. AddressSpace string
  39. Pool string
  40. SubPool string
  41. Options map[string]string
  42. V6 bool
  43. }
  44. // RequestPoolResponse represents the response message to a ``request address pool`` request
  45. type RequestPoolResponse struct {
  46. Response
  47. PoolID string
  48. Pool string // CIDR format
  49. Data map[string]string
  50. }
  51. // ReleasePoolRequest represents the expected data in a ``release address pool`` request message
  52. type ReleasePoolRequest struct {
  53. PoolID string
  54. }
  55. // ReleasePoolResponse represents the response message to a ``release address pool`` request
  56. type ReleasePoolResponse struct {
  57. Response
  58. }
  59. // RequestAddressRequest represents the expected data in a ``request address`` request message
  60. type RequestAddressRequest struct {
  61. PoolID string
  62. Address string
  63. Options map[string]string
  64. }
  65. // RequestAddressResponse represents the expected data in the response message to a ``request address`` request
  66. type RequestAddressResponse struct {
  67. Response
  68. Address string // in CIDR format
  69. Data map[string]string
  70. }
  71. // ReleaseAddressRequest represents the expected data in a ``release address`` request message
  72. type ReleaseAddressRequest struct {
  73. PoolID string
  74. Address string
  75. }
  76. // ReleaseAddressResponse represents the response message to a ``release address`` request
  77. type ReleaseAddressResponse struct {
  78. Response
  79. }