diff --git a/cmd/partition_test.go b/cmd/partition_test.go index 43b2d317..389954b6 100644 --- a/cmd/partition_test.go +++ b/cmd/partition_test.go @@ -270,16 +270,16 @@ func Test_PartitionCapacityCmd(t *testing.T) { Name: "partition-1", Servers: []*models.V1ServerCapacity{ { - Allocated: pointer.Pointer(int32(1)), - Faulty: pointer.Pointer(int32(2)), + Allocated: 1, + Faulty: 2, Faultymachines: []string{"abc"}, - Free: pointer.Pointer(int32(3)), - Other: pointer.Pointer(int32(4)), + Free: 3, + Other: 4, Othermachines: []string{"def"}, Size: pointer.Pointer("size-1"), - Total: pointer.Pointer(int32(5)), - Reservations: pointer.Pointer(int32(3)), - Usedreservations: pointer.Pointer(int32(1)), + Total: 5, + Reservations: 3, + Usedreservations: 1, }, }, }, @@ -294,16 +294,16 @@ func Test_PartitionCapacityCmd(t *testing.T) { Name: "partition-1", Servers: []*models.V1ServerCapacity{ { - Allocated: pointer.Pointer(int32(1)), - Faulty: pointer.Pointer(int32(2)), + Allocated: 1, + Faulty: 2, Faultymachines: []string{"abc"}, - Free: pointer.Pointer(int32(3)), - Other: pointer.Pointer(int32(4)), + Free: 3, + Other: 4, Othermachines: []string{"def"}, Size: pointer.Pointer("size-1"), - Total: pointer.Pointer(int32(5)), - Reservations: pointer.Pointer(int32(3)), - Usedreservations: pointer.Pointer(int32(1)), + Total: 5, + Reservations: 3, + Usedreservations: 1, }, }, }, @@ -349,16 +349,16 @@ Total 5 3 1 1/3 4 2 Name: "partition-1", Servers: []*models.V1ServerCapacity{ { - Allocated: pointer.Pointer(int32(1)), - Faulty: pointer.Pointer(int32(2)), + Allocated: 1, + Faulty: 2, Faultymachines: []string{"abc"}, - Free: pointer.Pointer(int32(3)), - Other: pointer.Pointer(int32(4)), + Free: 3, + Other: 4, Othermachines: []string{"def"}, Size: pointer.Pointer("size-1"), - Total: pointer.Pointer(int32(5)), - Reservations: pointer.Pointer(int32(3)), - Usedreservations: pointer.Pointer(int32(1)), + Total: 5, + Reservations: 3, + Usedreservations: 1, }, }, }, @@ -373,16 +373,16 @@ Total 5 3 1 1/3 4 2 Name: "partition-1", Servers: []*models.V1ServerCapacity{ { - Allocated: pointer.Pointer(int32(1)), - Faulty: pointer.Pointer(int32(2)), + Allocated: 1, + Faulty: 2, Faultymachines: []string{"abc"}, - Free: pointer.Pointer(int32(3)), - Other: pointer.Pointer(int32(4)), + Free: 3, + Other: 4, Othermachines: []string{"def"}, Size: pointer.Pointer("size-1"), - Total: pointer.Pointer(int32(5)), - Reservations: pointer.Pointer(int32(3)), - Usedreservations: pointer.Pointer(int32(1)), + Total: 5, + Reservations: 3, + Usedreservations: 1, }, }, }, diff --git a/cmd/tableprinters/partition.go b/cmd/tableprinters/partition.go index 14fd6cf4..8adde9e3 100644 --- a/cmd/tableprinters/partition.go +++ b/cmd/tableprinters/partition.go @@ -37,18 +37,25 @@ func (t *TablePrinter) PartitionTable(data []*models.V1PartitionResponse, wide b func (t *TablePrinter) PartitionCapacityTable(data []*models.V1PartitionCapacity, wide bool) ([]string, [][]string, error) { var ( - header = []string{"Partition", "Size", "Total", "Free", "Allocated", "Reserved", "Other", "Faulty"} + header = []string{"Partition", "Size", "Allocated", "Free", "Unavailable", "Reservations", "|", "Total", "|", "Faulty"} rows [][]string - totalCount int32 - freeCount int32 allocatedCount int32 faultyCount int32 + freeCount int32 otherCount int32 + phonedHomeCount int32 reservationCount int32 + totalCount int32 + unavailableCount int32 usedReservationCount int32 + waitingCount int32 ) + if wide { + header = append(header, "Phoned Home", "Waiting", "Other") + } + for _, pc := range data { pc := pc @@ -56,45 +63,62 @@ func (t *TablePrinter) PartitionCapacityTable(data []*models.V1PartitionCapacity id := pointer.SafeDeref(c.Size) var ( - allocated = fmt.Sprintf("%d", pointer.SafeDeref(c.Allocated)) - total = fmt.Sprintf("%d", pointer.SafeDeref(c.Total)) - free = fmt.Sprintf("%d", pointer.SafeDeref(c.Free)) - faulty = fmt.Sprintf("%d", pointer.SafeDeref(c.Faulty)) - other = fmt.Sprintf("%d", pointer.SafeDeref(c.Other)) - reservations = fmt.Sprintf("%d/%d", pointer.SafeDeref(c.Usedreservations), pointer.SafeDeref(c.Reservations)) + allocated = fmt.Sprintf("%d", c.Allocated) + faulty = fmt.Sprintf("%d", c.Faulty) + free = fmt.Sprintf("%d", c.Free) + other = fmt.Sprintf("%d", c.Other) + phonedHome = fmt.Sprintf("%d", c.PhonedHome) + reservations = "0" + total = fmt.Sprintf("%d", c.Total) + unavailable = fmt.Sprintf("%d", c.Unavailable) + waiting = fmt.Sprintf("%d", c.Waiting) ) - if wide { - if len(c.Faultymachines) > 0 { - faulty = strings.Join(c.Faultymachines, "\n") - } - if len(c.Othermachines) > 0 { - other = strings.Join(c.Othermachines, "\n") - } + if c.Reservations > 0 { + reservations = fmt.Sprintf("%d (%d/%d used)", c.Reservations-c.Usedreservations, c.Usedreservations, c.Reservations) } - totalCount += pointer.SafeDeref(c.Total) - freeCount += pointer.SafeDeref(c.Free) - allocatedCount += pointer.SafeDeref(c.Allocated) - otherCount += pointer.SafeDeref(c.Other) - faultyCount += pointer.SafeDeref(c.Faulty) - reservationCount += pointer.SafeDeref(c.Reservations) - usedReservationCount += pointer.SafeDeref(c.Usedreservations) + allocatedCount += c.Allocated + faultyCount += c.Faulty + freeCount += c.Free + otherCount += c.Other + phonedHomeCount += c.PhonedHome + reservationCount += c.Reservations + totalCount += c.Total + unavailableCount += c.Unavailable + usedReservationCount += c.Usedreservations + waitingCount += c.Waiting + + row := []string{*pc.ID, id, allocated, free, unavailable, reservations, "|", total, "|", faulty} + if wide { + row = append(row, phonedHome, waiting, other) + } - rows = append(rows, []string{*pc.ID, id, total, free, allocated, reservations, other, faulty}) + rows = append(rows, row) } } footerRow := ([]string{ - "Total", + "Σ", "", - fmt.Sprintf("%d", totalCount), - fmt.Sprintf("%d", freeCount), fmt.Sprintf("%d", allocatedCount), - fmt.Sprintf("%d/%d", usedReservationCount, reservationCount), - fmt.Sprintf("%d", otherCount), + fmt.Sprintf("%d", freeCount), + fmt.Sprintf("%d", unavailableCount), + fmt.Sprintf("%d", reservationCount-usedReservationCount), + "|", + fmt.Sprintf("%d", totalCount), + "|", fmt.Sprintf("%d", faultyCount), }) + + if wide { + footerRow = append(footerRow, []string{ + fmt.Sprintf("%d", phonedHomeCount), + fmt.Sprintf("%d", waitingCount), + fmt.Sprintf("%d", otherCount), + }...) + } + rows = append(rows, footerRow) return header, rows, nil diff --git a/go.mod b/go.mod index 977b2eec..87e74c7c 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/go-openapi/strfmt v0.23.0 github.com/google/go-cmp v0.6.0 github.com/google/uuid v1.6.0 - github.com/metal-stack/metal-go v0.32.2 + github.com/metal-stack/metal-go v0.32.4-0.20240730135831-fe6be460a83e github.com/metal-stack/metal-lib v0.17.1 github.com/metal-stack/updater v1.2.2 github.com/metal-stack/v v1.0.3 diff --git a/go.sum b/go.sum index 3719e854..dedfbd34 100644 --- a/go.sum +++ b/go.sum @@ -235,8 +235,8 @@ github.com/mdlayher/sdnotify v1.0.0 h1:Ma9XeLVN/l0qpyx1tNeMSeTjCPH6NtuD6/N9XdTlQ github.com/mdlayher/sdnotify v1.0.0/go.mod h1:HQUmpM4XgYkhDLtd+Uad8ZFK1T9D5+pNxnXQjCeJlGE= github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos= github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ= -github.com/metal-stack/metal-go v0.32.2 h1:vD1LtGVAeLx9vrPrguPBchXYsp7/oZ5MfTnfUO/yMz0= -github.com/metal-stack/metal-go v0.32.2/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ= +github.com/metal-stack/metal-go v0.32.4-0.20240730135831-fe6be460a83e h1:pecYgPnB1uZjemB2YaR4ZVNrK/p5n6aGuvFpNzPuDhA= +github.com/metal-stack/metal-go v0.32.4-0.20240730135831-fe6be460a83e/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ= github.com/metal-stack/metal-lib v0.17.1 h1:JLa4wJ62dgxtY9UOLF+QDk10/i/W5vhzrv8RsundDUY= github.com/metal-stack/metal-lib v0.17.1/go.mod h1:nyNGI4DZFOcWbSoq2Y6V3SHpFxuXBIqYBZHTb6cy//s= github.com/metal-stack/security v0.8.0 h1:tVaSDB9m5clwYrnLyaXfPy7mQlJTnmeoHscG+RUy/xo=