diff --git a/cmd/completion/machine.go b/cmd/completion/machine.go index a48cee9..b47ef40 100644 --- a/cmd/completion/machine.go +++ b/cmd/completion/machine.go @@ -152,3 +152,24 @@ func (c *Completion) MachineRackListCompletion(cmd *cobra.Command, args []string return names, cobra.ShellCompDirectiveNoFileComp } + +func (c *Completion) MachineRoomListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + mfr := &models.V1MachineFindRequest{} + + if cmd.Flag("partition") != nil { + if partition := cmd.Flag("partition").Value.String(); partition != "" { + mfr.PartitionID = partition + } + } + + resp, err := c.client.Machine().FindMachines(machine.NewFindMachinesParams().WithBody(mfr), nil) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + var names []string + for _, m := range resp.Payload { + names = append(names, m.Roomid) + } + + return names, cobra.ShellCompDirectiveNoFileComp +} diff --git a/cmd/completion/switch.go b/cmd/completion/switch.go index e96a026..2dee1b7 100644 --- a/cmd/completion/switch.go +++ b/cmd/completion/switch.go @@ -94,3 +94,18 @@ func (c *Completion) SwitchListPorts(cmd *cobra.Command, args []string, toComple } return names, cobra.ShellCompDirectiveNoFileComp } + +func (c *Completion) SwitchRoomListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + resp, err := c.client.SwitchOperations().ListSwitches(switch_operations.NewListSwitchesParams(), nil) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + var names []string + for _, p := range resp.Payload { + if p.RoomID == "" { + continue + } + names = append(names, p.RoomID) + } + return names, cobra.ShellCompDirectiveNoFileComp +} diff --git a/cmd/machine.go b/cmd/machine.go index d449d0e..f070a10 100644 --- a/cmd/machine.go +++ b/cmd/machine.go @@ -46,6 +46,7 @@ func (c *machineCmd) listCmdFlags(cmd *cobra.Command, lastEventErrorThresholdDef {flagName: "size", f: c.comp.SizeListCompletion}, {flagName: "project", f: c.comp.ProjectListCompletion}, {flagName: "rack", f: c.comp.MachineRackListCompletion}, + {flagName: "room", f: c.comp.MachineRoomListCompletion}, {flagName: "id", f: c.comp.MachineListCompletion}, {flagName: "image", f: c.comp.ImageListCompletion}, {flagName: "state", f: cobra.FixedCompletions([]string{ @@ -70,6 +71,7 @@ func (c *machineCmd) listCmdFlags(cmd *cobra.Command, lastEventErrorThresholdDef cmd.Flags().String("partition", "", "partition to filter [optional]") cmd.Flags().String("size", "", "size to filter [optional]") cmd.Flags().String("rack", "", "rack to filter [optional]") + cmd.Flags().String("room", "", "room to filter [optional]") cmd.Flags().String("state", "", "state to filter [optional]") cmd.Flags().String("name", "", "allocation name to filter [optional]") cmd.Flags().String("project", "", "allocation project to filter [optional]") @@ -597,6 +599,7 @@ func machineFindRequestFromCLI() *models.V1MachineFindRequest { NicsMacAddresses: macs, PartitionID: viper.GetString("partition"), Rackid: viper.GetString("rack"), + Roomid: viper.GetString("room"), Sizeid: viper.GetString("size"), StateValue: viper.GetString("state"), Tags: viper.GetStringSlice("tags"), diff --git a/cmd/switch.go b/cmd/switch.go index af331b7..b11c543 100644 --- a/cmd/switch.go +++ b/cmd/switch.go @@ -11,6 +11,7 @@ import ( "github.com/metal-stack/metal-go/api/models" "github.com/metal-stack/metal-lib/pkg/genericcli" "github.com/metal-stack/metal-lib/pkg/genericcli/printers" + "github.com/metal-stack/metalctl/cmd/sorters" "github.com/metal-stack/metalctl/cmd/tableprinters" "github.com/spf13/cobra" @@ -51,11 +52,13 @@ func newSwitchCmd(c *config) *cobra.Command { cmd.Flags().String("os-version", "", "OS version of this switch.") cmd.Flags().String("partition", "", "Partition of this switch.") cmd.Flags().String("rack", "", "Rack of this switch.") + cmd.Flags().String("room", "", "Room of this switch.") genericcli.Must(cmd.RegisterFlagCompletionFunc("id", c.comp.SwitchListCompletion)) genericcli.Must(cmd.RegisterFlagCompletionFunc("name", c.comp.SwitchNameListCompletion)) genericcli.Must(cmd.RegisterFlagCompletionFunc("partition", c.comp.PartitionListCompletion)) genericcli.Must(cmd.RegisterFlagCompletionFunc("rack", c.comp.SwitchRackListCompletion)) + genericcli.Must(cmd.RegisterFlagCompletionFunc("room", c.comp.SwitchRoomListCompletion)) genericcli.Must(cmd.RegisterFlagCompletionFunc("os-vendor", c.comp.SwitchOSVendorListCompletion)) genericcli.Must(cmd.RegisterFlagCompletionFunc("os-version", c.comp.SwitchOSVersionListCompletion)) }, @@ -79,11 +82,13 @@ func newSwitchCmd(c *config) *cobra.Command { switchDetailCmd.Flags().String("os-version", "", "OS version of this switch.") switchDetailCmd.Flags().String("partition", "", "Partition of this switch.") switchDetailCmd.Flags().String("rack", "", "Rack of this switch.") + switchDetailCmd.Flags().String("room", "", "Room of this switch.") genericcli.Must(switchDetailCmd.RegisterFlagCompletionFunc("id", c.comp.SwitchListCompletion)) genericcli.Must(switchDetailCmd.RegisterFlagCompletionFunc("name", c.comp.SwitchNameListCompletion)) genericcli.Must(switchDetailCmd.RegisterFlagCompletionFunc("partition", c.comp.PartitionListCompletion)) genericcli.Must(switchDetailCmd.RegisterFlagCompletionFunc("rack", c.comp.SwitchRackListCompletion)) + genericcli.Must(switchDetailCmd.RegisterFlagCompletionFunc("room", c.comp.SwitchRoomListCompletion)) switchMachinesCmd := &cobra.Command{ Use: "connected-machines", @@ -108,6 +113,7 @@ r01leaf01,swp2,44e3a522-5f48-4f3c-9188-41025f9e401e, switchMachinesCmd.Flags().String("os-version", "", "OS version of this switch.") switchMachinesCmd.Flags().String("partition", "", "Partition of this switch.") switchMachinesCmd.Flags().String("rack", "", "Rack of this switch.") + switchMachinesCmd.Flags().String("room", "", "Room of this switch.") switchMachinesCmd.Flags().String("size", "", "Size of the connected machines.") switchMachinesCmd.Flags().String("machine-id", "", "The id of the connected machine, ignores size flag if set.") @@ -115,6 +121,7 @@ r01leaf01,swp2,44e3a522-5f48-4f3c-9188-41025f9e401e, genericcli.Must(switchMachinesCmd.RegisterFlagCompletionFunc("name", c.comp.SwitchNameListCompletion)) genericcli.Must(switchMachinesCmd.RegisterFlagCompletionFunc("partition", c.comp.PartitionListCompletion)) genericcli.Must(switchMachinesCmd.RegisterFlagCompletionFunc("rack", c.comp.SwitchRackListCompletion)) + genericcli.Must(switchMachinesCmd.RegisterFlagCompletionFunc("room", c.comp.SwitchRoomListCompletion)) genericcli.Must(switchMachinesCmd.RegisterFlagCompletionFunc("size", c.comp.SizeListCompletion)) genericcli.Must(switchMachinesCmd.RegisterFlagCompletionFunc("machine-id", c.comp.MachineListCompletion)) @@ -224,6 +231,7 @@ func (c *switchCmd) List() ([]*models.V1SwitchResponse, error) { Osversion: viper.GetString("os-version"), Partitionid: viper.GetString("partition"), Rackid: viper.GetString("rack"), + Roomid: viper.GetString("room"), }), nil) if err != nil { return nil, err @@ -278,6 +286,7 @@ func switchResponseToUpdate(r *models.V1SwitchResponse) *models.V1SwitchUpdateRe Name: r.Name, Os: switchOS, RackID: r.RackID, + RoomID: r.RoomID, } } @@ -322,6 +331,7 @@ func (c *switchCmd) switchMachines() error { ID: viper.GetString("machine-id"), PartitionID: viper.GetString("partition"), Rackid: viper.GetString("rack"), + Roomid: viper.GetString("room"), Sizeid: viper.GetString("size"), }), nil) if err != nil { @@ -373,6 +383,7 @@ func (c *switchCmd) switchReplace(args []string) error { Name: resp.Name, Os: switchOS, RackID: resp.RackID, + RoomID: resp.RoomID, }) if err != nil { return err diff --git a/cmd/switch_test.go b/cmd/switch_test.go index a6bd49b..36f4e43 100644 --- a/cmd/switch_test.go +++ b/cmd/switch_test.go @@ -168,7 +168,7 @@ ID PARTITION RACK OS METALCORE IP MODE LAST SYNC { name: "list with filters", cmd: func(want []*models.V1SwitchResponse) []string { - args := []string{"switch", "list", "--id", *want[0].ID, "--name", want[0].Name, "--os-vendor", want[0].Os.Vendor, "--os-version", want[0].Os.Version, "--partition", *want[0].Partition.ID, "--rack", *want[0].RackID} + args := []string{"switch", "list", "--id", *want[0].ID, "--name", want[0].Name, "--os-vendor", want[0].Os.Vendor, "--os-version", want[0].Os.Version, "--partition", *want[0].Partition.ID, "--rack", *want[0].RackID, "--room", "room-a"} assertExhaustiveArgs(t, args, "sort-by") return args }, @@ -181,6 +181,7 @@ ID PARTITION RACK OS METALCORE IP MODE LAST SYNC Osversion: switch1.Os.Version, Partitionid: *switch1.Partition.ID, Rackid: *switch1.RackID, + Roomid: "room-a", })), nil).Return(&switch_operations.FindSwitchesOK{ Payload: []*models.V1SwitchResponse{ switch1, diff --git a/docs/metalctl_machine_ipmi.md b/docs/metalctl_machine_ipmi.md index 45d2345..c7d9c93 100644 --- a/docs/metalctl_machine_ipmi.md +++ b/docs/metalctl_machine_ipmi.md @@ -47,6 +47,7 @@ metalctl machine ipmi [] [flags] --project string allocation project to filter [optional] --rack string rack to filter [optional] --role string allocation role to filter [optional] + --room string room to filter [optional] --size string size to filter [optional] --sort-by strings sort by (comma separated) column(s), sort direction can be changed by appending :asc or :desc behind the column identifier. possible values: age|bios|bmc|event|id|liveliness|partition|project|rack|size|when --state string state to filter [optional] diff --git a/docs/metalctl_machine_ipmi_chassis-list.md b/docs/metalctl_machine_ipmi_chassis-list.md index a591106..f6f1681 100644 --- a/docs/metalctl_machine_ipmi_chassis-list.md +++ b/docs/metalctl_machine_ipmi_chassis-list.md @@ -47,6 +47,7 @@ metalctl machine ipmi chassis-list [flags] --project string allocation project to filter [optional] --rack string rack to filter [optional] --role string allocation role to filter [optional] + --room string room to filter [optional] --size string size to filter [optional] --sort-by strings sort by (comma separated) column(s), sort direction can be changed by appending :asc or :desc behind the column identifier. possible values: age|bios|bmc|event|id|liveliness|partition|project|rack|size|when --state string state to filter [optional] diff --git a/docs/metalctl_machine_issues.md b/docs/metalctl_machine_issues.md index 76943fc..c4c211e 100644 --- a/docs/metalctl_machine_issues.md +++ b/docs/metalctl_machine_issues.md @@ -49,6 +49,7 @@ metalctl machine issues [] [flags] --project string allocation project to filter [optional] --rack string rack to filter [optional] --role string allocation role to filter [optional] + --room string room to filter [optional] --severity string issue severity to include [optional] --size string size to filter [optional] --sort-by strings sort by (comma separated) column(s), sort direction can be changed by appending :asc or :desc behind the column identifier. possible values: age|bios|bmc|event|id|liveliness|partition|project|rack|size|when diff --git a/docs/metalctl_machine_list.md b/docs/metalctl_machine_list.md index 2ba8363..b091b43 100644 --- a/docs/metalctl_machine_list.md +++ b/docs/metalctl_machine_list.md @@ -47,6 +47,7 @@ metalctl machine list [flags] --project string allocation project to filter [optional] --rack string rack to filter [optional] --role string allocation role to filter [optional] + --room string room to filter [optional] --size string size to filter [optional] --sort-by strings sort by (comma separated) column(s), sort direction can be changed by appending :asc or :desc behind the column identifier. possible values: age|event|id|image|liveliness|partition|project|rack|size|when --state string state to filter [optional] diff --git a/docs/metalctl_switch_connected-machines.md b/docs/metalctl_switch_connected-machines.md index 1a937e3..8b4ff40 100644 --- a/docs/metalctl_switch_connected-machines.md +++ b/docs/metalctl_switch_connected-machines.md @@ -31,6 +31,7 @@ r01leaf01,swp2,44e3a522-5f48-4f3c-9188-41025f9e401e, --os-version string OS version of this switch. --partition string Partition of this switch. --rack string Rack of this switch. + --room string Room of this switch. --size string Size of the connected machines. ``` diff --git a/docs/metalctl_switch_detail.md b/docs/metalctl_switch_detail.md index 66df50e..2d2e229 100644 --- a/docs/metalctl_switch_detail.md +++ b/docs/metalctl_switch_detail.md @@ -16,6 +16,7 @@ metalctl switch detail [flags] --os-version string OS version of this switch. --partition string Partition of this switch. --rack string Rack of this switch. + --room string Room of this switch. ``` ### Options inherited from parent commands diff --git a/docs/metalctl_switch_list.md b/docs/metalctl_switch_list.md index 9aa815f..bf23b46 100644 --- a/docs/metalctl_switch_list.md +++ b/docs/metalctl_switch_list.md @@ -16,6 +16,7 @@ metalctl switch list [flags] --os-version string OS version of this switch. --partition string Partition of this switch. --rack string Rack of this switch. + --room string Room of this switch. --sort-by strings sort by (comma separated) column(s), sort direction can be changed by appending :asc or :desc behind the column identifier. possible values: description|id|name ``` diff --git a/go.mod b/go.mod index c686542..1128533 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/go-openapi/strfmt v0.26.4 github.com/google/go-cmp v0.7.0 github.com/google/uuid v1.6.0 - github.com/metal-stack/metal-go v0.44.1 + github.com/metal-stack/metal-go v0.45.0 github.com/metal-stack/metal-lib v0.25.2 github.com/metal-stack/updater v1.3.1 github.com/metal-stack/v v1.0.3 @@ -57,7 +57,7 @@ require ( github.com/go-openapi/jsonpointer v1.0.0 // indirect github.com/go-openapi/jsonreference v1.0.0 // indirect github.com/go-openapi/loads v0.24.0 // indirect - github.com/go-openapi/runtime/server-middleware v0.30.0 // indirect + github.com/go-openapi/runtime/server-middleware v0.32.4 // indirect github.com/go-openapi/spec v0.22.6 // indirect github.com/go-openapi/swag v0.27.0 // indirect github.com/go-openapi/swag/cmdutils v0.27.0 // indirect diff --git a/go.sum b/go.sum index 9c1cbd8..6a4ced7 100644 --- a/go.sum +++ b/go.sum @@ -135,6 +135,8 @@ github.com/go-openapi/runtime v0.32.4 h1:8ElGj/3goG0itt0nBPP6Cm57ehcYyuHoI3O20nx github.com/go-openapi/runtime v0.32.4/go.mod h1:Bz6keOZw1NX4T6f+m42OoT1MBPDt6Re13dbccHyGH/4= github.com/go-openapi/runtime/server-middleware v0.30.0 h1:8rPoJ/xv7JL8BsovaqboKETlpWBArVh8n+0L/GyePog= github.com/go-openapi/runtime/server-middleware v0.30.0/go.mod h1:OYNT/TxNvB/VK5oe4htM2jDTwlEXuejVJmu0DVZfAMs= +github.com/go-openapi/runtime/server-middleware v0.32.4 h1:AU6eLMq9CXwh8f6kC1pivtkz+7lfo3TmakMBbUisKME= +github.com/go-openapi/runtime/server-middleware v0.32.4/go.mod h1:fYPep4GdTwg/XqZUjR40uIM/8C12Ba5M+MrGCiwpTHo= github.com/go-openapi/spec v0.22.6 h1:Tyy1pLaNCM8GBCFLoGYLonjJi6zykqyLCjXLc19ZPic= github.com/go-openapi/spec v0.22.6/go.mod h1:HZvTHat+iH0PALQRWhrqIHtU/PEqxqd89fu0MxGlMeM= github.com/go-openapi/strfmt v0.26.4 h1:yI6IAEfcWow459BD5UzFY430KUwXZwBHrYusPFkhWlc= @@ -243,10 +245,12 @@ github.com/lestrrat-go/dsig-secp256k1 v1.0.0 h1:JpDe4Aybfl0soBvoVwjqDbp+9S1Y2OM7 github.com/lestrrat-go/dsig-secp256k1 v1.0.0/go.mod h1:CxUgAhssb8FToqbL8NjSPoGQlnO4w3LG1P0qPWQm/NU= github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE= github.com/lestrrat-go/httpcc v1.0.1/go.mod h1:qiltp3Mt56+55GPVCbTdM9MlqhvzyuL6W/NMDA8vA5E= +github.com/lestrrat-go/httprc v1.0.6 h1:qgmgIRhpvBqexMJjA/PmwSvhNk679oqD1RbovdCGW8k= github.com/lestrrat-go/httprc/v3 v3.0.6 h1:4FpLQ18KK/ypPbVU3NLWJNRvH3kcYiqKqWfKGqNWxxI= github.com/lestrrat-go/httprc/v3 v3.0.6/go.mod h1:mSMtkZW92Z98M5YoNNztbRGxbXHql7tSitCvaxvo9l0= github.com/lestrrat-go/jwx/v3 v3.1.1 h1:yd9AdPmZ4INnQ7k42IrzXYpnEG803+SrQ6hdMvzHJzw= github.com/lestrrat-go/jwx/v3 v3.1.1/go.mod h1:uw/MN2M/Xiu4FhwcIwH11Zsh9JWx9SWzgALl7/uIEkU= +github.com/lestrrat-go/option v1.0.1 h1:oAzP2fvZGQKWkvHa1/SAcFolBEca1oN+mQ7eooNBEYU= github.com/lestrrat-go/option/v2 v2.0.0 h1:XxrcaJESE1fokHy3FpaQ/cXW8ZsIdWcdFzzLOcID3Ss= github.com/lestrrat-go/option/v2 v2.0.0/go.mod h1:oSySsmzMoR0iRzCDCaUfsCzxQHUEuhOViQObyy7S6Vg= github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWy0/jY= @@ -265,6 +269,8 @@ github.com/mdlayher/socket v0.6.1 h1:M7uj2NtuujUY4mYr1C57NmfNiRHbkKpnBxO856lsc3A github.com/mdlayher/socket v0.6.1/go.mod h1:+/SGtqc9V+5dAuRgQsU0fGBI+oRDiW7O2Obx10OIWfg= github.com/metal-stack/metal-go v0.44.1 h1:tu6TMEsAccA9i/Ipte1RV9EcQ3APX4m9PdvvYCB10uQ= github.com/metal-stack/metal-go v0.44.1/go.mod h1:GSfXrAj55LGsUSMHWGDsmq5n056NG0yb1JM8bgfvKOw= +github.com/metal-stack/metal-go v0.45.0 h1:X5BCppdE3RYNScfwQxv9JTehyFIv6LhVzhbG25k27KQ= +github.com/metal-stack/metal-go v0.45.0/go.mod h1:GSfXrAj55LGsUSMHWGDsmq5n056NG0yb1JM8bgfvKOw= github.com/metal-stack/metal-lib v0.25.2 h1:OW8y6PtlV5lv3bXSDU1MaNGvtbroiDYjuhSxqKHKAgw= github.com/metal-stack/metal-lib v0.25.2/go.mod h1:tnx4MM5oml10EMN6Nq6oFSbjOKB9B27WUZQUyZ4MywA= github.com/metal-stack/security v0.9.6 h1:q+JbfFis/G2IuyKky2btmDmO0Y2GQ47p7lmzOi80kMY= @@ -281,6 +287,7 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= +github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s= github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ= github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 h1:zrbMGy9YXpIeTnGj4EljqMiZsIcE09mmF8XsD5AYOJc=