Skip to content

Commit 346f09c

Browse files
NET-1986: Only report online hosts. (#3370)
* feat(go): only report online hosts. * feat(go): only report online external clients.
1 parent 4105a98 commit 346f09c

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

logic/extpeers.go

+21
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,27 @@ func GetAllExtClients() ([]models.ExtClient, error) {
416416
return clients, nil
417417
}
418418

419+
// GetAllExtClientsWithStatus - returns all external clients with
420+
// given status.
421+
func GetAllExtClientsWithStatus(status models.NodeStatus) ([]models.ExtClient, error) {
422+
extClients, err := GetAllExtClients()
423+
if err != nil {
424+
return nil, err
425+
}
426+
427+
var validExtClients []models.ExtClient
428+
for _, extClient := range extClients {
429+
nodes := []models.Node{extClient.ConvertToStaticNode()}
430+
AddStatusToNodes(nodes)
431+
432+
if nodes[0].Status == status {
433+
validExtClients = append(validExtClients, extClient)
434+
}
435+
}
436+
437+
return validExtClients, nil
438+
}
439+
419440
// ToggleExtClientConnectivity - enables or disables an ext client
420441
func ToggleExtClientConnectivity(client *models.ExtClient, enable bool) (models.ExtClient, error) {
421442
update := models.CustomExtClient{

logic/hosts.go

+27
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,33 @@ func GetAllHosts() ([]models.Host, error) {
106106
return currHosts, nil
107107
}
108108

109+
// GetAllHostsWithStatus - returns all hosts with at least one
110+
// node with given status.
111+
func GetAllHostsWithStatus(status models.NodeStatus) ([]models.Host, error) {
112+
hosts, err := GetAllHosts()
113+
if err != nil {
114+
return nil, err
115+
}
116+
117+
var validHosts []models.Host
118+
for _, host := range hosts {
119+
if len(host.Nodes) == 0 {
120+
continue
121+
}
122+
123+
nodes := AddStatusToNodes(GetHostNodes(&host))
124+
125+
for _, node := range nodes {
126+
if node.Status == status {
127+
validHosts = append(validHosts, host)
128+
break
129+
}
130+
}
131+
}
132+
133+
return validHosts, nil
134+
}
135+
109136
// GetAllHostsAPI - get's all the hosts in an API usable format
110137
func GetAllHostsAPI(hosts []models.Host) []models.ApiHost {
111138
apiHosts := []models.ApiHost{}

pro/util.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package pro
55

66
import (
77
"encoding/base64"
8+
"github.com/gravitl/netmaker/models"
89

910
"github.com/gravitl/netmaker/logic"
1011
)
@@ -26,11 +27,11 @@ func base64decode(input string) []byte {
2627

2728
func getCurrentServerUsage() (limits Usage) {
2829
limits.SetDefaults()
29-
hosts, hErr := logic.GetAllHosts()
30+
hosts, hErr := logic.GetAllHostsWithStatus(models.OnlineSt)
3031
if hErr == nil {
3132
limits.Hosts = len(hosts)
3233
}
33-
clients, cErr := logic.GetAllExtClients()
34+
clients, cErr := logic.GetAllExtClientsWithStatus(models.OnlineSt)
3435
if cErr == nil {
3536
limits.Clients = len(clients)
3637
}

0 commit comments

Comments
 (0)