mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 09:22:42 +08:00
@@ -82,11 +82,11 @@ func getUsage(w http.ResponseWriter, _ *http.Request) {
|
|||||||
FailOvers int `json:"fail_overs"`
|
FailOvers int `json:"fail_overs"`
|
||||||
}
|
}
|
||||||
var serverUsage usage
|
var serverUsage usage
|
||||||
hosts, err := logic.GetAllHosts()
|
hosts, err := logic.GetAllHostsWithStatus(models.OnlineSt)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
serverUsage.Hosts = len(hosts)
|
serverUsage.Hosts = len(hosts)
|
||||||
}
|
}
|
||||||
clients, err := logic.GetAllExtClients()
|
clients, err := logic.GetAllExtClientsWithStatus(models.OnlineSt)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
serverUsage.Clients = len(clients)
|
serverUsage.Clients = len(clients)
|
||||||
}
|
}
|
||||||
|
@@ -417,6 +417,27 @@ func GetAllExtClients() ([]models.ExtClient, error) {
|
|||||||
return clients, nil
|
return clients, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAllExtClientsWithStatus - returns all external clients with
|
||||||
|
// given status.
|
||||||
|
func GetAllExtClientsWithStatus(status models.NodeStatus) ([]models.ExtClient, error) {
|
||||||
|
extClients, err := GetAllExtClients()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var validExtClients []models.ExtClient
|
||||||
|
for _, extClient := range extClients {
|
||||||
|
node := extClient.ConvertToStaticNode()
|
||||||
|
getNodeStatus(&node, false)
|
||||||
|
|
||||||
|
if node.Status == status {
|
||||||
|
validExtClients = append(validExtClients, extClient)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return validExtClients, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ToggleExtClientConnectivity - enables or disables an ext client
|
// ToggleExtClientConnectivity - enables or disables an ext client
|
||||||
func ToggleExtClientConnectivity(client *models.ExtClient, enable bool) (models.ExtClient, error) {
|
func ToggleExtClientConnectivity(client *models.ExtClient, enable bool) (models.ExtClient, error) {
|
||||||
update := models.CustomExtClient{
|
update := models.CustomExtClient{
|
||||||
|
@@ -106,6 +106,33 @@ func GetAllHosts() ([]models.Host, error) {
|
|||||||
return currHosts, nil
|
return currHosts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAllHostsWithStatus - returns all hosts with at least one
|
||||||
|
// node with given status.
|
||||||
|
func GetAllHostsWithStatus(status models.NodeStatus) ([]models.Host, error) {
|
||||||
|
hosts, err := GetAllHosts()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var validHosts []models.Host
|
||||||
|
for _, host := range hosts {
|
||||||
|
if len(host.Nodes) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes := GetHostNodes(&host)
|
||||||
|
for _, node := range nodes {
|
||||||
|
getNodeStatus(&node, false)
|
||||||
|
if node.Status == status {
|
||||||
|
validHosts = append(validHosts, host)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return validHosts, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetAllHostsAPI - get's all the hosts in an API usable format
|
// GetAllHostsAPI - get's all the hosts in an API usable format
|
||||||
func GetAllHostsAPI(hosts []models.Host) []models.ApiHost {
|
func GetAllHostsAPI(hosts []models.Host) []models.ApiHost {
|
||||||
apiHosts := []models.ApiHost{}
|
apiHosts := []models.ApiHost{}
|
||||||
|
@@ -512,7 +512,7 @@ func SetNodeDefaults(node *models.Node, resetConnected bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
node.SetLastModified()
|
node.SetLastModified()
|
||||||
node.SetLastCheckIn()
|
//node.SetLastCheckIn()
|
||||||
|
|
||||||
if resetConnected {
|
if resetConnected {
|
||||||
node.SetDefaultConnected()
|
node.SetDefaultConnected()
|
||||||
|
@@ -5,6 +5,7 @@ package pro
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"github.com/gravitl/netmaker/models"
|
||||||
|
|
||||||
"github.com/gravitl/netmaker/logic"
|
"github.com/gravitl/netmaker/logic"
|
||||||
)
|
)
|
||||||
@@ -26,11 +27,11 @@ func base64decode(input string) []byte {
|
|||||||
|
|
||||||
func getCurrentServerUsage() (limits Usage) {
|
func getCurrentServerUsage() (limits Usage) {
|
||||||
limits.SetDefaults()
|
limits.SetDefaults()
|
||||||
hosts, hErr := logic.GetAllHosts()
|
hosts, hErr := logic.GetAllHostsWithStatus(models.OnlineSt)
|
||||||
if hErr == nil {
|
if hErr == nil {
|
||||||
limits.Hosts = len(hosts)
|
limits.Hosts = len(hosts)
|
||||||
}
|
}
|
||||||
clients, cErr := logic.GetAllExtClients()
|
clients, cErr := logic.GetAllExtClientsWithStatus(models.OnlineSt)
|
||||||
if cErr == nil {
|
if cErr == nil {
|
||||||
limits.Clients = len(clients)
|
limits.Clients = len(clients)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user