create_egress.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package node
  2. import (
  3. "strings"
  4. "github.com/gravitl/netmaker/cli/functions"
  5. "github.com/gravitl/netmaker/models"
  6. "github.com/spf13/cobra"
  7. )
  8. var (
  9. networkInterface string
  10. natEnabled bool
  11. )
  12. var nodeCreateEgressCmd = &cobra.Command{
  13. Use: "create_egress [NETWORK NAME] [NODE ID] [EGRESS GATEWAY ADDRESSES (comma separated)]",
  14. Args: cobra.ExactArgs(3),
  15. Short: "Turn a Node into a Egress",
  16. Long: `Turn a Node into a Egress`,
  17. Run: func(cmd *cobra.Command, args []string) {
  18. egress := &models.EgressGatewayRequest{
  19. NetID: args[0],
  20. NodeID: args[1],
  21. Interface: networkInterface,
  22. Ranges: strings.Split(args[2], ","),
  23. }
  24. if natEnabled {
  25. egress.NatEnabled = "yes"
  26. }
  27. functions.PrettyPrint(functions.CreateEgress(args[0], args[1], egress))
  28. },
  29. }
  30. func init() {
  31. nodeCreateEgressCmd.Flags().StringVar(&networkInterface, "interface", "", "Network interface name (ex:- eth0)")
  32. nodeCreateEgressCmd.Flags().BoolVar(&natEnabled, "nat", false, "Enable NAT for Egress Traffic ?")
  33. rootCmd.AddCommand(nodeCreateEgressCmd)
  34. }