-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NET-1962: add gateway subcommand. (#3339)
* feat(go): add deprecation warning. * feat(go): add support for gateway commands. * feat(go): mention the server version in which the commands were deprecated.
- Loading branch information
1 parent
48535f7
commit 9a7c13b
Showing
9 changed files
with
142 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package gateway | ||
|
||
import ( | ||
"github.com/gravitl/netmaker/cli/functions" | ||
"github.com/gravitl/netmaker/models" | ||
"github.com/spf13/cobra" | ||
"strings" | ||
) | ||
|
||
var externalClientDNS string | ||
var isInternetGateway bool | ||
var metadata string | ||
var persistentKeepAlive uint | ||
var mtu uint | ||
|
||
var gatewayCreateCmd = &cobra.Command{ | ||
Use: "create [NETWORK NAME] [NODE ID] [RELAYED NODES ID (comma separated)]", | ||
Args: cobra.ExactArgs(3), | ||
Short: "Create a new Gateway on a Netmaker network.", | ||
Long: ` | ||
Configures a node as a gateway in a specified network, allowing it to relay traffic for other nodes. The gateway can also function as an internet gateway if specified. | ||
Arguments: | ||
NETWORK NAME: The name of the network where the gateway will be created. | ||
NODE ID: The ID of the node to be configured as a gateway. | ||
RELAYED NODES ID: A comma-separated list of node IDs that will be relayed through this gateway. | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
functions.PrettyPrint( | ||
functions.CreateGateway( | ||
models.IngressRequest{ | ||
ExtclientDNS: externalClientDNS, | ||
IsInternetGateway: isInternetGateway, | ||
Metadata: metadata, | ||
PersistentKeepalive: int32(persistentKeepAlive), | ||
MTU: int32(mtu), | ||
}, | ||
models.RelayRequest{ | ||
NodeID: args[0], | ||
NetID: args[1], | ||
RelayedNodes: strings.Split(args[2], ","), | ||
}, | ||
), | ||
) | ||
}, | ||
} | ||
|
||
func init() { | ||
gatewayCreateCmd.Flags().StringVarP(&externalClientDNS, "dns", "d", "", "the IP address of the DNS server to be used by external clients") | ||
gatewayCreateCmd.Flags().BoolVarP(&isInternetGateway, "internet", "i", false, "if set, the gateway will route traffic to the internet") | ||
gatewayCreateCmd.Flags().StringVarP(&metadata, "note", "n", "", "description or metadata to be associated with the gateway") | ||
gatewayCreateCmd.Flags().UintVarP(&persistentKeepAlive, "keep-alive", "k", 20, "the keep-alive interval (in seconds) for maintaining persistent connections") | ||
gatewayCreateCmd.Flags().UintVarP(&mtu, "mtu", "m", 1420, "the maximum transmission unit (MTU) size in bytes") | ||
rootCmd.AddCommand(gatewayCreateCmd) | ||
} |
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,27 @@ | ||
package gateway | ||
|
||
import ( | ||
"github.com/gravitl/netmaker/cli/functions" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var gatewayDeleteCmd = &cobra.Command{ | ||
Use: "delete [NETWORK NAME] [NODE ID]", | ||
Args: cobra.ExactArgs(2), | ||
Short: "Delete a Gateway.", | ||
Long: ` | ||
Removes the gateway configuration from a node in a specified network. The node itself remains, but it will no longer function as a gateway. | ||
Arguments: | ||
NETWORK NAME: The name of the network from which the gateway configuration should be removed. | ||
NODE ID: The ID of the node that is currently acting as a gateway. | ||
`, | ||
Aliases: []string{"rm"}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
functions.PrettyPrint(functions.DeleteGateway(args[0], args[1])) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(gatewayDeleteCmd) | ||
} |
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,18 @@ | ||
package gateway | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// rootCmd represents the base command when called without any subcommands. | ||
var rootCmd = &cobra.Command{ | ||
Use: "gateway", | ||
Short: "Manage Gateways.", | ||
Long: `Manage Gateways.`, | ||
Aliases: []string{"gw"}, | ||
} | ||
|
||
// GetRoot returns the root subcommand. | ||
func GetRoot() *cobra.Command { | ||
return rootCmd | ||
} |
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
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,18 @@ | ||
package functions | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gravitl/netmaker/models" | ||
"net/http" | ||
) | ||
|
||
func CreateGateway(ingressRequest models.IngressRequest, relayRequest models.RelayRequest) *models.ApiNode { | ||
return request[models.ApiNode](http.MethodPost, fmt.Sprintf("/api/nodes/%s/%s/gateway", relayRequest.NetID, relayRequest.NodeID), &models.CreateGwReq{ | ||
IngressRequest: ingressRequest, | ||
RelayRequest: relayRequest, | ||
}) | ||
} | ||
|
||
func DeleteGateway(networkID, nodeID string) *models.ApiNode { | ||
return request[models.ApiNode](http.MethodDelete, fmt.Sprintf("/api/nodes/%s/%s/gateway", networkID, nodeID), nil) | ||
} |