diff --git a/cli/network_add_subnet.go b/cli/network_add_subnet.go index 04f333d6..138d576f 100644 --- a/cli/network_add_subnet.go +++ b/cli/network_add_subnet.go @@ -21,16 +21,17 @@ func newNetworkAddSubnetCommand(cli *CLI) *cobra.Command { RunE: cli.wrap(runNetworkAddSubnet), } - cmd.Flags().String("type", "", "Type of subnet") - cmd.RegisterFlagCompletionFunc("type", cmpl.SuggestCandidates("cloud", "server")) + cmd.Flags().String("type", "", "Type of subnet (required)") + cmd.RegisterFlagCompletionFunc("type", cmpl.SuggestCandidates("cloud", "server", "vswitch")) cmd.MarkFlagRequired("type") - cmd.Flags().String("network-zone", "", "Name of network zone") + cmd.Flags().String("network-zone", "", "Name of network zone (required)") cmd.RegisterFlagCompletionFunc("network-zone", cmpl.SuggestCandidates("eu-central")) cmd.MarkFlagRequired("network-zone") cmd.Flags().IPNet("ip-range", net.IPNet{}, "Range to allocate IPs from") + cmd.Flags().Int("vswitch-id", 0, "ID of the vSwitch") return cmd } @@ -38,6 +39,7 @@ func runNetworkAddSubnet(cli *CLI, cmd *cobra.Command, args []string) error { subnetType, _ := cmd.Flags().GetString("type") networkZone, _ := cmd.Flags().GetString("network-zone") ipRange, _ := cmd.Flags().GetIPNet("ip-range") + vSwitchID, _ := cmd.Flags().GetInt("vswitch-id") idOrName := args[0] network, _, err := cli.Client().Network.Get(cli.Context, idOrName) @@ -55,6 +57,9 @@ func runNetworkAddSubnet(cli *CLI, cmd *cobra.Command, args []string) error { if ipRange.IP != nil && ipRange.Mask != nil { subnet.IPRange = &ipRange } + if subnetType == "vswitch" { + subnet.VSwitchID = vSwitchID + } opts := hcloud.NetworkAddSubnetOpts{ Subnet: subnet, diff --git a/cli/network_describe.go b/cli/network_describe.go index 6184ca09..8b6b1240 100644 --- a/cli/network_describe.go +++ b/cli/network_describe.go @@ -61,6 +61,9 @@ func networkDescribeText(cli *CLI, network *hcloud.Network) error { fmt.Printf(" Network Zone:\t%s\n", subnet.NetworkZone) fmt.Printf(" IP Range:\t\t%s\n", subnet.IPRange.String()) fmt.Printf(" Gateway:\t\t%s\n", subnet.Gateway.String()) + if subnet.Type == hcloud.NetworkSubnetTypeVSwitch { + fmt.Printf(" vSwitch ID:\t\t%d\n", subnet.VSwitchID) + } } } diff --git a/go.mod b/go.mod index 4bea0762..ef67b7af 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ require ( github.com/cheggaaa/pb/v3 v3.0.5 github.com/dustin/go-humanize v1.0.0 github.com/fatih/structs v1.1.0 - github.com/hetznercloud/hcloud-go v1.22.0 + github.com/hetznercloud/hcloud-go v1.23.1 github.com/pelletier/go-toml v1.8.0 github.com/spf13/cobra v1.1.1 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 91bacdfc..78856949 100644 --- a/go.sum +++ b/go.sum @@ -101,8 +101,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/hetznercloud/hcloud-go v1.22.0 h1:CC0jwkaBzwP4ObFE0sdJBTvGh5DE9kB/tuDETnRfOik= -github.com/hetznercloud/hcloud-go v1.22.0/go.mod h1:xng8lbDUg+xM1dgc0yGHX5EeqbwIq7UYlMWMTx3SQVg= +github.com/hetznercloud/hcloud-go v1.23.1 h1:SkYdCa6x458cMSDz5GI18iPz5j2hicACiDP6J/s/bTs= +github.com/hetznercloud/hcloud-go v1.23.1/go.mod h1:xng8lbDUg+xM1dgc0yGHX5EeqbwIq7UYlMWMTx3SQVg= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=