package daemon import ( "context" "isle/bootstrap" "isle/daemon/daecommon" "net" "strconv" "isle/garage" "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) func garageAdminClientLogger(logger *mlog.Logger) *mlog.Logger { return logger.WithNamespace("garageAdminClient") } // newGarageAdminClient will return an AdminClient for a local garage instance, // or it will _panic_ if there is no local instance configured. func newGarageAdminClient( logger *mlog.Logger, daemonConfig daecommon.Config, adminToken string, hostBootstrap bootstrap.Bootstrap, ) *garage.AdminClient { thisHost := hostBootstrap.ThisHost() return garage.NewAdminClient( garageAdminClientLogger(logger), net.JoinHostPort( thisHost.IP().String(), strconv.Itoa(daemonConfig.Storage.Allocations[0].AdminPort), ), adminToken, ) } func garageApplyLayout( ctx context.Context, logger *mlog.Logger, daemonConfig daecommon.Config, adminToken string, hostBootstrap bootstrap.Bootstrap, ) error { var ( adminClient = newGarageAdminClient( logger, daemonConfig, adminToken, hostBootstrap, ) thisHost = hostBootstrap.ThisHost() hostName = thisHost.Name allocs = daemonConfig.Storage.Allocations peers = make([]garage.PeerLayout, len(allocs)) ) for i, alloc := range allocs { id := daecommon.BootstrapGarageHostForAlloc(thisHost, alloc).ID zone := string(hostName) if alloc.Zone != "" { zone = alloc.Zone } peers[i] = garage.PeerLayout{ ID: id, Capacity: alloc.Capacity * 1_000_000_000, Zone: zone, Tags: []string{}, } } return adminClient.ApplyLayout(ctx, peers) }