diff --git a/cmd/completion/network.go b/cmd/completion/network.go index 04422ea..2b612cf 100644 --- a/cmd/completion/network.go +++ b/cmd/completion/network.go @@ -2,6 +2,8 @@ package completion import ( "github.com/metal-stack/metal-go/api/client/network" + "github.com/metal-stack/metal-go/api/models" + "github.com/spf13/cobra" ) @@ -28,3 +30,6 @@ func (c *Completion) NetworkDestinationPrefixesCompletion(cmd *cobra.Command, ar } return prefixes, cobra.ShellCompDirectiveNoFileComp } +func (c *Completion) AddressFamilyCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{models.V1NetworkImmutableAddressfamilyIPV4, models.V1NetworkImmutableAddressfamilyIPV6}, cobra.ShellCompDirectiveNoFileComp +} diff --git a/cmd/network.go b/cmd/network.go index 2ad1ec8..e4d6de2 100644 --- a/cmd/network.go +++ b/cmd/network.go @@ -69,8 +69,10 @@ func newNetworkCmd(c *config) *cobra.Command { cmd.Flags().Int64P("vrf", "", 0, "vrf to filter [optional]") cmd.Flags().StringSlice("prefixes", []string{}, "prefixes to filter, use it like: --prefixes prefix1,prefix2.") cmd.Flags().StringSlice("destination-prefixes", []string{}, "destination prefixes to filter, use it like: --destination-prefixes prefix1,prefix2.") + cmd.Flags().String("addressfamily", "", "addressfamily to filter, either ipv4 or ipv6 [optional]") genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion)) genericcli.Must(cmd.RegisterFlagCompletionFunc("partition", c.comp.PartitionListCompletion)) + genericcli.Must(cmd.RegisterFlagCompletionFunc("addressfamily", c.comp.AddressFamilyCompletion)) }, UpdateCmdMutateFn: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "the name of the network [optional]") @@ -103,6 +105,17 @@ func newNetworkCmd(c *config) *cobra.Command { return err } + var ( + af *string + length *int64 + ) + if viper.IsSet("length") { + length = pointer.Pointer(viper.GetInt64("length")) + } + if viper.IsSet("addressfamily") { + af = pointer.Pointer(viper.GetString("addressfamily")) + } + return w.childCLI.CreateAndPrint(&models.V1NetworkAllocateRequest{ Description: viper.GetString("description"), Name: viper.GetString("name"), @@ -112,6 +125,8 @@ func newNetworkCmd(c *config) *cobra.Command { Labels: labels, Destinationprefixes: destinationPrefixes, Nat: nat, + AddressFamily: af, + Length: length, }, c.describePrinter) } @@ -140,6 +155,8 @@ func newNetworkCmd(c *config) *cobra.Command { allocateCmd.Flags().StringSlice("labels", []string{}, "labels for this network. [optional]") allocateCmd.Flags().BoolP("dmz", "", false, "use this private network as dmz. [optional]") allocateCmd.Flags().BoolP("shared", "", false, "shared allows usage of this private network from other networks") + allocateCmd.Flags().StringP("addressfamily", "", "ipv4", "addressfamily of the network to acquire [optional]") + allocateCmd.Flags().Int64P("length", "", 22, "bitlength of network to create. [optional]") genericcli.Must(allocateCmd.RegisterFlagCompletionFunc("project", c.comp.ProjectListCompletion)) genericcli.Must(allocateCmd.RegisterFlagCompletionFunc("partition", c.comp.PartitionListCompletion)) @@ -177,6 +194,7 @@ func (c networkCmd) List() ([]*models.V1NetworkResponse, error) { Prefixes: viper.GetStringSlice("prefixes"), Destinationprefixes: viper.GetStringSlice("destination-prefixes"), Parentnetworkid: viper.GetString("parent"), + Addressfamily: viper.GetString("addressfamily"), }), nil) if err != nil { return nil, err @@ -225,21 +243,22 @@ func (c networkCmd) Convert(r *models.V1NetworkResponse) (string, *models.V1Netw func networkResponseToCreate(r *models.V1NetworkResponse) *models.V1NetworkCreateRequest { return &models.V1NetworkCreateRequest{ - Description: r.Description, - Destinationprefixes: r.Destinationprefixes, - ID: r.ID, - Labels: r.Labels, - Name: r.Name, - Nat: r.Nat, - Parentnetworkid: r.Parentnetworkid, - Partitionid: r.Partitionid, - Prefixes: r.Prefixes, - Privatesuper: r.Privatesuper, - Projectid: r.Projectid, - Shared: r.Shared, - Underlay: r.Underlay, - Vrf: r.Vrf, - Vrfshared: r.Vrfshared, + Description: r.Description, + Destinationprefixes: r.Destinationprefixes, + ID: r.ID, + Labels: r.Labels, + Name: r.Name, + Nat: r.Nat, + Parentnetworkid: r.Parentnetworkid, + Partitionid: r.Partitionid, + Defaultchildprefixlength: r.Defaultchildprefixlength, + Prefixes: r.Prefixes, + Privatesuper: r.Privatesuper, + Projectid: r.Projectid, + Shared: r.Shared, + Underlay: r.Underlay, + Vrf: r.Vrf, + Vrfshared: r.Vrfshared, } } diff --git a/cmd/partition.go b/cmd/partition.go index 61de994..3832b6b 100644 --- a/cmd/partition.go +++ b/cmd/partition.go @@ -140,11 +140,10 @@ func partitionResponseToCreate(r *models.V1PartitionResponse) *models.V1Partitio Imageurl: r.Bootconfig.Imageurl, Kernelurl: r.Bootconfig.Kernelurl, }, - Description: r.Description, - ID: r.ID, - Mgmtserviceaddress: r.Mgmtserviceaddress, - Name: r.Name, - Privatenetworkprefixlength: r.Privatenetworkprefixlength, + Description: r.Description, + ID: r.ID, + Mgmtserviceaddress: r.Mgmtserviceaddress, + Name: r.Name, } } diff --git a/cmd/partition_test.go b/cmd/partition_test.go index 43b2d31..d4bf3ac 100644 --- a/cmd/partition_test.go +++ b/cmd/partition_test.go @@ -21,11 +21,10 @@ var ( Imageurl: "imageurl", Kernelurl: "kernelurl", }, - Description: "partition 1", - ID: pointer.Pointer("1"), - Mgmtserviceaddress: "mgmt", - Name: "partition-1", - Privatenetworkprefixlength: 24, + Description: "partition 1", + ID: pointer.Pointer("1"), + Mgmtserviceaddress: "mgmt", + Name: "partition-1", Labels: map[string]string{ "a": "b", }, @@ -36,11 +35,10 @@ var ( Imageurl: "imageurl", Kernelurl: "kernelurl", }, - Description: "partition 2", - ID: pointer.Pointer("2"), - Mgmtserviceaddress: "mgmt", - Name: "partition-2", - Privatenetworkprefixlength: 24, + Description: "partition 2", + ID: pointer.Pointer("2"), + Mgmtserviceaddress: "mgmt", + Name: "partition-2", } ) @@ -239,7 +237,6 @@ ID NAME DESCRIPTION LABELS mocks: &client.MetalMockFns{ Partition: func(mock *mock.Mock) { p := partition1 - p.Privatenetworkprefixlength = 0 mock.On("CreatePartition", testcommon.MatchIgnoreContext(t, partition.NewCreatePartitionParams().WithBody(partitionResponseToCreate(p))), nil).Return(&partition.CreatePartitionCreated{ Payload: partition1, }, nil) diff --git a/docs/metalctl_network_allocate.md b/docs/metalctl_network_allocate.md index 7fc6039..9c8df92 100644 --- a/docs/metalctl_network_allocate.md +++ b/docs/metalctl_network_allocate.md @@ -9,14 +9,16 @@ metalctl network allocate [flags] ### Options ``` - -d, --description string description of the network to create. [optional] - --dmz use this private network as dmz. [optional] - -h, --help help for allocate - --labels strings labels for this network. [optional] - -n, --name string name of the network to create. [required] - --partition string partition where this network should exist. [required] - --project string partition where this network should exist. [required] - --shared shared allows usage of this private network from other networks + --addressfamily string addressfamily of the network to acquire [optional] (default "ipv4") + -d, --description string description of the network to create. [optional] + --dmz use this private network as dmz. [optional] + -h, --help help for allocate + --labels strings labels for this network. [optional] + --length int bitlength of network to create. [optional] (default 22) + -n, --name string name of the network to create. [required] + --partition string partition where this network should exist. [required] + --project string partition where this network should exist. [required] + --shared shared allows usage of this private network from other networks ``` ### Options inherited from parent commands diff --git a/docs/metalctl_network_list.md b/docs/metalctl_network_list.md index 9197c12..595d624 100644 --- a/docs/metalctl_network_list.md +++ b/docs/metalctl_network_list.md @@ -9,6 +9,7 @@ metalctl network list [flags] ### Options ``` + --addressfamily string addressfamily to filter, either ipv4 or ipv6 [optional] --destination-prefixes strings destination prefixes to filter, use it like: --destination-prefixes prefix1,prefix2. -h, --help help for list --id string ID to filter [optional] diff --git a/go.mod b/go.mod index 977b2ee..f9bcb2f 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/go-openapi/strfmt v0.23.0 github.com/google/go-cmp v0.6.0 github.com/google/uuid v1.6.0 - github.com/metal-stack/metal-go v0.32.2 + github.com/metal-stack/metal-go v0.32.2-0.20240711103636-2b8da1b20985 github.com/metal-stack/metal-lib v0.17.1 github.com/metal-stack/updater v1.2.2 github.com/metal-stack/v v1.0.3 diff --git a/go.sum b/go.sum index 3719e85..e15af4c 100644 --- a/go.sum +++ b/go.sum @@ -235,8 +235,8 @@ github.com/mdlayher/sdnotify v1.0.0 h1:Ma9XeLVN/l0qpyx1tNeMSeTjCPH6NtuD6/N9XdTlQ github.com/mdlayher/sdnotify v1.0.0/go.mod h1:HQUmpM4XgYkhDLtd+Uad8ZFK1T9D5+pNxnXQjCeJlGE= github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos= github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ= -github.com/metal-stack/metal-go v0.32.2 h1:vD1LtGVAeLx9vrPrguPBchXYsp7/oZ5MfTnfUO/yMz0= -github.com/metal-stack/metal-go v0.32.2/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ= +github.com/metal-stack/metal-go v0.32.2-0.20240711103636-2b8da1b20985 h1:pUAez+Jc8XqJkaxBb6OPZeDECrvx8M6N89jgW7FjtYY= +github.com/metal-stack/metal-go v0.32.2-0.20240711103636-2b8da1b20985/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ= github.com/metal-stack/metal-lib v0.17.1 h1:JLa4wJ62dgxtY9UOLF+QDk10/i/W5vhzrv8RsundDUY= github.com/metal-stack/metal-lib v0.17.1/go.mod h1:nyNGI4DZFOcWbSoq2Y6V3SHpFxuXBIqYBZHTb6cy//s= github.com/metal-stack/security v0.8.0 h1:tVaSDB9m5clwYrnLyaXfPy7mQlJTnmeoHscG+RUy/xo=