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

comments

parent 842e0219
No related branches found
No related tags found
3 merge requests!97Resolve "PND handling via CLI and database",!91"Overhaul Architecture",!90Develop
Pipeline #63919 passed with warnings
This commit is part of merge request !91. Comments created here will be created in the context of that merge request.
......@@ -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
}
......
......@@ -43,7 +43,7 @@ func (c *Core) AttachDatabase() {
c.database = database.NewDatabaseClient()
}
// CreateSouthboundInterfaces initializes the controller with his SBIs
// CreateSouthboundInterfaces initializes the controller with his supported SBIs
func (c *Core) CreateSouthboundInterfaces() {
arista := &AristaOC{}
c.southboundInterfaces[arista.SbiIdentifier()] = arista
......
......@@ -19,6 +19,7 @@ type Device struct {
Transport Transport `json:"-"`
}
//NewDevice creates a Device
func NewDevice(sbi SouthboundInterface, addr, username, password string,
transport Transport) *Device {
return &Device{
......
......@@ -41,18 +41,22 @@ func NewPND(name, description string, sbi SouthboundInterface) PrincipalNetworkD
}
}
//GetName returns the name of the PND
func (pnd *pndImplementation) GetName() string {
return pnd.name
}
//GetDevice returns a specific device via the given uuid
func (pnd *pndImplementation) GetDevice(uuid uuid.UUID) (*Device, bool) {
return pnd.getDevice(uuid)
}
//GetDescription returns the current description of the PND
func (pnd *pndImplementation) GetDescription() string {
return pnd.description
}
//GetSBIs returns the registered SBIs
func (pnd *pndImplementation) GetSBIs() map[string]SouthboundInterface {
return pnd.sbi
}
......@@ -62,18 +66,25 @@ func (pnd *pndImplementation) Destroy() error {
return destroy()
}
//AddSbi adds a SBI to the PND which will be supported
func (pnd *pndImplementation) AddSbi(sbi SouthboundInterface) error {
return pnd.addSbi(sbi)
}
//AddSbi removes a SBI from the PND
//TODO: this should to recursivly through
//devices and remove the devices using
//this SBI
func (pnd *pndImplementation) RemoveSbi(sbiIdentifier string) error {
return pnd.removeSbi(sbiIdentifier)
}
//AddDevice adds a new device to the PND
func (pnd *pndImplementation) AddDevice(device *Device) error {
return pnd.addDevice(device)
}
//RemoveDevice removes a device from the PND
func (pnd *pndImplementation) RemoveDevice(uuid uuid.UUID) error {
return pnd.removeDevice(uuid)
}
......@@ -109,6 +120,7 @@ func (pnd *pndImplementation) getDevice(uuid uuid.UUID) (*Device, bool) {
return device, exists
}
//Request sends a request for a specific device
func (pnd *pndImplementation) Request(uuid uuid.UUID, path string) error {
d := pnd.devices[uuid]
ctx := context.Background()
......@@ -123,6 +135,7 @@ func (pnd *pndImplementation) Request(uuid uuid.UUID, path string) error {
return nil
}
//RequestAll sends a request for all registered devices
func (pnd *pndImplementation) RequestAll(path string) error {
for k := range pnd.devices {
if err := pnd.Request(k, path); err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment