Skip to content

Commit

Permalink
Remove size try command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed May 6, 2024
1 parent 6d78cfd commit e3a3d65
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 143 deletions.
52 changes: 1 addition & 51 deletions cmd/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"time"

"github.com/dustin/go-humanize"
"github.com/go-openapi/strfmt"
"github.com/google/uuid"
"github.com/metal-stack/metal-go/api/client/size"
Expand Down Expand Up @@ -63,18 +62,6 @@ func newSizeCmd(c *config) *cobra.Command {
},
}

tryCmd := &cobra.Command{
Use: "try",
Short: "try a specific hardware spec and give the chosen size back",
RunE: func(cmd *cobra.Command, args []string) error {
return w.try()
},
}

tryCmd.Flags().Int32P("cores", "C", 0, "Cores of the hardware to try")
tryCmd.Flags().StringP("memory", "M", "", "Memory of the hardware to try, can be given in bytes or any human readable size spec")
tryCmd.Flags().StringP("storagesize", "S", "", "Total storagesize of the hardware to try, can be given in bytes or any human readable size spec")

reservationsCmd := &cobra.Command{
Use: "reservations",
Short: "manage size reservations",
Expand Down Expand Up @@ -111,7 +98,7 @@ func newSizeCmd(c *config) *cobra.Command {

must(suggestCmd.RegisterFlagCompletionFunc("machine-id", c.comp.MachineListCompletion))

return genericcli.NewCmds(cmdsConfig, newSizeImageConstraintCmd(c), tryCmd, reservationsCmd, suggestCmd)
return genericcli.NewCmds(cmdsConfig, newSizeImageConstraintCmd(c), reservationsCmd, suggestCmd)
}

func (c sizeCmd) Get(id string) (*models.V1SizeResponse, error) {
Expand Down Expand Up @@ -210,43 +197,6 @@ func sizeResponseToUpdate(r *models.V1SizeResponse) *models.V1SizeUpdateRequest

// non-generic command handling

func (c *sizeCmd) try() error {
var (
memory int64
disks []*models.V1MachineBlockDevice
)

if viper.IsSet("memory") {
m, err := humanize.ParseBytes(viper.GetString("memory"))
if err != nil {
return err
}
memory = int64(m)
}

if viper.IsSet("storagesize") {
s, err := humanize.ParseBytes(viper.GetString("storagesize"))
if err != nil {
return err
}
disks = append(disks, &models.V1MachineBlockDevice{
Name: pointer.Pointer("/dev/trydisk"),
Size: pointer.Pointer(int64(s)),
})
}

resp, err := c.client.Size().FromHardware(size.NewFromHardwareParams().WithBody(&models.V1MachineHardware{
CPUCores: pointer.Pointer(viper.GetInt32("cores")),
Memory: &memory,
Disks: disks,
}), nil)
if err != nil {
return err
}

return c.listPrinter.Print(resp.Payload)
}

func (c sizeCmd) listReverations() error {
resp, err := c.client.Size().ListSizeReservations(size.NewListSizeReservationsParams().WithBody(emptyBody), nil)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions cmd/size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,17 @@ ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RA
{
Max: int64(2),
Min: int64(1),
Type: pointer.Pointer("storage"),
Type: pointer.Pointer(models.V1SizeConstraintTypeStorage),
},
{
Max: int64(4),
Min: int64(3),
Type: pointer.Pointer("memory"),
Type: pointer.Pointer(models.V1SizeConstraintTypeMemory),
},
{
Max: int64(6),
Min: int64(5),
Type: pointer.Pointer("cores"),
Type: pointer.Pointer(models.V1SizeConstraintTypeCores),
},
},
}, nil)
Expand All @@ -336,17 +336,17 @@ ID NAME DESCRIPTION RESERVATIONS CPU RANGE MEMORY RANGE STORAGE RA
{
Max: int64(2),
Min: int64(1),
Type: pointer.Pointer("storage"),
Type: pointer.Pointer(models.V1SizeConstraintTypeStorage),
},
{
Max: int64(4),
Min: int64(3),
Type: pointer.Pointer("memory"),
Type: pointer.Pointer(models.V1SizeConstraintTypeMemory),
},
{
Max: int64(6),
Min: int64(5),
Type: pointer.Pointer("cores"),
Type: pointer.Pointer(models.V1SizeConstraintTypeCores),
},
},
Description: "foo",
Expand Down
4 changes: 0 additions & 4 deletions cmd/tableprinters/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ func (t *TablePrinter) ToHeaderAndRows(data any, wide bool) ([]string, [][]strin
return t.SizeTable(pointer.WrapInSlice(d), wide)
case []*models.V1SizeResponse:
return t.SizeTable(d, wide)
case *models.V1SizeMatchingLog:
return t.SizeMatchingLogTable(pointer.WrapInSlice(d), wide)
case []*models.V1SizeMatchingLog:
return t.SizeMatchingLogTable(d, wide)
case *models.V1SizeReservationResponse:
return t.SizeReservationTable(pointer.WrapInSlice(d), wide)
case []*models.V1SizeReservationResponse:
Expand Down
32 changes: 0 additions & 32 deletions cmd/tableprinters/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,38 +63,6 @@ func (t *TablePrinter) SizeTable(data []*models.V1SizeResponse, wide bool) ([]st
return header, rows, nil
}

func (t *TablePrinter) SizeMatchingLogTable(data []*models.V1SizeMatchingLog, wide bool) ([]string, [][]string, error) {
var (
header = []string{"Name", "Match", "CPU Constraint", "Memory Constraint", "Storage Constraint"}
rows [][]string
)

for _, d := range data {
var cpu, memory, storage string
for _, cs := range d.Constraints {
c := cs.Constraint
switch *c.Type {
case "cores": // TODO: should be enums in spec
cpu = fmt.Sprintf("%d - %d\n%s\nmatches: %v", c.Min, c.Max, *cs.Log, *cs.Match)
case "memory":
memory = fmt.Sprintf("%s - %s\n%s\nmatches: %v", humanize.Bytes(uint64(c.Min)), humanize.Bytes(uint64(c.Max)), *cs.Log, *cs.Match)
case "storage":
storage = fmt.Sprintf("%s - %s\n%s\nmatches: %v", humanize.Bytes(uint64(c.Min)), humanize.Bytes(uint64(c.Max)), *cs.Log, *cs.Match)
}
}
sizeMatch := fmt.Sprintf("%v", *d.Match)

rows = append(rows, []string{*d.Name, sizeMatch, cpu, memory, storage})
}

t.t.MutateTable(func(table *tablewriter.Table) {
table.SetAutoWrapText(false)
table.SetColMinWidth(3, 40)
})

return header, rows, nil
}

func (t *TablePrinter) SizeReservationTable(data []*models.V1SizeReservationResponse, wide bool) ([]string, [][]string, error) {
var (
header = []string{"Partition", "Size", "Tenant", "Project", "Project Name", "Used/Amount", "Project Allocations"}
Expand Down
1 change: 0 additions & 1 deletion docs/metalctl_size.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ a size matches a machine in terms of cpu cores, ram and storage.
* [metalctl size list](metalctl_size_list.md) - list all sizes
* [metalctl size reservations](metalctl_size_reservations.md) - manage size reservations
* [metalctl size suggest](metalctl_size_suggest.md) - suggest size from a given machine id
* [metalctl size try](metalctl_size_try.md) - try a specific hardware spec and give the chosen size back
* [metalctl size update](metalctl_size_update.md) - updates the size

49 changes: 0 additions & 49 deletions docs/metalctl_size_try.md

This file was deleted.

0 comments on commit e3a3d65

Please sign in to comment.