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
Branches
Tags
3 merge requests!97Resolve "PND handling via CLI and database",!91"Overhaul Architecture",!90Develop
This commit is part of merge request !91. Comments created here will be created in the context of that merge request.
......@@ -79,9 +79,10 @@ func (c *Core) UnMarshallPNDs() error {
// CreateSouthboundInterfaces initializes the controller with his SBIs
func (c *Core) CreateSouthboundInterfaces() {
if len(c.southboundInterfaces) == 0 {
sbi := &AristaOC{}
sbi.SetDefaults()
c.southboundInterfaces[sbi.SbiIdentifier()] = sbi
arista := GetAristaOCInstance()
c.southboundInterfaces[arista.SbiIdentifier()] = arista
openconfig := GetOpenconfigInstance()
c.southboundInterfaces[openconfig.SbiIdentifier()] = openconfig
}
}
......
......@@ -42,7 +42,6 @@ func (d *Device) UnmarshalJSON(b []byte) error {
},
Transport: nil,
}
device.SBI.SetDefaults()
device.Transport = device.SBI.GetTransport()
device.Device = device.SBI.Schema().Root
......
......@@ -48,12 +48,10 @@ func getSouthboundInterfaceFromJSONMap(m map[string]interface{}) SouthboundInter
switch sbi := m["name"]; sbi {
case "arista":
newSBI = &AristaOC{}
newSBI.SetDefaults()
newSBI = GetAristaOCInstance()
case "openconfig":
newSBI = &OpenConfig{}
newSBI.SetDefaults()
newSBI = GetOpenconfigInstance()
}
return newSBI
}
package nucleus
import (
"sync"
"code.fbi.h-da.de/cocsn/yang-models/generated/arista"
"code.fbi.h-da.de/cocsn/yang-models/generated/openconfig"
log "github.com/golang/glog"
......@@ -9,13 +11,16 @@ import (
"github.com/openconfig/ygot/ytypes"
)
var lock = &sync.Mutex{}
var singleOpenConfig *OpenConfig
var singleArista *AristaOC
// SouthboundInterface provides an
// interface for SBI implementations
type SouthboundInterface interface {
// Deprecated
SbiIdentifier() string
SetDefaults()
SetNode() func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
Schema() *ytypes.Schema
SetTransport(t Transport)
......@@ -31,10 +36,6 @@ type OpenConfig struct {
schema *ytypes.Schema
}
func (oc *OpenConfig) SetDefaults() {
oc.Name = "openconfig"
}
func (oc *OpenConfig) SbiIdentifier() string {
return oc.Name
}
......@@ -64,18 +65,27 @@ func (oc *OpenConfig) SetTransport(t Transport) {
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 {
Name string `json:"name"`
Transport Transport `json:"-"`
schema *ytypes.Schema
}
func (oc *AristaOC) SetDefaults() {
oc.Name = "arista"
t := &Gnmi{SetNode: oc.SetNode()}
oc.Transport = t
}
func (oc *AristaOC) SbiIdentifier() string {
return oc.Name
}
......@@ -104,3 +114,18 @@ func (oc *AristaOC) GetTransport() Transport {
func (oc *AristaOC) SetTransport(t Transport) {
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