Skip to content
Snippets Groups Projects
Commit 28b0f2c9 authored by Malte Bauch's avatar Malte Bauch
Browse files

added functions to retrieve instances of sbis

parent b2efd44b
No related branches found
No related tags found
3 merge requests!97Resolve "PND handling via CLI and database",!91"Overhaul Architecture",!90Develop
...@@ -79,9 +79,10 @@ func (c *Core) UnMarshallPNDs() error { ...@@ -79,9 +79,10 @@ func (c *Core) UnMarshallPNDs() error {
// CreateSouthboundInterfaces initializes the controller with his SBIs // CreateSouthboundInterfaces initializes the controller with his SBIs
func (c *Core) CreateSouthboundInterfaces() { func (c *Core) CreateSouthboundInterfaces() {
if len(c.southboundInterfaces) == 0 { if len(c.southboundInterfaces) == 0 {
sbi := &AristaOC{} arista := GetAristaOCInstance()
sbi.SetDefaults() c.southboundInterfaces[arista.SbiIdentifier()] = arista
c.southboundInterfaces[sbi.SbiIdentifier()] = sbi openconfig := GetOpenconfigInstance()
c.southboundInterfaces[openconfig.SbiIdentifier()] = openconfig
} }
} }
......
...@@ -42,7 +42,6 @@ func (d *Device) UnmarshalJSON(b []byte) error { ...@@ -42,7 +42,6 @@ func (d *Device) UnmarshalJSON(b []byte) error {
}, },
Transport: nil, Transport: nil,
} }
device.SBI.SetDefaults()
device.Transport = device.SBI.GetTransport() device.Transport = device.SBI.GetTransport()
device.Device = device.SBI.Schema().Root device.Device = device.SBI.Schema().Root
......
...@@ -48,12 +48,10 @@ func getSouthboundInterfaceFromJSONMap(m map[string]interface{}) SouthboundInter ...@@ -48,12 +48,10 @@ func getSouthboundInterfaceFromJSONMap(m map[string]interface{}) SouthboundInter
switch sbi := m["name"]; sbi { switch sbi := m["name"]; sbi {
case "arista": case "arista":
newSBI = &AristaOC{} newSBI = GetAristaOCInstance()
newSBI.SetDefaults()
case "openconfig": case "openconfig":
newSBI = &OpenConfig{} newSBI = GetOpenconfigInstance()
newSBI.SetDefaults()
} }
return newSBI return newSBI
} }
package nucleus package nucleus
import ( import (
"sync"
"code.fbi.h-da.de/cocsn/yang-models/generated/arista" "code.fbi.h-da.de/cocsn/yang-models/generated/arista"
"code.fbi.h-da.de/cocsn/yang-models/generated/openconfig" "code.fbi.h-da.de/cocsn/yang-models/generated/openconfig"
log "github.com/golang/glog" log "github.com/golang/glog"
...@@ -9,13 +11,16 @@ import ( ...@@ -9,13 +11,16 @@ import (
"github.com/openconfig/ygot/ytypes" "github.com/openconfig/ygot/ytypes"
) )
var lock = &sync.Mutex{}
var singleOpenConfig *OpenConfig
var singleArista *AristaOC
// SouthboundInterface provides an // SouthboundInterface provides an
// interface for SBI implementations // interface for SBI implementations
type SouthboundInterface interface { type SouthboundInterface interface {
// Deprecated // Deprecated
SbiIdentifier() string SbiIdentifier() string
SetDefaults()
SetNode() func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error SetNode() func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
Schema() *ytypes.Schema Schema() *ytypes.Schema
SetTransport(t Transport) SetTransport(t Transport)
...@@ -31,10 +36,6 @@ type OpenConfig struct { ...@@ -31,10 +36,6 @@ type OpenConfig struct {
schema *ytypes.Schema schema *ytypes.Schema
} }
func (oc *OpenConfig) SetDefaults() {
oc.Name = "openconfig"
}
func (oc *OpenConfig) SbiIdentifier() string { func (oc *OpenConfig) SbiIdentifier() string {
return oc.Name return oc.Name
} }
...@@ -64,18 +65,27 @@ func (oc *OpenConfig) SetTransport(t Transport) { ...@@ -64,18 +65,27 @@ func (oc *OpenConfig) SetTransport(t Transport) {
oc.Transport = t oc.Transport = t
} }
func GetOpenconfigInstance() SouthboundInterface {
if singleOpenConfig == nil {
lock.Lock()
defer lock.Unlock()
if singleOpenConfig == nil {
log.Info("creating OpenConfig instance")
singleOpenConfig = &OpenConfig{}
singleOpenConfig.Name = "openconfig"
t := &Gnmi{SetNode: singleOpenConfig.SetNode()}
singleOpenConfig.Transport = t
}
}
return singleOpenConfig
}
type AristaOC struct { type AristaOC struct {
Name string `json:"name"` Name string `json:"name"`
Transport Transport `json:"-"` Transport Transport `json:"-"`
schema *ytypes.Schema schema *ytypes.Schema
} }
func (oc *AristaOC) SetDefaults() {
oc.Name = "arista"
t := &Gnmi{SetNode: oc.SetNode()}
oc.Transport = t
}
func (oc *AristaOC) SbiIdentifier() string { func (oc *AristaOC) SbiIdentifier() string {
return oc.Name return oc.Name
} }
...@@ -104,3 +114,18 @@ func (oc *AristaOC) GetTransport() Transport { ...@@ -104,3 +114,18 @@ func (oc *AristaOC) GetTransport() Transport {
func (oc *AristaOC) SetTransport(t Transport) { func (oc *AristaOC) SetTransport(t Transport) {
oc.Transport = t oc.Transport = t
} }
func GetAristaOCInstance() SouthboundInterface {
if singleArista == nil {
lock.Lock()
defer lock.Unlock()
if singleArista == nil {
log.Info("creating AristaOC instance")
singleArista = &AristaOC{}
singleArista.Name = "arista"
t := &Gnmi{SetNode: singleArista.SetNode()}
singleArista.Transport = t
}
}
return singleArista
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment