Skip to content

Commit

Permalink
IPv6 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Jul 7, 2024
1 parent e922dcf commit 8c1af87
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 27 deletions.
12 changes: 12 additions & 0 deletions cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"errors"
"fmt"
"strings"

"slices"

Expand Down Expand Up @@ -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"),
Expand All @@ -112,6 +119,8 @@ func newNetworkCmd(c *config) *cobra.Command {
Labels: labels,
Destinationprefixes: destinationPrefixes,
Nat: nat,
AddressFamily: af,
Length: length,
}, c.describePrinter)
}

Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions cmd/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
19 changes: 8 additions & 11 deletions cmd/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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",
}
)

Expand Down Expand Up @@ -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)
Expand Down
18 changes: 10 additions & 8 deletions docs/metalctl_network_allocate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 8c1af87

Please sign in to comment.