create.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package gateway
  2. import (
  3. "github.com/gravitl/netmaker/cli/functions"
  4. "github.com/gravitl/netmaker/models"
  5. "github.com/spf13/cobra"
  6. "strings"
  7. )
  8. var externalClientDNS string
  9. var isInternetGateway bool
  10. var metadata string
  11. var persistentKeepAlive uint
  12. var mtu uint
  13. var gatewayCreateCmd = &cobra.Command{
  14. Use: "create [NETWORK NAME] [NODE ID] [RELAYED NODES ID (comma separated)]",
  15. Args: cobra.ExactArgs(3),
  16. Short: "Create a new Gateway on a Netmaker network.",
  17. Long: `
  18. 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.
  19. Arguments:
  20. NETWORK NAME: The name of the network where the gateway will be created.
  21. NODE ID: The ID of the node to be configured as a gateway.
  22. RELAYED NODES ID: A comma-separated list of node IDs that will be relayed through this gateway.
  23. `,
  24. Run: func(cmd *cobra.Command, args []string) {
  25. functions.PrettyPrint(
  26. functions.CreateGateway(
  27. models.IngressRequest{
  28. ExtclientDNS: externalClientDNS,
  29. IsInternetGateway: isInternetGateway,
  30. Metadata: metadata,
  31. PersistentKeepalive: int32(persistentKeepAlive),
  32. MTU: int32(mtu),
  33. },
  34. models.RelayRequest{
  35. NodeID: args[0],
  36. NetID: args[1],
  37. RelayedNodes: strings.Split(args[2], ","),
  38. },
  39. ),
  40. )
  41. },
  42. }
  43. func init() {
  44. gatewayCreateCmd.Flags().StringVarP(&externalClientDNS, "dns", "d", "", "the IP address of the DNS server to be used by external clients")
  45. gatewayCreateCmd.Flags().BoolVarP(&isInternetGateway, "internet", "i", false, "if set, the gateway will route traffic to the internet")
  46. gatewayCreateCmd.Flags().StringVarP(&metadata, "note", "n", "", "description or metadata to be associated with the gateway")
  47. gatewayCreateCmd.Flags().UintVarP(&persistentKeepAlive, "keep-alive", "k", 20, "the keep-alive interval (in seconds) for maintaining persistent connections")
  48. gatewayCreateCmd.Flags().UintVarP(&mtu, "mtu", "m", 1420, "the maximum transmission unit (MTU) size in bytes")
  49. rootCmd.AddCommand(gatewayCreateCmd)
  50. }