Implement 'storage list-allocation(s)'
This commit is contained in:
parent
070524f686
commit
1d02c1f6a0
@ -59,6 +59,7 @@ func main() {
|
||||
subCmdHost,
|
||||
subCmdNebula,
|
||||
subCmdNetwork,
|
||||
subCmdStorage,
|
||||
subCmdVersion,
|
||||
)
|
||||
|
||||
|
54
go/cmd/entrypoint/storage.go
Normal file
54
go/cmd/entrypoint/storage.go
Normal 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,
|
||||
)
|
||||
},
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user