Skip to content

Commit

Permalink
Add vswitch integration (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
LKaemmerling authored Nov 3, 2020
1 parent 9d209c0 commit 178bf96
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
11 changes: 8 additions & 3 deletions cli/network_add_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ 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
}

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)
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions cli/network_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

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

0 comments on commit 178bf96

Please sign in to comment.