Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3cb6072
First work on network
majst01 May 14, 2025
d3bb312
Reough impl for network.
Gerrit91 May 15, 2025
c1ef75e
Fixes.
Gerrit91 May 15, 2025
5837734
Merge remote-tracking branch 'origin/main' into network-services
Gerrit91 May 16, 2025
b4a5d18
Start with admin command (not yet working).
Gerrit91 May 16, 2025
f0a7b78
Update.
Gerrit91 May 19, 2025
f47065e
Namespaced ip get
majst01 May 20, 2025
0b47606
Admin IP List
majst01 May 21, 2025
4888ed3
pin api
majst01 May 26, 2025
81d5626
Improvements
majst01 May 27, 2025
1e61919
Network improvements
majst01 Jun 16, 2025
03fdc62
Update api
majst01 Jun 26, 2025
0c85b25
Update api
majst01 Oct 17, 2025
90ffb0a
size, admin not finished yet (#4)
majst01 Feb 6, 2026
aa8338b
Merge main
majst01 Feb 6, 2026
0562727
Fixes
majst01 Feb 10, 2026
105f40b
go 1.26
majst01 Feb 13, 2026
692da9f
go fix
majst01 Feb 13, 2026
ed1fc6d
Merge main
majst01 Feb 23, 2026
6fc48a9
Merge main
majst01 Mar 21, 2026
961982b
Fix
majst01 Mar 25, 2026
704023f
More tests
majst01 Mar 25, 2026
955fbfb
More tests
majst01 Mar 25, 2026
87f8960
Untested machine create
majst01 Apr 6, 2026
4f9b854
Fix
majst01 Apr 7, 2026
54316fa
machine create, but horribly broken and wrong
majst01 Apr 27, 2026
020cfba
Merge remote-tracking branch 'origin/main' into network-services
Gerrit91 May 20, 2026
a1f392e
remove testcommon
majst01 May 30, 2026
3e0b8cc
Merge main
majst01 Jun 1, 2026
58e0399
Add partition flag
majst01 Jun 2, 2026
a93af23
More ip list filter
majst01 Jun 3, 2026
b7fa6cc
More ip list filter
majst01 Jun 3, 2026
e7b7cd8
More ip list filter
majst01 Jun 3, 2026
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
5 changes: 5 additions & 0 deletions cmd/admin/v2/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ func AddCmds(cmd *cobra.Command, c *config.Config) {
adminCmd.AddCommand(newAuditCmd(c))
adminCmd.AddCommand(newComponentCmd(c))
adminCmd.AddCommand(newImageCmd(c))
adminCmd.AddCommand(newIPCmd(c))
adminCmd.AddCommand(newMachineCmd(c))
adminCmd.AddCommand(newNetworkCmd(c))
adminCmd.AddCommand(newProjectCmd(c))
adminCmd.AddCommand(newSizeCmd(c))
adminCmd.AddCommand(newSwitchCmd(c))
adminCmd.AddCommand(newTaskCmd(c))
adminCmd.AddCommand(newTenantCmd(c))
adminCmd.AddCommand(newTokenCmd(c))
adminCmd.AddCommand(newVPNCmd(c))

cmd.AddCommand(adminCmd)
}
132 changes: 132 additions & 0 deletions cmd/admin/v2/ip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package v2

import (
"strings"

"github.com/metal-stack/api/go/enum"
adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2"
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/metal-stack/cli/cmd/config"
"github.com/metal-stack/cli/cmd/sorters"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/genericcli/printers"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

type ip struct {
c *config.Config
}

func newIPCmd(c *config.Config) *cobra.Command {
w := &ip{
c: c,
}

cmdsConfig := &genericcli.CmdsConfig[any, any, *apiv2.IP]{
BinaryName: config.BinaryName,
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.Fs),
Singular: "ip",
Plural: "ips",
Description: "manage ip addresses",
Sorter: sorters.IPSorter(),
DescribePrinter: func() printers.Printer { return c.DescribePrinter },
ListPrinter: func() printers.Printer { return c.ListPrinter },
OnlyCmds: genericcli.OnlyCmds(genericcli.ListCmd),
ListCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().String("ip", "", "ipaddress to filter [optional]")
cmd.Flags().String("name", "", "name to filter [optional]")
cmd.Flags().String("network", "", "network to filter [optional]")
cmd.Flags().String("project", "", "project to filter [optional]")
cmd.Flags().String("uuid", "", "allocation uuid to filter [optional]")
cmd.Flags().String("machine", "", "machine to filter [optional]")
cmd.Flags().String("namespace", "", "namespace to filter [optional]")
cmd.Flags().String("parent-prefix", "", "parent-prefix to filter [optional]")
cmd.Flags().String("type", "", "type to filter [optional] can be either ephemeral|static")
cmd.Flags().String("addressfamily", "", "addressfamily to filter [optional] can be either ipv6|ipv6")
cmd.Flags().StringSlice("label", nil, "label to filter, must be in the form of key=value, can be either specified multiple times, or comma seperated [optional]")
genericcli.Must(cmd.RegisterFlagCompletionFunc("network", c.Completion.NetworkListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("type", c.Completion.IpTypeCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("addressfamily", c.Completion.IpAddressFamilyCompletion))
},
ValidArgsFn: c.Completion.IpListCompletion,
}

return genericcli.NewCmds(cmdsConfig)
}

func (c *ip) List() ([]*apiv2.IP, error) {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

var (
labels *apiv2.Labels
ipType *apiv2.IPType
af *apiv2.IPAddressFamily
)

if len(viper.GetStringSlice("label")) > 0 {
labels = &apiv2.Labels{
Labels: map[string]string{},
}
for _, label := range viper.GetStringSlice("label") {
key, value, _ := strings.Cut(label, "=")
labels.Labels[key] = value
}
}

if viper.IsSet("type") {
ipt, err := enum.GetEnum[apiv2.IPType](viper.GetString("type"))
if err != nil {
return nil, err
}
ipType = &ipt
}

if viper.IsSet("addressfamily") {
ipaf, err := enum.GetEnum[apiv2.IPAddressFamily](viper.GetString("addressfamily"))
if err != nil {
return nil, err
}
af = &ipaf
}

resp, err := c.c.Client.Adminv2().IP().List(ctx, &adminv2.IPServiceListRequest{
Query: &apiv2.IPQuery{
Ip: pointer.PointerOrNil(viper.GetString("ip")),
Network: pointer.PointerOrNil(viper.GetString("network")),
Name: pointer.PointerOrNil(viper.GetString("name")),
Project: pointer.PointerOrNil(viper.GetString("project")),
Uuid: pointer.PointerOrNil(viper.GetString("uuid")),
Machine: pointer.PointerOrNil(viper.GetString("machine")),
ParentPrefixCidr: pointer.PointerOrNil(viper.GetString("parent-prefix")),
Namespace: pointer.PointerOrNil(viper.GetString("namespace")),
Labels: labels,
Type: ipType,
AddressFamily: af,
},
})
if err != nil {
return nil, err
}

return resp.Ips, nil
}

func (t *ip) Get(id string) (*apiv2.IP, error) {
panic("unimplemented")
}
func (c *ip) Delete(id string) (*apiv2.IP, error) {
panic("unimplemented")
}
func (t *ip) Create(rq any) (*apiv2.IP, error) {
panic("unimplemented")
}
func (t *ip) Convert(r *apiv2.IP) (string, any, any, error) {
panic("unimplemented")
}

func (t *ip) Update(rq any) (*apiv2.IP, error) {
panic("unimplemented")
}
189 changes: 189 additions & 0 deletions cmd/admin/v2/machine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package v2

import (
"fmt"

adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2"
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/metal-stack/cli/cmd/config"
"github.com/metal-stack/cli/cmd/sorters"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/genericcli/printers"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/metal-stack/metal-lib/pkg/tag"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

type machine struct {
c *config.Config
}

func newMachineCmd(c *config.Config) *cobra.Command {
w := &machine{
c: c,
}

cmdsConfig := &genericcli.CmdsConfig[any, any, *apiv2.Machine]{
BinaryName: config.BinaryName,
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.Fs),
Singular: "machine",
Plural: "machines",
Description: "manage machines",
Sorter: sorters.MachineSorter(),
DescribePrinter: func() printers.Printer { return c.DescribePrinter },
ListPrinter: func() printers.Printer { return c.ListPrinter },
ListCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().StringP("project", "p", "", "project from where machines should be listed")
cmd.Flags().StringP("partition", "", "", "partition from where machines should be listed")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectListCompletion))
genericcli.Must(cmd.RegisterFlagCompletionFunc("partition", c.Completion.PartitionListCompletion))
},
DescribeCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().StringP("project", "p", "", "project of the machine")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectListCompletion))
},
ValidArgsFn: c.Completion.MachineListCompletion,
}

bmcCommandCmd := &cobra.Command{
Use: "bmc-command",
Short: "send a command to the bmc of a machine",
RunE: func(cmd *cobra.Command, args []string) error {
return w.bmcCommand()
},
}
bmcCommandCmd.Flags().String("id", "", "id of the machine where the command should be sent to")
bmcCommandCmd.Flags().String("command", "", "the actual command to send to the machine")
genericcli.Must(bmcCommandCmd.RegisterFlagCompletionFunc("id", c.Completion.MachineListCompletion))
genericcli.Must(bmcCommandCmd.RegisterFlagCompletionFunc("command", c.Completion.BMCCommandListCompletion))
genericcli.Must(bmcCommandCmd.MarkFlagRequired("id"))
genericcli.Must(bmcCommandCmd.MarkFlagRequired("command"))

return genericcli.NewCmds(cmdsConfig, bmcCommandCmd)
}

func (c *machine) bmcCommand() error {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

commandString := viper.GetString("command")

cmd, ok := apiv2.MachineBMCCommand_value[commandString]
if !ok {
return fmt.Errorf("unknown command: %s", commandString)
}
_, err := c.c.Client.Adminv2().Machine().BMCCommand(ctx, &adminv2.MachineServiceBMCCommandRequest{
Uuid: viper.GetString("id"),
Command: apiv2.MachineBMCCommand(cmd),
})
if err != nil {
return err
}
return err
}

func (c *machine) Create(rq any) (*apiv2.Machine, error) {
panic("unimplemented")
}

func (c *machine) Delete(id string) (*apiv2.Machine, error) {
panic("unimplemented")
}

func (c *machine) Get(id string) (*apiv2.Machine, error) {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

resp, err := c.c.Client.Adminv2().Machine().Get(ctx, &adminv2.MachineServiceGetRequest{
Uuid: id,
})
if err != nil {
return nil, err
}

return resp.Machine, nil
}

func (c *machine) List() ([]*apiv2.Machine, error) {
ctx, cancel := c.c.NewRequestContext()
defer cancel()

resp, err := c.c.Client.Adminv2().Machine().List(ctx, &adminv2.MachineServiceListRequest{
Query: &apiv2.MachineQuery{
Uuid: pointer.PointerOrNil(viper.GetString("id")),
Name: pointer.PointerOrNil(viper.GetString("name")),
Partition: pointer.PointerOrNil(viper.GetString("partition")),
Size: pointer.PointerOrNil(viper.GetString("size")),
Rack: pointer.PointerOrNil(viper.GetString("rack")),
Labels: &apiv2.Labels{
Labels: tag.NewTagMap(viper.GetStringSlice("labels")),
},
Allocation: &apiv2.MachineAllocationQuery{
Uuid: pointer.PointerOrNil(viper.GetString("allocation-uuid")),
Name: pointer.PointerOrNil(viper.GetString("allocation-name")),
Project: pointer.PointerOrNil(viper.GetString("project")),
Image: pointer.PointerOrNil(viper.GetString("image")),
FilesystemLayout: pointer.PointerOrNil(viper.GetString("file-system-layout-id")),
Hostname: pointer.PointerOrNil(viper.GetString("hostname")),
// AllocationType: &0,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// AllocationType: &0,
// AllocationType: &0, TODO: implement

Labels: &apiv2.Labels{
Labels: tag.NewTagMap(viper.GetStringSlice("allocation-labels")),
},
// Vpn: &apiv2.MachineVPN{}, these query fields are no pointers and somehow seem wrong? how to search for vpn key?
},
Network: &apiv2.MachineNetworkQuery{},
Nic: &apiv2.MachineNicQuery{},
Disk: &apiv2.MachineDiskQuery{
Names: viper.GetStringSlice("disk-names"),
// Sizes:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Sizes:
// Sizes: TODO: implement

},
Bmc: &apiv2.MachineBMCQuery{
Address: pointer.PointerOrNil(viper.GetString("bmc-address")),
Mac: pointer.PointerOrNil(viper.GetString("bmc-mac")),
User: pointer.PointerOrNil(viper.GetString("bmc-user")),
Interface: pointer.PointerOrNil(viper.GetString("bmc-interface")),
},
Fru: &apiv2.MachineFRUQuery{
ChassisPartNumber: pointer.PointerOrNil(viper.GetString("chassis-part-number")),
ChassisPartSerial: pointer.PointerOrNil(viper.GetString("chassis-part-serial")),
BoardMfg: pointer.PointerOrNil(viper.GetString("board-mfg")),
BoardSerial: pointer.PointerOrNil(viper.GetString("board-serial")),
BoardPartNumber: pointer.PointerOrNil(viper.GetString("board-part-number")),
ProductManufacturer: pointer.PointerOrNil(viper.GetString("product-manufacturer")),
ProductPartNumber: pointer.PointerOrNil(viper.GetString("product-part-number")),
ProductSerial: pointer.PointerOrNil(viper.GetString("product-serial")),
},
Hardware: &apiv2.MachineHardwareQuery{
Memory: pointer.PointerOrNil(viper.GetUint64("memory")),
CpuCores: pointer.PointerOrNil(viper.GetUint32("cpu-cores")),
},
// State: &0,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// State: &0,
// State: &0, TODO: implement

},
Partition: nil, // again partition?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Partition: nil, // again partition?
// admins are allowed to list machines in all partitions
Partition: nil,

})
if err != nil {
return nil, err
}

return resp.Machines, nil
}

func (c *machine) Update(rq any) (*apiv2.Machine, error) {
panic("unimplemented")
}

func (c *machine) Convert(r *apiv2.Machine) (string, any, any, error) {
panic("unimplemented")

}

func (c *machine) MachineResponseToCreate(r *apiv2.Machine) any {
panic("unimplemented")
}

func (c *machine) MachineResponseToUpdate(desired *apiv2.Machine) (any, error) {
panic("unimplemented")
}
Loading
Loading