diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go index 10e4842c075e0439bfd18b9549ca3065d2e4678c..84fe3f70fa10e8ea087b82f11a35205300b9d995 100644 --- a/nucleus/cli-handling.go +++ b/nucleus/cli-handling.go @@ -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 } diff --git a/nucleus/controller.go b/nucleus/controller.go index bb0cc0bb00072711f1a906baf5a140e6b0107e16..a02b55424f458f6977a0b93849d8741b1056e384 100644 --- a/nucleus/controller.go +++ b/nucleus/controller.go @@ -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 diff --git a/nucleus/device.go b/nucleus/device.go index d33e62b79b5bdbe4f91bf56c832c518f5e8dd1d2..427fd049bba6b43d05ca9f7e9e03962f44f5da12 100644 --- a/nucleus/device.go +++ b/nucleus/device.go @@ -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{ diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index 6a6eaf5acda654183a1021934bcca2cec5760304..ea2e519838a335d9f39c8c78666a3e5f087eb999 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -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 {