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

client config now in clients.toml. also some shutdown simplification

parent aad7e9a3
Branches
Tags
2 merge requests!51Resolve "Read RESTCONF Client from config.toml",!18Develop
[[client]]
identifier = "ciena-mcp"
endpoint = "141.100.70.170:8080"
\ No newline at end of file
......@@ -18,6 +18,13 @@ type controllerConfig struct {
ConfigPath string
}
type clientConfig struct{
identifier string
endpoint string
username string
password string
}
type Core struct {
//Assert type with clients[key].(*MCPClient)
clients map[string]interfaces.Client
......@@ -26,33 +33,22 @@ type Core struct {
IsRunning chan bool
}
func (c *Core) Init(socket, configfile string, IsRunningChannel chan bool) {
if configfile == "" {
configfile = "gosdn.toml"
}
_, err := os.Stat(configfile)
if err != nil {
log.Fatal("Config file is missing: ", configfile)
}
c.config = controllerConfig{}
if _, err := toml.DecodeFile(configfile, &c.config); err != nil {
func (c *Core) Init(socket, configFileController, configFileClient string, IsRunningChannel chan bool) {
if err := c.readControllerConfig(configFileController); err != nil {
log.Fatal(err)
}
if socket != "localhost:55055" {
c.config.CliSocket = socket
}
if c.config.ConfigPath == "" {
c.config.ConfigPath = configfile
}
c.AttachDatabase()
c.IsRunning = IsRunningChannel
//TODO: Create client config/CLI adapter
c.clients["ciena-mcp"] = ciena.NewMCPClient("141.100.70.170:8080", "", "", &c.database)
if err := c.readClientConfig(configFileClient); err != nil {
log.Fatal(err)
}
}
func (c *Core) AttachDatabase() {
......@@ -61,13 +57,8 @@ func (c *Core) AttachDatabase() {
func (c *Core) Shutdown() {
stopIt := <- c.IsRunning
if !stopIt {
log.Debug("Shutdown() received action to shutdown")
}else {
log.Debug("Shutdown() received something else.")
}
<- c.IsRunning
log.Info("Received shutdown signal. Shutting down")
f, err := os.Create(c.config.ConfigPath)
if err != nil {
......@@ -77,6 +68,42 @@ func (c *Core) Shutdown() {
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 = "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
}
func (c *Core)readClientConfig(configFileClient string) error {
if configFileClient == "" {
configFileClient = "clients.toml"
}
if _,err := os.Stat(configFileClient); err != nil {
return err
}
clients := make([]clientConfig, 0)
if _,err := toml.DecodeFile(configFileClient, &clients); err != nil {
return err
}
for _,client := range clients {
c.clients[client.identifier] = ciena.NewMCPClient(client.endpoint, client.username, client.password, &c.database)
}
return nil
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ func StartAndRun(socket, filename string, IsRunningChannel chan bool) {
clients: make(map[string]interfaces.Client),
database: database.Database{},
}
core.Init(socket, filename, IsRunningChannel)
core.Init(socket, filename,"", IsRunningChannel)
// Start the GRCP CLI
go getCLIGoing(&core)
go core.Shutdown()
......@@ -25,10 +25,8 @@ func StartAndRun(socket, filename string, IsRunningChannel chan bool) {
log.Info("and ready for take off")
//Just to produce some signs of vitality...
for (true) {
for {
time.Sleep(10 * time.Second)
log.Debug("Still alive...")
}
log.Info("Good bye....!")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment