Skip to content
Snippets Groups Projects

"Overhaul Architecture"

Merged Ghost User requested to merge 67-overhaul-architecture into develop
4 files
+ 39
3
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 24
2
@@ -158,6 +158,8 @@ func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIR
return &pb.TAPIReply{Message: "Done"}, nil
}
//CreatePND creates a new PND and adds it to the principalNetworkDomain map of
//the core
func (s *server) CreatePND(ctx context.Context, in *pb.CreatePNDRequest) (*pb.CreatePNDReply, error) {
log.Info("Received: Create a PND with the name", in.GetName())
sbi := s.core.southboundInterfaces[in.GetSbi()]
@@ -167,6 +169,8 @@ func (s *server) CreatePND(ctx context.Context, in *pb.CreatePNDRequest) (*pb.Cr
return &pb.CreatePNDReply{Message: "Created new PND: " + id.String()}, nil
}
//GetAllPNDs is a request to get all current registered PNDs and returns a slim
//variant of PNDs and their respective devices
func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDsReply, error) {
log.Info("Received: Get all PNDs")
var pnds []*pb.PND
@@ -192,14 +196,17 @@ func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDs
return &pb.AllPNDsReply{Pnds: pnds}, nil
}
//GetAllSBINames returns all registered SBIs from core.
func (s *server) GetAllSBINames(ctx context.Context, in *emptypb.Empty) (*pb.AllSBINamesReply, error) {
sbiNames := make([]string, len(s.core.southboundInterfaces))
var sbiNames []string
for _, s := range s.core.southboundInterfaces {
sbiNames = append(sbiNames, s.SbiIdentifier())
}
return &pb.AllSBINamesReply{SbiNames: sbiNames}, nil
}
//AddDevice adds a new Device to a specific PND
//currently this is only working with gnmi transports
func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.AddDeviceReply, error) {
log.Info("Received: AddDevice")
uuidPND, err := uuid.Parse(in.UuidPND)
@@ -208,6 +215,7 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad
}
pnd, exists := s.core.principalNetworkDomains[uuidPND]
if exists != true {
log.Info(err)
return &pb.AddDeviceReply{Message: err.Error()}, err
}
sbi := s.core.principalNetworkDomains[uuidPND].GetSBIs()["default"]
@@ -224,39 +232,53 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad
newDevice := NewDevice(sbi, in.Device.Address, in.Device.Username,
in.Device.Password, transport)
pnd.AddDevice(newDevice)
err = pnd.AddDevice(newDevice)
if err != nil {
log.Info(err)
return &pb.AddDeviceReply{Message: err.Error()}, err
}
return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Config.Uuid.String()}, err
}
//HandleDeviceGetRequest handles a GET request via pnd.Request()
func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetRequest) (*pb.DeviceGetReply, error) {
log.Info("Received: HandleDeviceGetRequest")
uuidPND, err := uuid.Parse(in.GetUuidPND())
if err != nil {
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err
}
uuidDevice, err := uuid.Parse(in.GetUuidDevice())
if err != nil {
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err
}
pnd, exists := s.core.principalNetworkDomains[uuidPND]
if exists != true {
err := errors.New("Couldnt find PND: UUID is wrong")
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err
}
//the specific device a request will be sent to
device, exists := s.core.principalNetworkDomains[uuidPND].GetDevice(uuidDevice)
if exists != true {
err := errors.New("Couldnt find device: UUID is wrong")
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err
}
//GET request for the provided path
err = pnd.Request(uuidDevice, in.GetPath())
if err != nil {
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err
}
d, err := json.MarshalIndent(device, "", "\t")
if err != nil {
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err
}
Loading