From 1d02c1f6a05bd9833bed25c5f7a78297357461a9 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Thu, 14 Nov 2024 20:55:15 +0100 Subject: [PATCH] Implement 'storage list-allocation(s)' --- go/cmd/entrypoint/main.go | 1 + go/cmd/entrypoint/storage.go | 54 ++++++++++++++++++++++++++++++++++++ go/daemon/network/network.go | 3 +- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 go/cmd/entrypoint/storage.go diff --git a/go/cmd/entrypoint/main.go b/go/cmd/entrypoint/main.go index ca33e0c..522ac16 100644 --- a/go/cmd/entrypoint/main.go +++ b/go/cmd/entrypoint/main.go @@ -59,6 +59,7 @@ func main() { subCmdHost, subCmdNebula, subCmdNetwork, + subCmdStorage, subCmdVersion, ) diff --git a/go/cmd/entrypoint/storage.go b/go/cmd/entrypoint/storage.go new file mode 100644 index 0000000..bca78e1 --- /dev/null +++ b/go/cmd/entrypoint/storage.go @@ -0,0 +1,54 @@ +package main + +import ( + "cmp" + "fmt" + "isle/daemon/daecommon" + "slices" +) + +var subCmdStorageAllocationList = subCmd{ + name: "list-allocation", + plural: "s", + descr: "Lists all storage which is currently allocated on this host", + do: doWithOutput(func(ctx subCmdCtx) (any, error) { + ctx, err := ctx.withParsedFlags() + if err != nil { + return nil, fmt.Errorf("parsing flags: %w", err) + } + + config, err := newDaemonRPCClient().GetConfig(ctx) + if err != nil { + return nil, fmt.Errorf("getting network config: %w", err) + } + + type alloc struct { + Index int `yaml:"index"` + daecommon.ConfigStorageAllocation `yaml:",inline"` + } + + slices.SortFunc( + config.Storage.Allocations, + func(i, j daecommon.ConfigStorageAllocation) int { + return cmp.Compare(i.RPCPort, j.RPCPort) + }, + ) + + allocs := make([]alloc, len(config.Storage.Allocations)) + for i := range config.Storage.Allocations { + allocs[i] = alloc{i, config.Storage.Allocations[i]} + } + + return allocs, nil + }), +} + +var subCmdStorage = subCmd{ + name: "storage", + descr: "Sub-commands having to do with configuration of storage on this host", + do: func(ctx subCmdCtx) error { + return ctx.doSubCmd( + subCmdStorageAllocationList, + ) + }, +} diff --git a/go/daemon/network/network.go b/go/daemon/network/network.go index 9b2e3f0..fc96f62 100644 --- a/go/daemon/network/network.go +++ b/go/daemon/network/network.go @@ -105,8 +105,7 @@ type RPC interface { // existing host, given the public key for that host. This is currently // mostly useful for creating certs for mobile devices. // - // TODO replace this with CreateHostBootstrap, and the - // CreateNebulaCertificate RPC method can just pull cert out of that. + // TODO Specific error for if required secret isn't present. // // Errors: // - ErrHostNotFound