-
Notifications
You must be signed in to change notification settings - Fork 0
Admin IP command #47
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
Merged
Merged
Admin IP command #47
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fc517b8
Make completion work, add network completion for ip create
majst01 f8a8d61
More completions
majst01 ebf3c5b
Fixes
majst01 035b6d4
add admin ip command
majst01 39b4532
admin ip get
majst01 b0eb3da
Merge main
majst01 ac2a8c9
Only CMDs.
Gerrit91 7d43778
Tests.
Gerrit91 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,136 @@ | ||
| 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/cli/pkg/helpers" | ||
| "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: "an ip address of metal-stack.io", | ||
| Sorter: sorters.IPSorter(), | ||
| DescribePrinter: func() printers.Printer { return c.DescribePrinter }, | ||
| ListPrinter: func() printers.Printer { return c.ListPrinter }, | ||
| ListCmdMutateFn: func(cmd *cobra.Command) { | ||
| cmd.Flags().String("ip", "", "ip which should be listed") | ||
| cmd.Flags().String("uuid", "", "allocation uuid of ip which should be listed") | ||
| cmd.Flags().String("project", "", "project from where ips should be listed") | ||
| cmd.Flags().String("name", "", "name from ips which should be listed") | ||
| cmd.Flags().String("network", "", "network from where ips should be listed") | ||
| cmd.Flags().String("machine", "", "machine where ips are attached to") | ||
| cmd.Flags().StringSlice("labels", nil, "lists only ips with the given labels") | ||
| cmd.Flags().String("addressfamily", "", "addressfamily of ips which should be listed") | ||
| cmd.Flags().String("type", "", "type of ips which should be listed") | ||
|
|
||
| genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project)) | ||
| genericcli.Must(cmd.RegisterFlagCompletionFunc("network", c.Completion.Network)) | ||
| genericcli.Must(cmd.RegisterFlagCompletionFunc("machine", c.Completion.Machine)) | ||
| genericcli.Must(cmd.RegisterFlagCompletionFunc("addressfamily", c.Completion.AddressFamily)) | ||
| genericcli.Must(cmd.RegisterFlagCompletionFunc("type", c.Completion.IPType)) | ||
|
|
||
| }, | ||
| ValidArgsFn: c.Completion.Ip, | ||
| OnlyCmds: map[genericcli.DefaultCmd]bool{ | ||
| genericcli.ListCmd: true, | ||
| genericcli.DescribeCmd: true, | ||
| }, | ||
| } | ||
|
|
||
| return genericcli.NewCmds(cmdsConfig) | ||
| } | ||
|
|
||
| func (c *ip) Create(_ any) (*apiv2.IP, error) { | ||
| panic("unimplemented") | ||
| } | ||
|
|
||
| func (c *ip) Delete(id string) (*apiv2.IP, error) { | ||
| panic("unimplemented") | ||
| } | ||
|
|
||
| func (c *ip) Get(id string) (*apiv2.IP, error) { | ||
| ctx, cancel := c.c.NewRequestContext() | ||
| defer cancel() | ||
|
|
||
| resp, err := c.c.Client.Adminv2().IP().List(ctx, &adminv2.IPServiceListRequest{ | ||
| Query: &apiv2.IPQuery{ | ||
| Ip: &id, | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| switch len(resp.Ips) { | ||
| case 0: | ||
| return nil, fmt.Errorf("no ip found for ip:%s", id) | ||
| case 1: | ||
| return resp.Ips[0], nil | ||
| default: | ||
| return nil, fmt.Errorf("more than one ip found for ip:%s", id) | ||
| } | ||
| } | ||
|
|
||
| func (c *ip) List() ([]*apiv2.IP, error) { | ||
| ctx, cancel := c.c.NewRequestContext() | ||
| defer cancel() | ||
|
|
||
| var labels *apiv2.Labels | ||
| if labelSlice := viper.GetStringSlice("labels"); len(labelSlice) > 0 { | ||
| var err error | ||
|
|
||
| labels, err = helpers.LabelsFromSlice(labelSlice) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| resp, err := c.c.Client.Adminv2().IP().List(ctx, &adminv2.IPServiceListRequest{ | ||
| Query: &apiv2.IPQuery{ | ||
| Ip: pointer.PointerOrNil(viper.GetString("ip")), | ||
| Uuid: pointer.PointerOrNil(viper.GetString("uuid")), | ||
| Network: pointer.PointerOrNil(viper.GetString("network")), | ||
| Project: pointer.PointerOrNil(viper.GetString("project")), | ||
| Name: pointer.PointerOrNil(viper.GetString("name")), | ||
| Machine: pointer.PointerOrNil(viper.GetString("machine")), | ||
| ParentPrefixCidr: pointer.PointerOrNil(viper.GetString("parent-prefix")), | ||
| Labels: labels, | ||
| Type: helpers.IPTypeToType(viper.GetString("type")), | ||
| AddressFamily: helpers.IPAddressFamilyToType(viper.GetString("addressfamily")), | ||
| Namespace: pointer.PointerOrNil(viper.GetString("namespace")), | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return resp.Ips, nil | ||
| } | ||
|
|
||
| func (c *ip) Update(_ any) (*apiv2.IP, error) { | ||
| panic("unimplemented") | ||
| } | ||
|
|
||
| func (c *ip) Convert(r *apiv2.IP) (string, any, any, 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
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,25 @@ | ||
| package completion | ||
|
|
||
| import ( | ||
| adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func (c *Completion) Machine(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
| req := &adminv2.MachineServiceListRequest{} | ||
| resp, err := c.Client.Adminv2().Machine().List(cmd.Context(), req) | ||
| if err != nil { | ||
| return nil, cobra.ShellCompDirectiveError | ||
| } | ||
| var names []string | ||
| for _, m := range resp.Machines { | ||
| var hostname string | ||
| if m.Allocation != nil { | ||
| hostname = m.Allocation.Hostname | ||
| names = append(names, m.Uuid+"\t"+hostname) | ||
| } else { | ||
| names = append(names, m.Uuid) | ||
| } | ||
| } | ||
| return names, cobra.ShellCompDirectiveNoFileComp | ||
| } |
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
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,33 @@ | ||
| ## metalctlv2 admin ip | ||
|
|
||
| manage ip entities | ||
|
|
||
| ### Synopsis | ||
|
|
||
| an ip address of metal-stack.io | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help help for ip | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| --api-token string the token used for api requests | ||
| --api-url string the url to the metal-stack.io api | ||
| -c, --config string alternative config file path, (default is ~/.metal-stack/config.yaml) | ||
| --debug debug output | ||
| --force-color force colored output even without tty | ||
| -o, --output-format string output format (table|wide|markdown|json|yaml|template), wide is a table with more columns. (default "table") | ||
| --template string output template for template output-format, go template format. For property names inspect the output of -o json or -o yaml for reference. | ||
| --timeout duration request timeout used for api requests | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [metalctlv2 admin](metalctlv2_admin.md) - admin commands | ||
| * [metalctlv2 admin ip describe](metalctlv2_admin_ip_describe.md) - describes the ip | ||
| * [metalctlv2 admin ip list](metalctlv2_admin_ip_list.md) - list all ips | ||
|
|
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,31 @@ | ||
| ## metalctlv2 admin ip describe | ||
|
|
||
| describes the ip | ||
|
|
||
| ``` | ||
| metalctlv2 admin ip describe <id> [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help help for describe | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| --api-token string the token used for api requests | ||
| --api-url string the url to the metal-stack.io api | ||
| -c, --config string alternative config file path, (default is ~/.metal-stack/config.yaml) | ||
| --debug debug output | ||
| --force-color force colored output even without tty | ||
| -o, --output-format string output format (table|wide|markdown|json|yaml|template), wide is a table with more columns. (default "table") | ||
| --template string output template for template output-format, go template format. For property names inspect the output of -o json or -o yaml for reference. | ||
| --timeout duration request timeout used for api requests | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [metalctlv2 admin ip](metalctlv2_admin_ip.md) - manage ip entities | ||
|
|
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,41 @@ | ||
| ## metalctlv2 admin ip list | ||
|
|
||
| list all ips | ||
|
|
||
| ``` | ||
| metalctlv2 admin ip list [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| --addressfamily string addressfamily of ips which should be listed | ||
| -h, --help help for list | ||
| --ip string ip which should be listed | ||
| --labels strings lists only ips with the given labels | ||
| --machine string machine where ips are attached to | ||
| --name string name from ips which should be listed | ||
| --network string network from where ips should be listed | ||
| --project string project from where ips should be listed | ||
| --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: ip|name|network|project|type|uuid | ||
| --type string type of ips which should be listed | ||
| --uuid string allocation uuid of ip which should be listed | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| --api-token string the token used for api requests | ||
| --api-url string the url to the metal-stack.io api | ||
| -c, --config string alternative config file path, (default is ~/.metal-stack/config.yaml) | ||
| --debug debug output | ||
| --force-color force colored output even without tty | ||
| -o, --output-format string output format (table|wide|markdown|json|yaml|template), wide is a table with more columns. (default "table") | ||
| --template string output template for template output-format, go template format. For property names inspect the output of -o json or -o yaml for reference. | ||
| --timeout duration request timeout used for api requests | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [metalctlv2 admin ip](metalctlv2_admin_ip.md) - manage ip entities | ||
|
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.