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 (
func main() {
sbi := &nucleus.OpenConfig{}
device := nucleus.Device{
Uuid: uuid.New(),
Device: &openconfig.Device{},
SBI: sbi,
Config: nucleus.DeviceConfig{
Uuid: uuid.New(),
Address: "141.100.70.170:6030",
Username: "admin",
Password: "arista",
},
}
pnd := nucleus.NewPND("openconfig", sbi)
pnd := nucleus.NewPND("openconfig", "test description", sbi)
if err := pnd.AddDevice(device); err != nil {
log.Fatal(err)
}
......
......@@ -153,8 +153,8 @@ func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIR
return &pb.TAPIReply{Message: "Done"}, nil
}
func (s *server) CreatePND(ctx context.Context, in *pb.PNDRequest) (*pb.PNDReply, error) {
log.Info("Received: ", in.GetName())
func (s *server) CreatePND(ctx context.Context, in *pb.CreatePNDRequest) (*pb.CreatePNDReply, error) {
log.Info("Received: Create a PND with the name", in.GetName())
path := viper.GetString("pnd.path")
sbi := &OpenConfig{}
id := uuid.New()
......@@ -162,5 +162,47 @@ func (s *server) CreatePND(ctx context.Context, in *pb.PNDRequest) (*pb.PNDReply
if err := s.core.savePNDs(path); err != nil {
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 (
)
type Device struct {
Uuid uuid.UUID
Device ygot.GoStruct
SBI SouthboundInterface
Config DeviceConfig
......@@ -53,7 +54,6 @@ func (d Device) Add(resp interface{}) error {
}
type DeviceConfig struct {
Uuid uuid.UUID
Address string
Username string
Password string
......
......@@ -8,6 +8,8 @@ import (
// interface for PND implementations
type PrincipalNetworkDomain interface {
GetName() string
GetDescription() string
GetDefaultSBIName() string
Destroy() error
AddSbi(SouthboundInterface) error
RemoveSbi(string) error
......@@ -39,6 +41,14 @@ func (pnd *pndImplementation) GetName() string {
return pnd.Name
}
func (pnd *pndImplementation) GetDescription() string {
return pnd.Description
}
func (pnd *pndImplementation) GetDefaultSBIName() string {
return pnd.Sbi["default"].SbiIdentifier()
}
// Interface satisfaction
func (pnd *pndImplementation) Destroy() error {
return destroy()
......@@ -77,7 +87,7 @@ func (pnd *pndImplementation) removeSbi(sbiIdentifier string) error {
}
func (pnd *pndImplementation) addDevice(device Device) error {
pnd.Devices[device.Config.Uuid] = device
pnd.Devices[device.Uuid] = device
return nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment