From 8c1af875d123cb0f383471fc3f3a43cc7e2b1ee1 Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Thu, 4 Jul 2024 15:01:47 +0200 Subject: [PATCH] IPv6 Support --- cmd/network.go | 12 ++++++++++++ cmd/partition.go | 9 ++++----- cmd/partition_test.go | 19 ++++++++----------- docs/metalctl_network_allocate.md | 18 ++++++++++-------- go.mod | 2 +- go.sum | 4 ++-- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/cmd/network.go b/cmd/network.go index 2ad1ec83..78e92ec4 100644 --- a/cmd/network.go +++ b/cmd/network.go @@ -3,6 +3,7 @@ package cmd import ( "errors" "fmt" + "strings" "slices" @@ -103,6 +104,12 @@ func newNetworkCmd(c *config) *cobra.Command { return err } + af := viper.GetString("addressfamily") + length := viper.GetInt64("length") + if strings.ToLower(af) == "ipv6" && !viper.IsSet("length") { + length = 64 + } + return w.childCLI.CreateAndPrint(&models.V1NetworkAllocateRequest{ Description: viper.GetString("description"), Name: viper.GetString("name"), @@ -112,6 +119,8 @@ func newNetworkCmd(c *config) *cobra.Command { Labels: labels, Destinationprefixes: destinationPrefixes, Nat: nat, + AddressFamily: af, + Length: length, }, c.describePrinter) } @@ -140,6 +149,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)) @@ -233,6 +244,7 @@ func networkResponseToCreate(r *models.V1NetworkResponse) *models.V1NetworkCreat Nat: r.Nat, Parentnetworkid: r.Parentnetworkid, Partitionid: r.Partitionid, + Childprefixlength: r.Childprefixlength, Prefixes: r.Prefixes, Privatesuper: r.Privatesuper, Projectid: r.Projectid, diff --git a/cmd/partition.go b/cmd/partition.go index 61de9942..3832b6b0 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 43b2d317..d4bf3ac2 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 7fc60398..9c8df92f 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/go.mod b/go.mod index 8a847fd9..10784180 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.0 + github.com/metal-stack/metal-go v0.32.2-0.20240704124903-f041691ac142 github.com/metal-stack/metal-lib v0.17.0 github.com/metal-stack/updater v1.2.1 github.com/metal-stack/v v1.0.3 diff --git a/go.sum b/go.sum index 28ac93ab..7bbe721a 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.0 h1:8wpKkyx36qw4oKB0tt/95uENrw40DkCFbjq7bFz3KMs= -github.com/metal-stack/metal-go v0.32.0/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ= +github.com/metal-stack/metal-go v0.32.2-0.20240704124903-f041691ac142 h1:dLlmlLArovenE5Dw+24mScawh8zuFy7t6B6gzfP61zk= +github.com/metal-stack/metal-go v0.32.2-0.20240704124903-f041691ac142/go.mod h1:3MJTYCS4YJz8D8oteTKhjpaAKNMMjMKYDrIy9awHGtQ= github.com/metal-stack/metal-lib v0.17.0 h1:0fCRUtYweJ5wbUwiEalFGiHkEz0mZwTWQUIIo3Npzkw= github.com/metal-stack/metal-lib v0.17.0/go.mod h1:nyNGI4DZFOcWbSoq2Y6V3SHpFxuXBIqYBZHTb6cy//s= github.com/metal-stack/security v0.8.0 h1:tVaSDB9m5clwYrnLyaXfPy7mQlJTnmeoHscG+RUy/xo=