-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(network): add support for exposing routes to vswitch connection
Feature was released today. This adds: - Showing the field in `network describe` (also for `-o json`) - Setting the field through flag on `network create` - Updating the setting through the command `network expose-routes-to-vswitch`
- Loading branch information
Showing
5 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package network | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hetznercloud/cli/internal/cmd/base" | ||
"github.com/hetznercloud/cli/internal/cmd/cmpl" | ||
"github.com/hetznercloud/cli/internal/hcapi2" | ||
"github.com/hetznercloud/cli/internal/state" | ||
"github.com/hetznercloud/hcloud-go/hcloud" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ExposeRoutesToVSwitchCommand = base.Cmd{ | ||
BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "expose-routes-to-vswitch [flags] network", | ||
Short: "Expose routes to connected vSwitch", | ||
Long: "Enabling this will expose routes to the connected vSwitch. Set the --disable flag to remove the exposed routes.", | ||
Args: cobra.ExactArgs(1), | ||
ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Network().Names)), | ||
TraverseChildren: true, | ||
DisableFlagsInUseLine: true, | ||
} | ||
|
||
cmd.Flags().Bool("disable", false, "Remove any exposed routes from the connected vSwitch") | ||
|
||
return cmd | ||
}, | ||
Run: func(ctx context.Context, client hcapi2.Client, waiter state.ActionWaiter, cmd *cobra.Command, args []string) error { | ||
idOrName := args[0] | ||
network, _, err := client.Network().Get(ctx, idOrName) | ||
if err != nil { | ||
return err | ||
} | ||
if network == nil { | ||
return fmt.Errorf("network not found: %s", idOrName) | ||
} | ||
|
||
disable, _ := cmd.Flags().GetBool("disable") | ||
opts := hcloud.NetworkUpdateOpts{ | ||
ExposeRoutesToVSwitch: hcloud.Ptr(!disable), | ||
} | ||
|
||
_, _, err = client.Network().Update(ctx, network, opts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if disable { | ||
fmt.Printf("Exposing routes to connected vSwitch of network %s disabled\n", network.Name) | ||
} else { | ||
fmt.Printf("Exposing routes to connected vSwitch of network %s enabled\n", network.Name) | ||
} | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters