node.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package swarm
  2. // Node represents a node.
  3. type Node struct {
  4. ID string
  5. Meta
  6. // Spec defines the desired state of the node as specified by the user.
  7. // The system will honor this and will *never* modify it.
  8. Spec NodeSpec `json:",omitempty"`
  9. // Description encapsulates the properties of the Node as reported by the
  10. // agent.
  11. Description NodeDescription `json:",omitempty"`
  12. // Status provides the current status of the node, as seen by the manager.
  13. Status NodeStatus `json:",omitempty"`
  14. // ManagerStatus provides the current status of the node's manager
  15. // component, if the node is a manager.
  16. ManagerStatus *ManagerStatus `json:",omitempty"`
  17. }
  18. // NodeSpec represents the spec of a node.
  19. type NodeSpec struct {
  20. Annotations
  21. Role NodeRole `json:",omitempty"`
  22. Availability NodeAvailability `json:",omitempty"`
  23. }
  24. // NodeRole represents the role of a node.
  25. type NodeRole string
  26. const (
  27. // NodeRoleWorker WORKER
  28. NodeRoleWorker NodeRole = "worker"
  29. // NodeRoleManager MANAGER
  30. NodeRoleManager NodeRole = "manager"
  31. )
  32. // NodeAvailability represents the availability of a node.
  33. type NodeAvailability string
  34. const (
  35. // NodeAvailabilityActive ACTIVE
  36. NodeAvailabilityActive NodeAvailability = "active"
  37. // NodeAvailabilityPause PAUSE
  38. NodeAvailabilityPause NodeAvailability = "pause"
  39. // NodeAvailabilityDrain DRAIN
  40. NodeAvailabilityDrain NodeAvailability = "drain"
  41. )
  42. // NodeDescription represents the description of a node.
  43. type NodeDescription struct {
  44. Hostname string `json:",omitempty"`
  45. Platform Platform `json:",omitempty"`
  46. Resources Resources `json:",omitempty"`
  47. Engine EngineDescription `json:",omitempty"`
  48. }
  49. // Platform represents the platform (Arch/OS).
  50. type Platform struct {
  51. Architecture string `json:",omitempty"`
  52. OS string `json:",omitempty"`
  53. }
  54. // EngineDescription represents the description of an engine.
  55. type EngineDescription struct {
  56. EngineVersion string `json:",omitempty"`
  57. Labels map[string]string `json:",omitempty"`
  58. Plugins []PluginDescription `json:",omitempty"`
  59. }
  60. // PluginDescription represents the description of an engine plugin.
  61. type PluginDescription struct {
  62. Type string `json:",omitempty"`
  63. Name string `json:",omitempty"`
  64. }
  65. // NodeStatus represents the status of a node.
  66. type NodeStatus struct {
  67. State NodeState `json:",omitempty"`
  68. Message string `json:",omitempty"`
  69. Addr string `json:",omitempty"`
  70. }
  71. // Reachability represents the reachability of a node.
  72. type Reachability string
  73. const (
  74. // ReachabilityUnknown UNKNOWN
  75. ReachabilityUnknown Reachability = "unknown"
  76. // ReachabilityUnreachable UNREACHABLE
  77. ReachabilityUnreachable Reachability = "unreachable"
  78. // ReachabilityReachable REACHABLE
  79. ReachabilityReachable Reachability = "reachable"
  80. )
  81. // ManagerStatus represents the status of a manager.
  82. type ManagerStatus struct {
  83. Leader bool `json:",omitempty"`
  84. Reachability Reachability `json:",omitempty"`
  85. Addr string `json:",omitempty"`
  86. }
  87. // NodeState represents the state of a node.
  88. type NodeState string
  89. const (
  90. // NodeStateUnknown UNKNOWN
  91. NodeStateUnknown NodeState = "unknown"
  92. // NodeStateDown DOWN
  93. NodeStateDown NodeState = "down"
  94. // NodeStateReady READY
  95. NodeStateReady NodeState = "ready"
  96. // NodeStateDisconnected DISCONNECTED
  97. NodeStateDisconnected NodeState = "disconnected"
  98. )