2022-11-16 18:38:39 +02:00
|
|
|
package status
|
|
|
|
|
|
|
|
import (
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
2023-05-05 09:02:31 +07:00
|
|
|
"github.com/portainer/portainer/api/internal/endpointutils"
|
2022-11-16 18:38:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// NodesCount returns the total node number of all environments
|
|
|
|
func NodesCount(endpoints []portainer.Endpoint) int {
|
|
|
|
nodes := 0
|
2024-06-26 18:14:22 -03:00
|
|
|
|
2022-11-16 18:38:39 +02:00
|
|
|
for _, env := range endpoints {
|
2023-05-05 09:02:31 +07:00
|
|
|
if !endpointutils.IsEdgeEndpoint(&env) || env.UserTrusted {
|
|
|
|
nodes += countNodes(&env)
|
|
|
|
}
|
2022-11-16 18:38:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nodes
|
|
|
|
}
|
|
|
|
|
|
|
|
func countNodes(endpoint *portainer.Endpoint) int {
|
|
|
|
if len(endpoint.Snapshots) == 1 {
|
|
|
|
return max(endpoint.Snapshots[0].NodeCount, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(endpoint.Kubernetes.Snapshots) == 1 {
|
|
|
|
return max(endpoint.Kubernetes.Snapshots[0].NodeCount, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|