Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cmd/completion/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 15 additions & 0 deletions cmd/completion/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions cmd/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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]")
Expand Down Expand Up @@ -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"),
Expand Down
11 changes: 11 additions & 0 deletions cmd/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
},
Expand All @@ -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",
Expand All @@ -108,13 +113,15 @@ r01leaf01,swp2,44e3a522-5f48-4f3c-9188-41025f9e401e,<b-serial>
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.")

genericcli.Must(switchMachinesCmd.RegisterFlagCompletionFunc("id", c.comp.SwitchListCompletion))
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))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -278,6 +286,7 @@ func switchResponseToUpdate(r *models.V1SwitchResponse) *models.V1SwitchUpdateRe
Name: r.Name,
Os: switchOS,
RackID: r.RackID,
RoomID: r.RoomID,
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cmd/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions docs/metalctl_machine_ipmi.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ metalctl machine ipmi [<machine ID>] [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]
Expand Down
1 change: 1 addition & 0 deletions docs/metalctl_machine_ipmi_chassis-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions docs/metalctl_machine_issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ metalctl machine issues [<machine ID>] [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
Expand Down
1 change: 1 addition & 0 deletions docs/metalctl_machine_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions docs/metalctl_switch_connected-machines.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ r01leaf01,swp2,44e3a522-5f48-4f3c-9188-41025f9e401e,<b-serial>
--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.
```

Expand Down
1 change: 1 addition & 0 deletions docs/metalctl_switch_detail.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/metalctl_switch_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down