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
|
|
|
)
|
|
|
|
|
|
|
|
// GaragePeers returns a Peer for each known garage instance in the network.
|
2022-10-28 22:09:18 +00:00
|
|
|
func (b Bootstrap) GaragePeers() []garage.RemotePeer {
|
2022-10-15 14:28:03 +00:00
|
|
|
|
2022-10-28 22:09:18 +00:00
|
|
|
var peers []garage.RemotePeer
|
2022-10-15 14:28:03 +00:00
|
|
|
|
|
|
|
for _, host := range b.Hosts {
|
|
|
|
|
|
|
|
for _, instance := range host.Garage.Instances {
|
|
|
|
|
2022-10-28 22:09:18 +00:00
|
|
|
peer := garage.RemotePeer{
|
|
|
|
ID: instance.ID,
|
2022-10-29 19:11:40 +00:00
|
|
|
IP: host.IP().String(),
|
2022-10-15 14:28:03 +00:00
|
|
|
RPCPort: instance.RPCPort,
|
|
|
|
S3APIPort: instance.S3APIPort,
|
|
|
|
}
|
|
|
|
|
|
|
|
peers = append(peers, peer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return peers
|
|
|
|
}
|
|
|
|
|
2022-10-16 13:38:15 +00:00
|
|
|
// ChooseGaragePeer returns a Peer 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.
|
2022-10-28 22:09:18 +00:00
|
|
|
func (b Bootstrap) ChooseGaragePeer() garage.RemotePeer {
|
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 {
|
2022-10-29 19:11:40 +00:00
|
|
|
|
2022-10-16 13:38:15 +00:00
|
|
|
inst := thisHost.Garage.Instances[0]
|
2022-10-28 22:09:18 +00:00
|
|
|
return garage.RemotePeer{
|
|
|
|
ID: inst.ID,
|
2022-10-29 19:11:40 +00:00
|
|
|
IP: thisHost.IP().String(),
|
2022-10-16 13:38:15 +00:00
|
|
|
RPCPort: inst.RPCPort,
|
|
|
|
S3APIPort: inst.S3APIPort,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, peer := range b.GaragePeers() {
|
|
|
|
return peer
|
|
|
|
}
|
|
|
|
|
|
|
|
panic("no garage instances configured")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GlobalBucketS3APIClient returns an S3 client pre-configured with access to
|
|
|
|
// the global bucket.
|
2022-10-19 14:53:31 +00:00
|
|
|
func (b Bootstrap) GlobalBucketS3APIClient() garage.S3APIClient {
|
2022-10-16 13:38:15 +00:00
|
|
|
addr := b.ChooseGaragePeer().S3APIAddr()
|
2022-11-02 13:34:40 +00:00
|
|
|
creds := b.Garage.GlobalBucketS3APICredentials
|
2022-10-19 14:53:31 +00:00
|
|
|
return garage.NewS3APIClient(addr, creds)
|
2022-10-16 13:38:15 +00:00
|
|
|
}
|