2022-10-15 14:28:03 +00:00
|
|
|
package bootstrap
|
|
|
|
|
|
|
|
import (
|
2023-08-05 21:53:17 +00:00
|
|
|
"isle/garage"
|
2022-10-15 14:28:03 +00:00
|
|
|
)
|
|
|
|
|
2024-11-08 16:46:44 +00:00
|
|
|
// GarageNodes returns a Node for each known garage instance in the network.
|
|
|
|
func (b Bootstrap) GarageNodes() []garage.RemoteNode {
|
|
|
|
var nodes []garage.RemoteNode
|
2022-10-15 14:28:03 +00:00
|
|
|
for _, host := range b.Hosts {
|
2024-11-08 16:46:44 +00:00
|
|
|
nodes = append(nodes, host.GarageNodes()...)
|
2022-10-15 14:28:03 +00:00
|
|
|
}
|
2024-11-08 16:46:44 +00:00
|
|
|
return nodes
|
2022-10-15 14:28:03 +00:00
|
|
|
}
|
|
|
|
|
2024-11-08 16:46:44 +00:00
|
|
|
// 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 {
|
2022-10-16 13:38:15 +00:00
|
|
|
thisHost := b.ThisHost()
|
2022-11-05 15:55:17 +00:00
|
|
|
if len(thisHost.Garage.Instances) > 0 {
|
2024-11-08 16:46:44 +00:00
|
|
|
return thisHost.GarageNodes()[0]
|
2022-10-16 13:38:15 +00:00
|
|
|
}
|
|
|
|
|
2024-11-08 16:46:44 +00:00
|
|
|
for _, node := range b.GarageNodes() {
|
|
|
|
return node
|
2022-10-16 13:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
panic("no garage instances configured")
|
|
|
|
}
|