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
...@@ -158,6 +158,8 @@ func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIR ...@@ -158,6 +158,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
} }
//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) { func (s *server) CreatePND(ctx context.Context, in *pb.CreatePNDRequest) (*pb.CreatePNDReply, error) {
log.Info("Received: Create a PND with the name", in.GetName()) log.Info("Received: Create a PND with the name", in.GetName())
sbi := s.core.southboundInterfaces[in.GetSbi()] sbi := s.core.southboundInterfaces[in.GetSbi()]
...@@ -167,6 +169,8 @@ func (s *server) CreatePND(ctx context.Context, in *pb.CreatePNDRequest) (*pb.Cr ...@@ -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 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) { func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDsReply, error) {
log.Info("Received: Get all PNDs") log.Info("Received: Get all PNDs")
var pnds []*pb.PND var pnds []*pb.PND
...@@ -192,14 +196,17 @@ func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDs ...@@ -192,14 +196,17 @@ func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDs
return &pb.AllPNDsReply{Pnds: pnds}, nil 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) { 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 { for _, s := range s.core.southboundInterfaces {
sbiNames = append(sbiNames, s.SbiIdentifier()) sbiNames = append(sbiNames, s.SbiIdentifier())
} }
return &pb.AllSBINamesReply{SbiNames: sbiNames}, nil 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) { func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.AddDeviceReply, error) {
log.Info("Received: AddDevice") log.Info("Received: AddDevice")
uuidPND, err := uuid.Parse(in.UuidPND) uuidPND, err := uuid.Parse(in.UuidPND)
...@@ -208,6 +215,7 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad ...@@ -208,6 +215,7 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad
} }
pnd, exists := s.core.principalNetworkDomains[uuidPND] pnd, exists := s.core.principalNetworkDomains[uuidPND]
if exists != true { if exists != true {
log.Info(err)
return &pb.AddDeviceReply{Message: err.Error()}, err return &pb.AddDeviceReply{Message: err.Error()}, err
} }
sbi := s.core.principalNetworkDomains[uuidPND].GetSBIs()["default"] sbi := s.core.principalNetworkDomains[uuidPND].GetSBIs()["default"]
...@@ -224,39 +232,53 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad ...@@ -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, newDevice := NewDevice(sbi, in.Device.Address, in.Device.Username,
in.Device.Password, transport) 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 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) { func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetRequest) (*pb.DeviceGetReply, error) {
log.Info("Received: HandleDeviceGetRequest") log.Info("Received: HandleDeviceGetRequest")
uuidPND, err := uuid.Parse(in.GetUuidPND()) uuidPND, err := uuid.Parse(in.GetUuidPND())
if err != nil { if err != nil {
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err return &pb.DeviceGetReply{Message: err.Error()}, err
} }
uuidDevice, err := uuid.Parse(in.GetUuidDevice()) uuidDevice, err := uuid.Parse(in.GetUuidDevice())
if err != nil { if err != nil {
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err return &pb.DeviceGetReply{Message: err.Error()}, err
} }
pnd, exists := s.core.principalNetworkDomains[uuidPND] pnd, exists := s.core.principalNetworkDomains[uuidPND]
if exists != true { if exists != true {
err := errors.New("Couldnt find PND: UUID is wrong") err := errors.New("Couldnt find PND: UUID is wrong")
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, 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) device, exists := s.core.principalNetworkDomains[uuidPND].GetDevice(uuidDevice)
if exists != true { if exists != true {
err := errors.New("Couldnt find device: UUID is wrong") err := errors.New("Couldnt find device: UUID is wrong")
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err return &pb.DeviceGetReply{Message: err.Error()}, err
} }
//GET request for the provided path
err = pnd.Request(uuidDevice, in.GetPath()) err = pnd.Request(uuidDevice, in.GetPath())
if err != nil { if err != nil {
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err return &pb.DeviceGetReply{Message: err.Error()}, err
} }
d, err := json.MarshalIndent(device, "", "\t") d, err := json.MarshalIndent(device, "", "\t")
if err != nil { if err != nil {
log.Info(err)
return &pb.DeviceGetReply{Message: err.Error()}, err return &pb.DeviceGetReply{Message: err.Error()}, err
} }
......
...@@ -43,7 +43,7 @@ func (c *Core) AttachDatabase() { ...@@ -43,7 +43,7 @@ func (c *Core) AttachDatabase() {
c.database = database.NewDatabaseClient() c.database = database.NewDatabaseClient()
} }
// CreateSouthboundInterfaces initializes the controller with his SBIs // CreateSouthboundInterfaces initializes the controller with his supported SBIs
func (c *Core) CreateSouthboundInterfaces() { func (c *Core) CreateSouthboundInterfaces() {
arista := &AristaOC{} arista := &AristaOC{}
c.southboundInterfaces[arista.SbiIdentifier()] = arista c.southboundInterfaces[arista.SbiIdentifier()] = arista
......
...@@ -19,6 +19,7 @@ type Device struct { ...@@ -19,6 +19,7 @@ type Device struct {
Transport Transport `json:"-"` Transport Transport `json:"-"`
} }
//NewDevice creates a Device
func NewDevice(sbi SouthboundInterface, addr, username, password string, func NewDevice(sbi SouthboundInterface, addr, username, password string,
transport Transport) *Device { transport Transport) *Device {
return &Device{ return &Device{
......
...@@ -41,18 +41,22 @@ func NewPND(name, description string, sbi SouthboundInterface) PrincipalNetworkD ...@@ -41,18 +41,22 @@ func NewPND(name, description string, sbi SouthboundInterface) PrincipalNetworkD
} }
} }
//GetName returns the name of the PND
func (pnd *pndImplementation) GetName() string { func (pnd *pndImplementation) GetName() string {
return pnd.name return pnd.name
} }
//GetDevice returns a specific device via the given uuid
func (pnd *pndImplementation) GetDevice(uuid uuid.UUID) (*Device, bool) { func (pnd *pndImplementation) GetDevice(uuid uuid.UUID) (*Device, bool) {
return pnd.getDevice(uuid) return pnd.getDevice(uuid)
} }
//GetDescription returns the current description of the PND
func (pnd *pndImplementation) GetDescription() string { func (pnd *pndImplementation) GetDescription() string {
return pnd.description return pnd.description
} }
//GetSBIs returns the registered SBIs
func (pnd *pndImplementation) GetSBIs() map[string]SouthboundInterface { func (pnd *pndImplementation) GetSBIs() map[string]SouthboundInterface {
return pnd.sbi return pnd.sbi
} }
...@@ -62,18 +66,25 @@ func (pnd *pndImplementation) Destroy() error { ...@@ -62,18 +66,25 @@ func (pnd *pndImplementation) Destroy() error {
return destroy() return destroy()
} }
//AddSbi adds a SBI to the PND which will be supported
func (pnd *pndImplementation) AddSbi(sbi SouthboundInterface) error { func (pnd *pndImplementation) AddSbi(sbi SouthboundInterface) error {
return pnd.addSbi(sbi) 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 { func (pnd *pndImplementation) RemoveSbi(sbiIdentifier string) error {
return pnd.removeSbi(sbiIdentifier) return pnd.removeSbi(sbiIdentifier)
} }
//AddDevice adds a new device to the PND
func (pnd *pndImplementation) AddDevice(device *Device) error { func (pnd *pndImplementation) AddDevice(device *Device) error {
return pnd.addDevice(device) return pnd.addDevice(device)
} }
//RemoveDevice removes a device from the PND
func (pnd *pndImplementation) RemoveDevice(uuid uuid.UUID) error { func (pnd *pndImplementation) RemoveDevice(uuid uuid.UUID) error {
return pnd.removeDevice(uuid) return pnd.removeDevice(uuid)
} }
...@@ -109,6 +120,7 @@ func (pnd *pndImplementation) getDevice(uuid uuid.UUID) (*Device, bool) { ...@@ -109,6 +120,7 @@ func (pnd *pndImplementation) getDevice(uuid uuid.UUID) (*Device, bool) {
return device, exists return device, exists
} }
//Request sends a request for a specific device
func (pnd *pndImplementation) Request(uuid uuid.UUID, path string) error { func (pnd *pndImplementation) Request(uuid uuid.UUID, path string) error {
d := pnd.devices[uuid] d := pnd.devices[uuid]
ctx := context.Background() ctx := context.Background()
...@@ -123,6 +135,7 @@ func (pnd *pndImplementation) Request(uuid uuid.UUID, path string) error { ...@@ -123,6 +135,7 @@ func (pnd *pndImplementation) Request(uuid uuid.UUID, path string) error {
return nil return nil
} }
//RequestAll sends a request for all registered devices
func (pnd *pndImplementation) RequestAll(path string) error { func (pnd *pndImplementation) RequestAll(path string) error {
for k := range pnd.devices { for k := range pnd.devices {
if err := pnd.Request(k, path); err != nil { 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