create_egress.go 1002 B

12345678910111213141516171819202122232425262728293031323334
  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 nodeCreateEgressCmd = &cobra.Command{
  9. Use: "create_egress [NETWORK NAME] [NODE ID] [EGRESS GATEWAY ADDRESSES (comma separated)]",
  10. Args: cobra.ExactArgs(3),
  11. Short: "Turn a Node into a Egress",
  12. Long: `Turn a Node into a Egress`,
  13. Run: func(cmd *cobra.Command, args []string) {
  14. egress := &models.EgressGatewayRequest{
  15. NetID: args[0],
  16. NodeID: args[1],
  17. Interface: networkInterface,
  18. Ranges: strings.Split(args[2], ","),
  19. }
  20. if natEnabled {
  21. egress.NatEnabled = "yes"
  22. }
  23. functions.PrettyPrint(functions.CreateEgress(args[0], args[1], egress))
  24. },
  25. }
  26. func init() {
  27. nodeCreateEgressCmd.Flags().StringVar(&networkInterface, "interface", "", "Network interface name (ex:- eth0)")
  28. nodeCreateEgressCmd.Flags().BoolVar(&natEnabled, "nat", false, "Enable NAT for Egress Traffic ?")
  29. rootCmd.AddCommand(nodeCreateEgressCmd)
  30. }