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

client writes to db now

parent 67a7511c
No related branches found
No related tags found
2 merge requests!24Resolve "Need common configuration storage",!18Develop
This commit is part of merge request !24. Comments created here will be created in the context of that merge request.
......@@ -105,6 +105,8 @@ func (d Database) StoreNodeEdgePoints(json string) {
}
func (d Database) StoreConnections(json string){}
//setNodeNodeEdgePointsRelation creates the database relations between "nodes" and "node edge points"
func setNodeNodeEdgePointsRelation(session neo4j.Session) {
query :=
......
......@@ -4,20 +4,16 @@ go 1.14
require (
code.fbi.h-da.de/cocsn/swagger/apis v0.0.0-20200924152423-61030cab7b88
code.fbi.h-da.de/cocsn/swagger/apis/ciena v0.0.0-20200922140607-29b1f99d0f68 // indirect
code.fbi.h-da.de/cocsn/yang-modules/generated/ciena v0.0.0-20200922150332-3e03fcde3e37 // indirect
code.fbi.h-da.de/cocsn/yang-modules/generated/tapi v0.0.0-20200922150332-3e03fcde3e37
github.com/BurntSushi/toml v0.3.1
github.com/go-openapi/runtime v0.19.22
github.com/go-openapi/strfmt v0.19.5
github.com/go-openapi/swag v0.19.9 // indirect
github.com/go-openapi/validate v0.19.11 // indirect
github.com/golang/protobuf v1.4.2
github.com/jessevdk/go-flags v1.4.0 // indirect
github.com/google/go-cmp v0.4.1 // indirect
github.com/mattn/go-sqlite3 v1.14.3
github.com/neo4j/neo4j-go-driver v1.8.3
github.com/openconfig/goyang v0.0.0-20200917201611-633eccb6fa97 // indirect
github.com/openconfig/ygot v0.8.7
golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
google.golang.org/genproto v0.0.0-20200519141106-08726f379972 // indirect
google.golang.org/grpc v1.29.1
google.golang.org/protobuf v1.23.0
)
This diff is collapsed.
package nucleus
import (
"code.fbi.h-da.de/cocsn/gosdn/database"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/interfaces"
"encoding/json"
"io/ioutil"
"github.com/BurntSushi/toml"
"log"
"os"
)
/*
+-- type controllerConfig struct
+-- type Core struct
+-- client *restconf.Client
+-- db *database.Database
+-- config controllerConfig
+-- func Init(){
read.config
db.create/attach
if config.client{
client.init
}
}
#example gosdn.toml
CliSocket="localhost:55055"
DatabaseSocket="localhost:7687"
ConfigPath="./gosdn.toml"
*/
type controllerConfig struct {
CliSocket string `json:"cli_socket"`
DatabaseSocket string `json:"database_socket"`
DatabaseUser string `json:"database_user,omitempty"`
DatabasePassword string `json:"database_password,omitempty"`
DatabaseCrypto bool `json:"database_crypto,omitempty"`
ConfigPath string `json:"config_path"`
CliSocket string
DatabaseSocket string
DatabaseUser string
DatabasePassword string
DatabaseCrypto bool
ConfigPath string
}
type Core struct {
clients []interfaces.Client
database interfaces.Database
database database.Database
config controllerConfig
}
func (c Core) Init(socket, filename string) {
if filename == "" {
filename = "gosdn.json"
func (c Core) Init(socket, configfile string) {
if configfile == "" {
configfile = "gosdn.toml"
}
config, err := ioutil.ReadFile(filename)
_, err := os.Stat(configfile)
if err != nil {
log.Fatal(err)
log.Fatal("Config file is missing: ", configfile)
}
c.config = controllerConfig{}
if err := json.Unmarshal(config, &c.config); err != nil {
if _, err := toml.DecodeFile(configfile, &c.config); err != nil {
log.Fatal(err)
}
if socket != "localhost:55055" {
c.config.CliSocket = socket
}
if c.config.ConfigPath == "" {
c.config.ConfigPath = configfile
}
c.database = interfaces.NewMockDatabaseClient(c.config.DatabaseSocket, c.config.DatabaseUser, c.config.DatabasePassword, c.config.DatabaseCrypto)
c.database = database.NewDatabaseClient(c.config.DatabaseSocket, c.config.DatabaseUser, c.config.DatabasePassword, c.config.DatabaseCrypto)
}
func (c Core) Shutdown() {
config, err := json.Marshal(c.config)
f, err := os.Create(c.config.ConfigPath)
if err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile("gosdn.json", config, 0644); err != nil {
enc := toml.NewEncoder(f)
if err := enc.Encode(c.config); err != nil {
log.Fatal(err)
}
}
package ciena
import (
"code.fbi.h-da.de/cocsn/gosdn/database"
"code.fbi.h-da.de/cocsn/gosdn/restconf/util"
apiclient "code.fbi.h-da.de/cocsn/swagger/apis/mcp/client"
"crypto/tls"
......@@ -14,6 +15,7 @@ import (
type MCPClient struct {
transport *httptransport.Runtime
client *apiclient.ServiceTopologyTAPI
database *database.Database
buf *[]byte
}
......@@ -23,7 +25,7 @@ func (c MCPClient) GetConfig() string {
}
//NewMCPClient creates a client
func NewMCPClient(endpoint, username, password string) MCPClient {
func NewMCPClient(endpoint, username, password string, database *database.Database) MCPClient {
// create the transport
transport := httptransport.New(endpoint, "/", nil)
transport.Transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
......@@ -40,30 +42,31 @@ func NewMCPClient(endpoint, username, password string) MCPClient {
return MCPClient{
transport: transport,
client: client,
database: database,
buf: &buf,
}
}
func (c MCPClient) GetConnections() (error, []byte) {
func (c MCPClient) GetConnections() error {
c.buf = nil
_, err := c.client.TapiConnectivityCore.GetTapiCoreContextConnection(nil)
responseBuffer := *c.buf
c.database.StoreConnections(string(*c.buf))
c.buf = nil
return err, responseBuffer
return err
}
func (c MCPClient) GetNodes() (error, []byte) {
func (c MCPClient) GetNodes() error {
c.buf = nil
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNode(nil)
responseBuffer := *c.buf
c.database.StoreNodes(string(*c.buf))
c.buf = nil
return err, responseBuffer
return err
}
func (c MCPClient) GetNodeEdgePoints() (error, []byte) {
func (c MCPClient) GetNodeEdgePoints() error {
c.buf = nil
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNodeEdgePoint(nil)
responseBuffer := *c.buf
c.database.StoreNodeEdgePoints(string(*c.buf))
c.buf = nil
return err, responseBuffer
return err
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment