Browse Source

circular imports resolved

Matthew R. Kasun 3 years ago
parent
commit
8aeb6bbfd9
2 changed files with 10 additions and 24 deletions
  1. 5 1
      main.go
  2. 5 23
      servercfg/serverconf.go

+ 5 - 1
main.go

@@ -46,7 +46,11 @@ func initialize() { // Client Mode Prereq Check
 	}
 	}
 
 
 	if servercfg.GetNodeID() == "" {
 	if servercfg.GetNodeID() == "" {
-		logger.FatalLog("error: must set NODE_ID, currently blank")
+		id, err := os.Hostname()
+		if err != nil {
+			id = ncutils.MakeRandomString(10)
+		}
+		servercfg.SetNodeID(id)
 	}
 	}
 
 
 	if err = database.InitializeDatabase(); err != nil {
 	if err = database.InitializeDatabase(); err != nil {

+ 5 - 23
servercfg/serverconf.go

@@ -3,14 +3,12 @@ package servercfg
 import (
 import (
 	"errors"
 	"errors"
 	"io"
 	"io"
-	"net"
 	"net/http"
 	"net/http"
 	"os"
 	"os"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 
 
 	"github.com/gravitl/netmaker/config"
 	"github.com/gravitl/netmaker/config"
-	"github.com/gravitl/netmaker/netclient/ncutils"
 )
 )
 
 
 var Version = "dev"
 var Version = "dev"
@@ -546,15 +544,15 @@ func GetNodeID() string {
 	if os.Getenv("NODE_ID") != "" {
 	if os.Getenv("NODE_ID") != "" {
 		id = os.Getenv("NODE_ID")
 		id = os.Getenv("NODE_ID")
 	} else if config.Config.Server.NodeID != "" {
 	} else if config.Config.Server.NodeID != "" {
-		id, err := os.Hostname()
-		if err != nil {
-			id = ncutils.MakeRandomString(10)
-		}
-		config.Config.Server.NodeID = id
+		id = config.Config.Server.NodeID
 	}
 	}
 	return id
 	return id
 }
 }
 
 
+func SetNodeID(id string) {
+	config.Config.Server.NodeID = id
+}
+
 // GetServerCheckinInterval - gets the server check-in time
 // GetServerCheckinInterval - gets the server check-in time
 func GetServerCheckinInterval() int64 {
 func GetServerCheckinInterval() int64 {
 	var t = int64(5)
 	var t = int64(5)
@@ -597,22 +595,6 @@ func GetAzureTenant() string {
 	return azureTenant
 	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
 // GetRce - sees if Rce is enabled, off by default
 func GetRce() bool {
 func GetRce() bool {
 	return os.Getenv("RCE") == "on" || config.Config.Server.RCE == "on"
 	return os.Getenv("RCE") == "on" || config.Config.Server.RCE == "on"