fetch related hosts on relay creation to enable proxy

This commit is contained in:
Abhishek Kondur
2023-01-10 18:54:52 +05:30
parent beb0b1adf2
commit 01d28e6483
3 changed files with 34 additions and 24 deletions

View File

@@ -295,3 +295,26 @@ func GetHostNetworks(hostID string) []string {
}
return nets
}
// GetRelatedHosts - fetches related hosts of a given host
func GetRelatedHosts(hostID string) []models.Host {
relatedHosts := []models.Host{}
networks := GetHostNetworks(hostID)
networkMap := make(map[string]struct{})
for _, network := range networks {
networkMap[network] = struct{}{}
}
hosts, err := GetAllHosts()
if err == nil {
for _, host := range hosts {
networks := GetHostNetworks(host.ID.String())
for _, network := range networks {
if _, ok := networkMap[network]; ok {
relatedHosts = append(relatedHosts, host)
break
}
}
}
}
return relatedHosts
}