isle/go/bootstrap/garage.go

31 lines
780 B
Go
Raw Normal View History

package bootstrap
import (
"isle/garage"
)
// GarageNodes returns a Node for each known garage instance in the network.
func (b Bootstrap) GarageNodes() []garage.RemoteNode {
var nodes []garage.RemoteNode
for _, host := range b.Hosts {
nodes = append(nodes, host.GarageNodes()...)
}
return nodes
}
// ChooseGarageNode returns a RemoteNode for a garage instance from the network.
// It will prefer a garage instance on this particular host, if there is one,
// but will otherwise return a random endpoint.
func (b Bootstrap) ChooseGarageNode() garage.RemoteNode {
thisHost := b.ThisHost()
2022-11-05 15:55:17 +00:00
if len(thisHost.Garage.Instances) > 0 {
return thisHost.GarageNodes()[0]
}
for _, node := range b.GarageNodes() {
return node
}
panic("no garage instances configured")
}