Browse Source

added function to get default hosts

0xdcarns 2 years ago
parent
commit
2b3747cc33
1 changed files with 15 additions and 0 deletions
  1. 15 0
      logic/hosts.go

+ 15 - 0
logic/hosts.go

@@ -246,3 +246,18 @@ func DissasociateNodeFromHost(n *models.Node, h *models.Host) error {
 	h.Nodes = RemoveStringSlice(h.Nodes, index)
 	return UpsertHost(h)
 }
+
+// GetDefaultHosts - retrieve all hosts marked as default from DB
+func GetDefaultHosts() []models.Host {
+	defaultHostList := []models.Host{}
+	hosts, err := GetAllHosts()
+	if err != nil {
+		return defaultHostList
+	}
+	for i := range hosts {
+		if hosts[i].IsDefault {
+			defaultHostList = append(defaultHostList, hosts[i])
+		}
+	}
+	return defaultHostList[:]
+}