2024-09-09 14:34:00 +00:00
|
|
|
package network
|
2024-06-24 16:55:36 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"isle/bootstrap"
|
2024-09-07 13:11:04 +00:00
|
|
|
"isle/daemon/daecommon"
|
2024-07-07 10:44:49 +00:00
|
|
|
"isle/garage/garagesrv"
|
2024-07-14 09:58:39 +00:00
|
|
|
"isle/jsonutil"
|
2024-09-09 14:34:00 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2024-06-24 16:55:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func writeBootstrapToStateDir(
|
|
|
|
stateDirPath string, hostBootstrap bootstrap.Bootstrap,
|
|
|
|
) error {
|
|
|
|
var (
|
|
|
|
path = bootstrap.StateDirPath(stateDirPath)
|
|
|
|
dirPath = filepath.Dir(path)
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := os.MkdirAll(dirPath, 0700); err != nil {
|
|
|
|
return fmt.Errorf("creating directory %q: %w", dirPath, err)
|
|
|
|
}
|
|
|
|
|
2024-07-14 13:50:24 +00:00
|
|
|
if err := jsonutil.WriteFile(hostBootstrap, path, 0600); err != nil {
|
2024-07-14 09:58:39 +00:00
|
|
|
return fmt.Errorf("writing bootstrap to %q: %w", path, err)
|
2024-06-24 16:55:36 +00:00
|
|
|
}
|
|
|
|
|
2024-07-14 09:58:39 +00:00
|
|
|
return nil
|
2024-06-24 16:55:36 +00:00
|
|
|
}
|
2024-07-07 10:44:49 +00:00
|
|
|
|
2024-09-10 20:51:33 +00:00
|
|
|
func coalesceNetworkConfigAndBootstrap(
|
|
|
|
networkConfig daecommon.NetworkConfig, hostBootstrap bootstrap.Bootstrap,
|
2024-07-07 10:44:49 +00:00
|
|
|
) (
|
|
|
|
bootstrap.Bootstrap, error,
|
|
|
|
) {
|
|
|
|
host := bootstrap.Host{
|
|
|
|
HostAssigned: hostBootstrap.HostAssigned,
|
|
|
|
HostConfigured: bootstrap.HostConfigured{
|
|
|
|
Nebula: bootstrap.NebulaHost{
|
2024-09-10 20:51:33 +00:00
|
|
|
PublicAddr: networkConfig.VPN.PublicAddr,
|
2024-07-07 10:44:49 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-09-10 20:51:33 +00:00
|
|
|
if allocs := networkConfig.Storage.Allocations; len(allocs) > 0 {
|
2024-07-07 10:44:49 +00:00
|
|
|
|
|
|
|
for i, alloc := range allocs {
|
|
|
|
|
|
|
|
id, rpcPort, err := garagesrv.InitAlloc(alloc.MetaPath, alloc.RPCPort)
|
|
|
|
if err != nil {
|
|
|
|
return bootstrap.Bootstrap{}, fmt.Errorf(
|
|
|
|
"initializing alloc at %q: %w", alloc.MetaPath, err,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
host.Garage.Instances = append(host.Garage.Instances, bootstrap.GarageHostInstance{
|
|
|
|
ID: id,
|
|
|
|
RPCPort: rpcPort,
|
|
|
|
S3APIPort: alloc.S3APIPort,
|
|
|
|
})
|
|
|
|
|
|
|
|
allocs[i].RPCPort = rpcPort
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hostBootstrap.Hosts[host.Name] = host
|
|
|
|
|
|
|
|
return hostBootstrap, nil
|
|
|
|
}
|