Use RPC for create-bootstrap

This commit is contained in:
Brian Picciano 2024-07-09 15:14:29 +02:00
parent 279c79a9f1
commit 1ee396c976
6 changed files with 31 additions and 18 deletions

View File

@ -104,12 +104,14 @@ var subCmdAdminCreateBootstrap = subCmd{
return fmt.Errorf("initializing bootstrap data: %w", err)
}
hostBootstrap, err := loadHostBootstrap()
hostsRes, err := subCmdCtx.getHosts()
if err != nil {
return fmt.Errorf("loading host bootstrap: %w", err)
return fmt.Errorf("getting hosts: %w", err)
}
newHostBootstrap.Hosts = hostBootstrap.Hosts
for _, host := range hostsRes.Hosts {
newHostBootstrap.Hosts[host.Name] = host
}
return newHostBootstrap.WriteTo(os.Stdout)
},

View File

@ -0,0 +1,15 @@
package main
import (
"fmt"
"isle/daemon"
)
func (ctx subCmdCtx) getHosts() (daemon.GetHostsResult, error) {
var res daemon.GetHostsResult
err := ctx.daemonRCPClient.Call(ctx.ctx, &res, "GetHosts", nil)
if err != nil {
return daemon.GetHostsResult{}, fmt.Errorf("calling GetHosts: %w", err)
}
return res, nil
}

View File

@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"isle/bootstrap"
"isle/daemon"
"isle/jsonutil"
"os"
"regexp"
@ -26,11 +25,7 @@ var subCmdHostsList = subCmd{
name: "list",
descr: "Lists all hosts in the network, and their IPs",
do: func(subCmdCtx subCmdCtx) error {
ctx := subCmdCtx.ctx
var res daemon.GetHostsResult
err := subCmdCtx.daemonRCPClient.Call(ctx, &res, "GetHosts", nil)
hostsRes, err := subCmdCtx.getHosts()
if err != nil {
return fmt.Errorf("calling GetHosts: %w", err)
}
@ -43,8 +38,8 @@ var subCmdHostsList = subCmd{
Storage bootstrap.GarageHost `json:",omitempty"`
}
hosts := make([]host, 0, len(res.Hosts))
for _, h := range res.Hosts {
hosts := make([]host, 0, len(hostsRes.Hosts))
for _, h := range hostsRes.Hosts {
host := host{
Name: h.Name,

View File

@ -61,9 +61,8 @@ type Daemon interface {
// - ErrAlreadyJoined
JoinNetwork(context.Context, bootstrap.Bootstrap) error
// GetGarageBootstrapHosts loads (and verifies) the <hostname>.json.signed
// file for all hosts stored in garage.
GetGarageBootstrapHosts(
// GetBootstrapHosts returns the hosts stored in the bootstrap.
GetBootstrapHosts(
ctx context.Context,
) (
map[string]bootstrap.Host, error,
@ -594,7 +593,7 @@ func (d *daemon) JoinNetwork(
}
}
func (d *daemon) GetGarageBootstrapHosts(
func (d *daemon) GetBootstrapHosts(
ctx context.Context,
) (
map[string]bootstrap.Host, error,
@ -604,7 +603,7 @@ func (d *daemon) GetGarageBootstrapHosts(
) (
map[string]bootstrap.Host, error,
) {
return getGarageBootstrapHosts(ctx, d.logger, currBootstrap)
return currBootstrap.Hosts, nil
})
}

View File

@ -71,7 +71,7 @@ func (r *RPC) GetHosts(
) (
GetHostsResult, error,
) {
hostsMap, err := r.daemon.GetGarageBootstrapHosts(ctx)
hostsMap, err := r.daemon.GetBootstrapHosts(ctx)
if err != nil {
return GetHostsResult{}, fmt.Errorf("retrieving hosts: %w", err)
}

View File

@ -1,7 +1,9 @@
# shellcheck source=../../utils/with-1-data-1-empty-node-network.sh
source "$UTILS"/with-1-data-1-empty-node-network.sh
as_primus
# TODO when primus creates secondus' bootstrap it should write the new host to
# its own bootstrap, as well as to garage.
as_secondus
hosts="$(isle hosts list)"
[ "$(echo "$hosts" | jq -r '.[0].Name')" = "primus" ]