Browse Source

Merge pull request #766 from gravitl/feature_v0.10.1_macaddress_node_set

set macaddress and nodeid if not set
dcarns 3 years ago
parent
commit
4310711fa4
2 changed files with 12 additions and 18 deletions
  1. 2 1
      netclient/functions/join.go
  2. 10 17
      servercfg/serverconf.go

+ 2 - 1
netclient/functions/join.go

@@ -103,7 +103,8 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
 	if cfg.Node.MacAddress == "" {
 		macs, err := ncutils.GetMacAddr()
 		if err != nil {
-			return err
+			//if macaddress can't be found set to random string
+			cfg.Node.MacAddress = ncutils.MakeRandomString(18)
 		} else {
 			cfg.Node.MacAddress = macs[0]
 		}

+ 10 - 17
servercfg/serverconf.go

@@ -3,7 +3,6 @@ package servercfg
 import (
 	"errors"
 	"io"
-	"net"
 	"net/http"
 	"os"
 	"strconv"
@@ -541,15 +540,25 @@ func IsHostNetwork() bool {
 // GetNodeID - gets the node id
 func GetNodeID() string {
 	var id string
+	var err error
 	// id = getMacAddr()
 	if os.Getenv("NODE_ID") != "" {
 		id = os.Getenv("NODE_ID")
 	} else if config.Config.Server.NodeID != "" {
 		id = config.Config.Server.NodeID
+	} else {
+		id, err = os.Hostname()
+		if err != nil {
+			return ""
+		}
 	}
 	return id
 }
 
+func SetNodeID(id string) {
+	config.Config.Server.NodeID = id
+}
+
 // GetServerCheckinInterval - gets the server check-in time
 func GetServerCheckinInterval() int64 {
 	var t = int64(5)
@@ -592,22 +601,6 @@ func GetAzureTenant() string {
 	return azureTenant
 }
 
-// GetMacAddr - get's mac address
-func getMacAddr() string {
-	ifas, err := net.Interfaces()
-	if err != nil {
-		return ""
-	}
-	var as []string
-	for _, ifa := range ifas {
-		a := ifa.HardwareAddr.String()
-		if a != "" {
-			as = append(as, a)
-		}
-	}
-	return as[0]
-}
-
 // GetRce - sees if Rce is enabled, off by default
 func GetRce() bool {
 	return os.Getenv("RCE") == "on" || config.Config.Server.RCE == "on"