15ce12e7b7
* feat(license): add liblicense dep * feat(license): add bolt license service * feat(license): introduce license service * feat(license): validate license before adding * feat(license): aggregate info after changing of licenses * feat(http): implement http handlers * feat(license-management): introduce license service * feat(licenses): introduce empty view * feat(license-management): add datatable * feat(licenses): show license info * fix(license): inject services * feat(licenses): add buttons to buy/renew license * feat(licenses): introduce add license route * feat(licenses): add license form * feat(license): datatable * feat(license): show more details about license * refactor(license): rename components name * feat(licenses): show expiration date * feat(license): introduce init license route * feat(license): validate license * feat(license): save licenses * feat(bouncer): check if license is valid on restricted * feat(bouncer): remove license check on api * feat(home): add node warning * feat(licenses): remove license * feat(licenses): listen to info changes * feat(license): show license expiration message * feat(license): block regular users from licenses view * feat(license): prevent removing of last license * fix(license): show message when failed delete * feat(license): remove trial license when applying oneoff * feat(license): hide the number of nodes for trial * feat(auth): disable login if license is invalid * feat(licenses): add confirmation before removal of license * feat(nodes): count nodes in env * feat(license): show message if nodes exceed allowed * feat(deps): update liblicense * feat(licenses): show validation errors * feat(license): use information panel for node info * fix(license): reload license data on remove * fix(license): always send list of failed keys * fix(license): rename buttons * feat(license): replace icon * feat(license): add link to licenses page in add license * fix(licenses): show green valid icon * fix(licenses): rename expires at * fix(licenses): rename Attach to add * fix(licenses): show license type label * feat(license): aggregate revoked info * chore(deps): update liblicense * fix(license): remove space * fix(sidebar): align icon * fix(license): change info layout * feat(license): aggregate only valid licenses * fix(licenses): move add license to a new line * style(license): remove console * refactor(license): move license line to component * feat(license): check server validation * fix(licenses): check form validation before submit * feat(licenses): send only invalid licenses * fix(license): hide panels when not needed * feat(licnese): receive a single license on init * refactor(header): move header to module * feat(license): move license panel to header * fix(header): set min height * fix(home): show node warning only if subscription * feat(licenses): minor UI updates * feat(licenses): minor UI update * feat(licenses-datatable): add copy button * fix(licenses-datatable): show date without hours * feat(license): show expiration message * fix(users): get user info only on restriced access * fix(license): clear check for single license Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package status
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
"github.com/portainer/libhttp/response"
|
|
"github.com/portainer/portainer/api"
|
|
)
|
|
|
|
type nodesCountResponse struct {
|
|
Nodes int `json:"nodes"`
|
|
}
|
|
|
|
// GET request on /api/status
|
|
func (handler *Handler) statusNodesCount(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
|
endpoints, err := handler.DataStore.Endpoint().Endpoints()
|
|
if err != nil {
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Failed to get endpoint list", err}
|
|
}
|
|
|
|
nodes := 0
|
|
for _, endpoint := range endpoints {
|
|
nodes += countNodes(&endpoint)
|
|
}
|
|
|
|
return response.JSON(w, &nodesCountResponse{Nodes: nodes})
|
|
}
|
|
|
|
func countNodes(endpoint *portainer.Endpoint) int {
|
|
switch endpoint.Type {
|
|
case portainer.EdgeAgentOnDockerEnvironment, portainer.DockerEnvironment, portainer.AgentOnDockerEnvironment:
|
|
return countDockerNodes(endpoint)
|
|
case portainer.EdgeAgentOnKubernetesEnvironment, portainer.KubernetesLocalEnvironment, portainer.AgentOnKubernetesEnvironment:
|
|
return countKubernetesNodes(endpoint)
|
|
case portainer.AzureEnvironment:
|
|
return 0
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func countDockerNodes(endpoint *portainer.Endpoint) int {
|
|
snapshots := endpoint.Snapshots
|
|
if len(snapshots) == 0 {
|
|
return 0
|
|
}
|
|
|
|
snapshot := snapshots[len(snapshots)-1]
|
|
return snapshot.NodeCount
|
|
}
|
|
|
|
func countKubernetesNodes(endpoint *portainer.Endpoint) int {
|
|
snapshots := endpoint.Kubernetes.Snapshots
|
|
if len(snapshots) == 0 {
|
|
return 0
|
|
}
|
|
|
|
snapshot := snapshots[len(snapshots)-1]
|
|
return snapshot.NodeCount
|
|
}
|