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

it is possible to backup pnds into a json file

parent cfe4a3b2
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.
......@@ -166,6 +166,7 @@ func (s *server) CreatePND(ctx context.Context, in *pb.CreatePNDRequest) (*pb.Cr
id := uuid.New()
s.core.principalNetworkDomains[id] = NewPND(in.GetName(), in.GetDescription(), sbi)
//TODO: export
s.core.MarshallPNDs()
return &pb.CreatePNDReply{Message: "Created new PND: " + id.String()}, nil
}
......@@ -226,6 +227,7 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad
devicesMap := pnd.GetDevices()
devicesMap[newDevice.Uuid] = newDevice
//TODO: export
s.core.MarshallPNDs()
return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Uuid.String()}, err
}
......
package nucleus
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"code.fbi.h-da.de/cocsn/gosdn/database"
......@@ -43,12 +45,23 @@ func (c *Core) AttachDatabase() {
c.database = database.NewDatabaseClient()
}
func (c *Core) MarshallPNDs() error {
b, err := json.MarshalIndent(c.principalNetworkDomains, "", "\t")
if err != nil {
return err
}
err = ioutil.WriteFile("./backup.json", b, 0644)
if err != nil {
return err
}
return nil
}
// CreateSouthboundInterfaces initializes the controller with his SBIs
func (c *Core) CreateSouthboundInterfaces() {
if len(c.southboundInterfaces) == 0 {
sbi := &AristaOC{}
t := &Gnmi{SetNode: sbi.SetNode()}
sbi.SetTransport(t)
sbi.SetDefaults()
c.southboundInterfaces[sbi.SbiIdentifier()] = sbi
}
}
......
......@@ -6,11 +6,11 @@ import (
)
type Device struct {
Uuid uuid.UUID
Device ygot.GoStruct
SBI SouthboundInterface
Config DeviceConfig
Transport Transport
Uuid uuid.UUID `json:"id"`
Device ygot.GoStruct `json:"device"`
SBI SouthboundInterface `json:"sbi"`
Config DeviceConfig `json:"config"`
Transport Transport `json:"-"`
}
// Add adds a property to a device. Please
......
......@@ -19,10 +19,10 @@ type PrincipalNetworkDomain interface {
}
type pndImplementation struct {
Name string
Description string
Sbi map[string]SouthboundInterface
Devices map[uuid.UUID]Device
Name string `json:"name"`
Description string `json:"description"`
Sbi map[string]SouthboundInterface `json:"sbis"`
Devices map[uuid.UUID]Device `json:"devices"`
}
//NewPND creates a Principle Network Domain
......
......@@ -15,6 +15,7 @@ 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)
......@@ -25,12 +26,17 @@ type Tapi struct {
}
type OpenConfig struct {
Transport Transport
Name string `json:"name"`
Transport Transport `json:"-"`
schema *ytypes.Schema
}
func (oc *OpenConfig) SetDefaults() {
oc.Name = "openconfig"
}
func (oc *OpenConfig) SbiIdentifier() string {
return "openconfig"
return oc.Name
}
func (oc *OpenConfig) Schema() *ytypes.Schema {
......@@ -59,12 +65,19 @@ func (oc *OpenConfig) SetTransport(t Transport) {
}
type AristaOC struct {
Transport Transport
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 "arista"
return oc.Name
}
func (oc *AristaOC) Schema() *ytypes.Schema {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment