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

changes to support sending and saving devices

parent c1242e9f
No related branches found
No related tags found
3 merge requests!97Resolve "PND handling via CLI and database",!91"Overhaul Architecture",!90Develop
...@@ -13,16 +13,16 @@ import ( ...@@ -13,16 +13,16 @@ import (
func main() { func main() {
sbi := &nucleus.OpenConfig{} sbi := &nucleus.OpenConfig{}
device := nucleus.Device{ device := nucleus.Device{
Uuid: uuid.New(),
Device: &openconfig.Device{}, Device: &openconfig.Device{},
SBI: sbi, SBI: sbi,
Config: nucleus.DeviceConfig{ Config: nucleus.DeviceConfig{
Uuid: uuid.New(),
Address: "141.100.70.170:6030", Address: "141.100.70.170:6030",
Username: "admin", Username: "admin",
Password: "arista", Password: "arista",
}, },
} }
pnd := nucleus.NewPND("openconfig", sbi) pnd := nucleus.NewPND("openconfig", "test description", sbi)
if err := pnd.AddDevice(device); err != nil { if err := pnd.AddDevice(device); err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
...@@ -153,8 +153,8 @@ func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIR ...@@ -153,8 +153,8 @@ func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIR
return &pb.TAPIReply{Message: "Done"}, nil return &pb.TAPIReply{Message: "Done"}, nil
} }
func (s *server) CreatePND(ctx context.Context, in *pb.PNDRequest) (*pb.PNDReply, error) { func (s *server) CreatePND(ctx context.Context, in *pb.CreatePNDRequest) (*pb.CreatePNDReply, error) {
log.Info("Received: ", in.GetName()) log.Info("Received: Create a PND with the name", in.GetName())
path := viper.GetString("pnd.path") path := viper.GetString("pnd.path")
sbi := &OpenConfig{} sbi := &OpenConfig{}
id := uuid.New() id := uuid.New()
...@@ -162,5 +162,47 @@ func (s *server) CreatePND(ctx context.Context, in *pb.PNDRequest) (*pb.PNDReply ...@@ -162,5 +162,47 @@ func (s *server) CreatePND(ctx context.Context, in *pb.PNDRequest) (*pb.PNDReply
if err := s.core.savePNDs(path); err != nil { if err := s.core.savePNDs(path); err != nil {
log.Info(err) log.Info(err)
} }
return &pb.PNDReply{Message: "Created new PND: " + id.String()}, nil return &pb.CreatePNDReply{Message: "Created new PND: " + id.String()}, nil
}
func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDsReply, error) {
var pnds []*pb.PND
for uuidPND, pnd := range s.core.principalNetworkDomains {
var devices []*pb.Device
for uuidDevice, device := range pnd.(*pndImplementation).Devices {
tmpDevice := pb.Device{
Uuid: uuidDevice.String(),
Address: device.Config.Address,
Username: device.Config.Username,
Password: device.Config.Password}
devices = append(devices, &tmpDevice)
}
tmpPND := pb.PND{
Uuid: uuidPND.String(),
Name: pnd.GetName(),
Description: pnd.GetDescription(),
Sbi: pnd.GetDefaultSBIName(),
Devices: devices}
pnds = append(pnds, &tmpPND)
}
return &pb.AllPNDsReply{Pnds: pnds}, nil
}
func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.AddDeviceReply, error) {
uuidPND, err := uuid.Parse(in.UuidPND)
pnd := s.core.principalNetworkDomains[uuidPND]
newDevice := Device{
Uuid: uuid.New(),
Device: nil,
SBI: nil,
Config: DeviceConfig{
Address: in.Device.Address,
Username: in.Device.Username,
Password: in.Device.Password,
},
}
devicesMap := pnd.(*pndImplementation).Devices
devicesMap[newDevice.Uuid] = newDevice
return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Uuid.String()}, err
} }
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
) )
type Device struct { type Device struct {
Uuid uuid.UUID
Device ygot.GoStruct Device ygot.GoStruct
SBI SouthboundInterface SBI SouthboundInterface
Config DeviceConfig Config DeviceConfig
...@@ -53,7 +54,6 @@ func (d Device) Add(resp interface{}) error { ...@@ -53,7 +54,6 @@ func (d Device) Add(resp interface{}) error {
} }
type DeviceConfig struct { type DeviceConfig struct {
Uuid uuid.UUID
Address string Address string
Username string Username string
Password string Password string
......
...@@ -8,6 +8,8 @@ import ( ...@@ -8,6 +8,8 @@ import (
// interface for PND implementations // interface for PND implementations
type PrincipalNetworkDomain interface { type PrincipalNetworkDomain interface {
GetName() string GetName() string
GetDescription() string
GetDefaultSBIName() string
Destroy() error Destroy() error
AddSbi(SouthboundInterface) error AddSbi(SouthboundInterface) error
RemoveSbi(string) error RemoveSbi(string) error
...@@ -39,6 +41,14 @@ func (pnd *pndImplementation) GetName() string { ...@@ -39,6 +41,14 @@ func (pnd *pndImplementation) GetName() string {
return pnd.Name return pnd.Name
} }
func (pnd *pndImplementation) GetDescription() string {
return pnd.Description
}
func (pnd *pndImplementation) GetDefaultSBIName() string {
return pnd.Sbi["default"].SbiIdentifier()
}
// Interface satisfaction // Interface satisfaction
func (pnd *pndImplementation) Destroy() error { func (pnd *pndImplementation) Destroy() error {
return destroy() return destroy()
...@@ -77,7 +87,7 @@ func (pnd *pndImplementation) removeSbi(sbiIdentifier string) error { ...@@ -77,7 +87,7 @@ func (pnd *pndImplementation) removeSbi(sbiIdentifier string) error {
} }
func (pnd *pndImplementation) addDevice(device Device) error { func (pnd *pndImplementation) addDevice(device Device) error {
pnd.Devices[device.Config.Uuid] = device pnd.Devices[device.Uuid] = device
return nil return nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment