File tree 3 files changed +51
-2
lines changed
3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change @@ -416,6 +416,27 @@ func GetAllExtClients() ([]models.ExtClient, error) {
416
416
return clients , nil
417
417
}
418
418
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
+
419
440
// ToggleExtClientConnectivity - enables or disables an ext client
420
441
func ToggleExtClientConnectivity (client * models.ExtClient , enable bool ) (models.ExtClient , error ) {
421
442
update := models.CustomExtClient {
Original file line number Diff line number Diff line change @@ -106,6 +106,33 @@ func GetAllHosts() ([]models.Host, error) {
106
106
return currHosts , nil
107
107
}
108
108
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
+
109
136
// GetAllHostsAPI - get's all the hosts in an API usable format
110
137
func GetAllHostsAPI (hosts []models.Host ) []models.ApiHost {
111
138
apiHosts := []models.ApiHost {}
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ package pro
5
5
6
6
import (
7
7
"encoding/base64"
8
+ "github.com/gravitl/netmaker/models"
8
9
9
10
"github.com/gravitl/netmaker/logic"
10
11
)
@@ -26,11 +27,11 @@ func base64decode(input string) []byte {
26
27
27
28
func getCurrentServerUsage () (limits Usage ) {
28
29
limits .SetDefaults ()
29
- hosts , hErr := logic .GetAllHosts ( )
30
+ hosts , hErr := logic .GetAllHostsWithStatus ( models . OnlineSt )
30
31
if hErr == nil {
31
32
limits .Hosts = len (hosts )
32
33
}
33
- clients , cErr := logic .GetAllExtClients ( )
34
+ clients , cErr := logic .GetAllExtClientsWithStatus ( models . OnlineSt )
34
35
if cErr == nil {
35
36
limits .Clients = len (clients )
36
37
}
You can’t perform that action at this time.
0 commit comments