Skip to content

Commit

Permalink
libnetwork/etchosts: add GetNetworkHostEntries()
Browse files Browse the repository at this point in the history
Add function to get all host entries from a given network status.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Apr 19, 2022
1 parent 85bda3a commit 65a15c3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libnetwork/etchosts/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,18 @@ func getLocalIP() string {
}
return ip
}

// GetNetworkHostEntries returns HostEntries for all ips in the network status
// with the given hostnames.
func GetNetworkHostEntries(netStatus map[string]types.StatusBlock, names ...string) HostEntries {
hostEntries := make(HostEntries, 0, len(netStatus))
for _, status := range netStatus {
for _, netInt := range status.Interfaces {
for _, netAddress := range netInt.Subnets {
e := HostEntry{IP: netAddress.IPNet.IP.String(), Names: names}
hostEntries = append(hostEntries, e)
}
}
}
return hostEntries
}

0 comments on commit 65a15c3

Please sign in to comment.