Browse Source

set macaddress and nodeid if not set

Matthew R. Kasun 3 years ago
parent
commit
16cf0eaeed
2 changed files with 8 additions and 2 deletions
  1. 2 1
      netclient/functions/join.go
  2. 6 1
      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]
 		}

+ 6 - 1
servercfg/serverconf.go

@@ -10,6 +10,7 @@ import (
 	"strings"
 
 	"github.com/gravitl/netmaker/config"
+	"github.com/gravitl/netmaker/netclient/ncutils"
 )
 
 var Version = "dev"
@@ -545,7 +546,11 @@ func GetNodeID() string {
 	if os.Getenv("NODE_ID") != "" {
 		id = os.Getenv("NODE_ID")
 	} else if config.Config.Server.NodeID != "" {
-		id = config.Config.Server.NodeID
+		id, err := os.Hostname()
+		if err != nil {
+			id = ncutils.MakeRandomString(10)
+		}
+		config.Config.Server.NodeID = id
 	}
 	return id
 }