diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go index 2998d38c52f624c86b5519e442bbde3844850eb7..08dd6799519d4714944f18c85f6938fd7185cf67 100644 --- a/nucleus/cli-handling.go +++ b/nucleus/cli-handling.go @@ -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 } diff --git a/nucleus/controller.go b/nucleus/controller.go index ec9a7df1465ecc12ac2f0b94271673e49d3f2b20..b04a8fb4e6f92cd989779ffe576c2105df1d8531 100644 --- a/nucleus/controller.go +++ b/nucleus/controller.go @@ -1,7 +1,9 @@ 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 } } diff --git a/nucleus/device.go b/nucleus/device.go index b575ef3dfffeda91fd4dc3e377a42edb9ffaf66f..868fd68ba3df90bbd4d9221534692d7d637e2bf7 100644 --- a/nucleus/device.go +++ b/nucleus/device.go @@ -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 diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index 7d2d412d7cae0379f91ada523a5a631f75c93d0a..54199758af1669d84d936f03e173ba6f00b0cb65 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -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 diff --git a/nucleus/southbound.go b/nucleus/southbound.go index e30dd247390f6b45ea8b581320305bbba4179939..dfe83a07b504de0f6e55005fa0f66e8d906eb2d9 100644 --- a/nucleus/southbound.go +++ b/nucleus/southbound.go @@ -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 {