Skip to content
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

IPv6 Support #252

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/completion/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
49 changes: 34 additions & 15 deletions cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
Expand Down Expand Up @@ -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"),
Expand All @@ -112,6 +125,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 +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))

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

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
1 change: 1 addition & 0 deletions docs/metalctl_network_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
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.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
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.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=
Expand Down
Loading