-
Notifications
You must be signed in to change notification settings - Fork 0
Network, Size and VPN #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
majst01
wants to merge
33
commits into
main
Choose a base branch
from
network-services
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 d3bb312
Reough impl for network.
Gerrit91 c1ef75e
Fixes.
Gerrit91 5837734
Merge remote-tracking branch 'origin/main' into network-services
Gerrit91 b4a5d18
Start with admin command (not yet working).
Gerrit91 f0a7b78
Update.
Gerrit91 f47065e
Namespaced ip get
majst01 0b47606
Admin IP List
majst01 4888ed3
pin api
majst01 81d5626
Improvements
majst01 1e61919
Network improvements
majst01 03fdc62
Update api
majst01 0c85b25
Update api
majst01 90ffb0a
size, admin not finished yet (#4)
majst01 aa8338b
Merge main
majst01 0562727
Fixes
majst01 105f40b
go 1.26
majst01 692da9f
go fix
majst01 ed1fc6d
Merge main
majst01 6fc48a9
Merge main
majst01 961982b
Fix
majst01 704023f
More tests
majst01 955fbfb
More tests
majst01 87f8960
Untested machine create
majst01 4f9b854
Fix
majst01 54316fa
machine create, but horribly broken and wrong
majst01 020cfba
Merge remote-tracking branch 'origin/main' into network-services
Gerrit91 a1f392e
remove testcommon
majst01 3e0b8cc
Merge main
majst01 58e0399
Add partition flag
majst01 a93af23
More ip list filter
majst01 b7fa6cc
More ip list filter
majst01 e7b7cd8
More ip list filter
majst01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||||||||
| 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: | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| }, | ||||||||
| 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, | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| }, | ||||||||
| Partition: nil, // again partition? | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| }) | ||||||||
| 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") | ||||||||
| } | ||||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.