Skip to content
Snippets Groups Projects
Commit f75a0547 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

include spf13/viper for config

parent e9246fb5
No related branches found
No related tags found
3 merge requests!90Develop,!88Use SPF Viper for configuration,!53V.0.1.0 Codename Threadbare
CliSocket = "localhost:55055"
DatabaseSocket = "bolt://172.17.0.4:7687"
DatabaseUser = ""
DatabasePassword = ""
DatabaseCrypto = false
ConfigPath = "./configs/gosdn.toml"
db.socket = "bolt://172.17.0.4:7687"
db.user = ""
db.password = ""
db.crypto = false
......@@ -4,6 +4,7 @@ import (
"errors"
"github.com/neo4j/neo4j-go-driver/neo4j"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
//Database is a database
......@@ -19,7 +20,11 @@ type PND struct {
}
//NewDatabaseClient creates a database ciena
func NewDatabaseClient(uri, username, password string, encrypted bool) Database {
func NewDatabaseClient() Database {
uri := viper.GetString("db.socket")
username := viper.GetString("db.user")
password := viper.GetString("db.password")
encrypted := viper.GetBool("db.crypto")
driver := createDriver(uri, username, password, encrypted)
return Database{
......
goarista @ 09b37ed2
Subproject commit 09b37ed24462f5dfc3c5e47abecd790c5540f327
......@@ -5,23 +5,23 @@ go 1.14
require (
code.fbi.h-da.de/cocsn/swagger/apis v0.0.0-20200924152423-61030cab7b88
code.fbi.h-da.de/cocsn/yang-models v0.0.3
github.com/BurntSushi/toml v0.3.1
github.com/aristanetworks/goarista v0.0.0-20201120222254-94a892eb0c6a
github.com/aristanetworks/goarista v0.0.0-20201120222254-94a892eb0c6a // indirect
github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591
github.com/go-openapi/runtime v0.19.22
github.com/go-openapi/strfmt v0.19.5
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/protobuf v1.4.2
github.com/google/uuid v1.1.2
github.com/neo4j/neo4j-go-driver v1.8.3
github.com/onsi/ginkgo v1.13.0 // indirect
github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802
github.com/openconfig/reference v0.0.0-20190727015836-8dfd928c9696
github.com/openconfig/reference v0.0.0-20190727015836-8dfd928c9696 // indirect
github.com/openconfig/ygot v0.8.11
github.com/rivo/tview v0.0.0-20201018122409-d551c850a743
github.com/sirupsen/logrus v1.4.2
github.com/spf13/viper v1.7.1
github.com/tidwall/gjson v1.6.3
golang.org/x/net v0.0.0-20200904194848-62affa334b73
golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect
google.golang.org/grpc v1.29.1
google.golang.org/protobuf v1.25.0
)
This diff is collapsed.
......@@ -2,9 +2,10 @@ package nucleus
import (
"code.fbi.h-da.de/cocsn/gosdn/database"
"github.com/BurntSushi/toml"
"fmt"
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"os"
)
......@@ -27,15 +28,19 @@ type Core struct {
}
//Initialize does start-up housekeeping like reading controller config files
func (c *Core) Initialize(socket, configFileController, configFileClient string, IsRunningChannel chan bool) {
if err := c.readControllerConfig(configFileController); err != nil {
log.Fatal(err)
}
func (c *Core) Initialize(IsRunningChannel chan bool) {
// Set config defaults
viper.SetDefault("socket", "localhost:55055")
if socket != "localhost:55055" {
c.config.CliSocket = socket
// Set config path and read config
viper.SetConfigName("gosdn")
viper.SetConfigType("toml")
viper.AddConfigPath("/usr/local/etc/gosdn/")
viper.AddConfigPath("./configs/")
err := viper.ReadInConfig()
if err != nil {
log.Fatal(fmt.Errorf("Fatal error config file: %s \n", err))
}
c.AttachDatabase()
c.IsRunning = IsRunningChannel
......@@ -43,7 +48,7 @@ func (c *Core) Initialize(socket, configFileController, configFileClient string,
// AttachDatabase connects to the database and passes the connectio to the controller core
func (c *Core) AttachDatabase() {
c.database = database.NewDatabaseClient(c.config.DatabaseSocket, c.config.DatabaseUser, c.config.DatabasePassword, c.config.DatabaseCrypto)
c.database = database.NewDatabaseClient()
}
// Shutdown waits for the shutdown signal and gracefully shuts down once it arrived
......@@ -51,33 +56,10 @@ func (c *Core) Shutdown() {
<-c.IsRunning
log.Info("Received shutdown signal. Shutting down")
f, err := os.Create(c.config.ConfigPath)
err := viper.WriteConfig()
if err != nil {
log.Fatal(err)
}
enc := toml.NewEncoder(f)
if err := enc.Encode(c.config); err != nil {
log.Fatal(err)
}
log.Info("Shutdown complete")
os.Exit(0)
}
func (c *Core) readControllerConfig(configFileController string) error {
if configFileController == "" {
configFileController = "configs/gosdn.toml"
}
if _, err := os.Stat(configFileController); err != nil {
return err
}
c.config = controllerConfig{}
if _, err := toml.DecodeFile(configFileController, &c.config); err != nil {
return err
}
if c.config.ConfigPath == "" {
c.config.ConfigPath = configFileController
}
return nil
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ import (
)
//StartAndRun is used to start the core of the controller and any auxiliary services.
func StartAndRun(socket, filename string, IsRunningChannel chan bool) {
func StartAndRun(IsRunningChannel chan bool) {
log.Info("This is the network superintendent...")
log.Info("Starting my ducks")
......@@ -15,7 +15,7 @@ func StartAndRun(socket, filename string, IsRunningChannel chan bool) {
core := Core{
database: database.Database{},
}
core.Initialize(socket, filename, "", IsRunningChannel)
core.Initialize(IsRunningChannel)
// Start the GRCP CLI
go getCLIGoing(&core)
go core.Shutdown()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment