Implement 'storage list-allocation(s)'

This commit is contained in:
Brian Picciano 2024-11-14 20:55:15 +01:00
parent 070524f686
commit 1d02c1f6a0
3 changed files with 56 additions and 2 deletions

View File

@ -59,6 +59,7 @@ func main() {
subCmdHost, subCmdHost,
subCmdNebula, subCmdNebula,
subCmdNetwork, subCmdNetwork,
subCmdStorage,
subCmdVersion, subCmdVersion,
) )

View File

@ -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,
)
},
}

View File

@ -105,8 +105,7 @@ type RPC interface {
// existing host, given the public key for that host. This is currently // existing host, given the public key for that host. This is currently
// mostly useful for creating certs for mobile devices. // mostly useful for creating certs for mobile devices.
// //
// TODO replace this with CreateHostBootstrap, and the // TODO Specific error for if required secret isn't present.
// CreateNebulaCertificate RPC method can just pull cert out of that.
// //
// Errors: // Errors:
// - ErrHostNotFound // - ErrHostNotFound