|
@@ -3,8 +3,10 @@ package node
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"log"
|
|
|
+ "net"
|
|
|
"os"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/gravitl/netmaker/cli/functions"
|
|
|
"github.com/gravitl/netmaker/models"
|
|
@@ -31,45 +33,43 @@ var nodeUpdateCmd = &cobra.Command{
|
|
|
log.Fatal(err)
|
|
|
}
|
|
|
} else {
|
|
|
- if endpoint != "" {
|
|
|
- node.Endpoint = endpoint
|
|
|
- node.IsStatic = "no"
|
|
|
+ if address != "" {
|
|
|
+ if _, addr, err := net.ParseCIDR(address); err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ } else {
|
|
|
+ node.Address = *addr
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if address6 != "" {
|
|
|
+ if _, addr6, err := net.ParseCIDR(address6); err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ } else {
|
|
|
+ node.Address6 = *addr6
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if localAddress != "" {
|
|
|
+ if _, localAddr, err := net.ParseCIDR(localAddress); err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ } else {
|
|
|
+ node.LocalAddress = *localAddr
|
|
|
+ node.IsLocal = true
|
|
|
+ }
|
|
|
}
|
|
|
- node.ListenPort = int32(listenPort)
|
|
|
- node.Address = address
|
|
|
- node.Address6 = address6
|
|
|
- node.LocalAddress = localAddress
|
|
|
- node.Name = name
|
|
|
node.PostUp = postUp
|
|
|
node.PostDown = postDown
|
|
|
- if allowedIPs != "" {
|
|
|
- node.AllowedIPs = strings.Split(allowedIPs, ",")
|
|
|
- }
|
|
|
- node.PersistentKeepalive = int32(keepAlive)
|
|
|
+ node.PersistentKeepalive = time.Duration(time.Second * time.Duration(keepAlive))
|
|
|
if relayAddrs != "" {
|
|
|
node.RelayAddrs = strings.Split(relayAddrs, ",")
|
|
|
}
|
|
|
if egressGatewayRanges != "" {
|
|
|
node.EgressGatewayRanges = strings.Split(egressGatewayRanges, ",")
|
|
|
}
|
|
|
- if localRange != "" {
|
|
|
- node.LocalRange = localRange
|
|
|
- node.IsLocal = "yes"
|
|
|
- }
|
|
|
- node.MTU = int32(mtu)
|
|
|
- node.ExpirationDateTime = int64(expirationDateTime)
|
|
|
+ node.ExpirationDateTime = time.Unix(int64(expirationDateTime), 0)
|
|
|
if defaultACL {
|
|
|
node.DefaultACL = "yes"
|
|
|
}
|
|
|
- if dnsOn {
|
|
|
- node.DNSOn = "yes"
|
|
|
- }
|
|
|
- if disconnect {
|
|
|
- node.Connected = "no"
|
|
|
- }
|
|
|
- if networkHub {
|
|
|
- node.IsHub = "yes"
|
|
|
- }
|
|
|
+ node.DNSOn = dnsOn
|
|
|
+ node.Connected = !disconnect
|
|
|
}
|
|
|
functions.PrettyPrint(functions.UpdateNode(networkName, nodeID, node))
|
|
|
},
|
|
@@ -77,24 +77,18 @@ var nodeUpdateCmd = &cobra.Command{
|
|
|
|
|
|
func init() {
|
|
|
nodeUpdateCmd.Flags().StringVar(&nodeDefinitionFilePath, "file", "", "Filepath of updated node definition in JSON")
|
|
|
- nodeUpdateCmd.Flags().StringVar(&endpoint, "endpoint", "", "Public endpoint of the node")
|
|
|
- nodeUpdateCmd.Flags().IntVar(&listenPort, "listen_port", 0, "Default wireguard port for the node")
|
|
|
nodeUpdateCmd.Flags().StringVar(&address, "ipv4_addr", "", "IPv4 address of the node")
|
|
|
nodeUpdateCmd.Flags().StringVar(&address6, "ipv6_addr", "", "IPv6 address of the node")
|
|
|
nodeUpdateCmd.Flags().StringVar(&localAddress, "local_addr", "", "Locally reachable address of the node")
|
|
|
nodeUpdateCmd.Flags().StringVar(&name, "name", "", "Node name")
|
|
|
nodeUpdateCmd.Flags().StringVar(&postUp, "post_up", "", "Commands to run after node is up `;` separated")
|
|
|
nodeUpdateCmd.Flags().StringVar(&postDown, "post_down", "", "Commands to run after node is down `;` separated")
|
|
|
- nodeUpdateCmd.Flags().StringVar(&allowedIPs, "allowed_addrs", "", "Additional private addresses given to the node (comma separated)")
|
|
|
nodeUpdateCmd.Flags().IntVar(&keepAlive, "keep_alive", 0, "Interval in which packets are sent to keep connections open with peers")
|
|
|
nodeUpdateCmd.Flags().StringVar(&relayAddrs, "relay_addrs", "", "Addresses for relaying connections if node acts as a relay")
|
|
|
nodeUpdateCmd.Flags().StringVar(&egressGatewayRanges, "egress_addrs", "", "Addresses for egressing traffic if node acts as an egress")
|
|
|
- nodeUpdateCmd.Flags().StringVar(&localRange, "local_range", "", "Local range in which the node will look for private addresses to use as an endpoint if `LocalNetwork` is enabled")
|
|
|
- nodeUpdateCmd.Flags().IntVar(&mtu, "mtu", 0, "MTU size")
|
|
|
nodeUpdateCmd.Flags().IntVar(&expirationDateTime, "expiry", 0, "UNIX timestamp after which node will lose access to the network")
|
|
|
nodeUpdateCmd.Flags().BoolVar(&defaultACL, "acl", false, "Enable default ACL ?")
|
|
|
nodeUpdateCmd.Flags().BoolVar(&dnsOn, "dns", false, "Setup DNS entries for peers locally ?")
|
|
|
nodeUpdateCmd.Flags().BoolVar(&disconnect, "disconnect", false, "Disconnect from the network ?")
|
|
|
- nodeUpdateCmd.Flags().BoolVar(&networkHub, "hub", false, "On a point to site network, this node is the only one which all peers connect to ?")
|
|
|
rootCmd.AddCommand(nodeUpdateCmd)
|
|
|
}
|