From e3a3d65901277f7546535e4976d57a30c1188afd Mon Sep 17 00:00:00 2001 From: Gerrit91 Date: Mon, 6 May 2024 15:54:57 +0200 Subject: [PATCH] Remove size try command. --- cmd/size.go | 52 +----------------------------------- cmd/size_test.go | 12 ++++----- cmd/tableprinters/printer.go | 4 --- cmd/tableprinters/size.go | 32 ---------------------- docs/metalctl_size.md | 1 - docs/metalctl_size_try.md | 49 --------------------------------- 6 files changed, 7 insertions(+), 143 deletions(-) delete mode 100644 docs/metalctl_size_try.md diff --git a/cmd/size.go b/cmd/size.go index 69dc7f4c..7c68a1a7 100644 --- a/cmd/size.go +++ b/cmd/size.go @@ -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" @@ -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", @@ -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) { @@ -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 { diff --git a/cmd/size_test.go b/cmd/size_test.go index 97030b5f..49745c94 100644 --- a/cmd/size_test.go +++ b/cmd/size_test.go @@ -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) @@ -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", diff --git a/cmd/tableprinters/printer.go b/cmd/tableprinters/printer.go index 8b617100..10500af1 100644 --- a/cmd/tableprinters/printer.go +++ b/cmd/tableprinters/printer.go @@ -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: diff --git a/cmd/tableprinters/size.go b/cmd/tableprinters/size.go index 1f647199..cd8c34a4 100644 --- a/cmd/tableprinters/size.go +++ b/cmd/tableprinters/size.go @@ -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"} diff --git a/docs/metalctl_size.md b/docs/metalctl_size.md index 82be6d15..790c38a6 100644 --- a/docs/metalctl_size.md +++ b/docs/metalctl_size.md @@ -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 diff --git a/docs/metalctl_size_try.md b/docs/metalctl_size_try.md deleted file mode 100644 index 156d5f19..00000000 --- a/docs/metalctl_size_try.md +++ /dev/null @@ -1,49 +0,0 @@ -## metalctl size try - -try a specific hardware spec and give the chosen size back - -``` -metalctl size try [flags] -``` - -### Options - -``` - -C, --cores int32 Cores of the hardware to try - -h, --help help for try - -M, --memory string Memory of the hardware to try, can be given in bytes or any human readable size spec - -S, --storagesize string Total storagesize of the hardware to try, can be given in bytes or any human readable size spec -``` - -### Options inherited from parent commands - -``` - --api-token string api token to authenticate. Can be specified with METALCTL_API_TOKEN environment variable. - --api-url string api server address. Can be specified with METALCTL_API_URL environment variable. - -c, --config string alternative config file path, (default is ~/.metalctl/config.yaml). - Example config.yaml: - - --- - apitoken: "alongtoken" - ... - - - --debug debug output - --force-color force colored output even without tty - --kubeconfig string Path to the kube-config to use for authentication and authorization. Is updated by login. Uses default path if not specified. - --no-headers do not print headers of table output format (default print headers) - -o, --output-format string output format (table|wide|markdown|json|yaml|template), wide is a table with more columns. (default "table") - --template string output template for template output-format, go template format. - For property names inspect the output of -o json or -o yaml for reference. - Example for machines: - - metalctl machine list -o template --template "{{ .id }}:{{ .size.id }}" - - - --yes-i-really-mean-it skips security prompts (which can be dangerous to set blindly because actions can lead to data loss or additional costs) -``` - -### SEE ALSO - -* [metalctl size](metalctl_size.md) - manage size entities -