diff --git a/cmd/gnmi/gnmi.go b/cmd/gnmi/gnmi.go index 6b07f0de01d6138f50b79dae9f2687a4ebf8d40b..55c4507e77bdf601201702168438de17e60142ea 100644 --- a/cmd/gnmi/gnmi.go +++ b/cmd/gnmi/gnmi.go @@ -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) } diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go index e18c610d58d02d854330ff40df12426735312344..282a12b05ae489305e412b879f837c8df04854fe 100644 --- a/nucleus/cli-handling.go +++ b/nucleus/cli-handling.go @@ -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 } diff --git a/nucleus/device.go b/nucleus/device.go index c56690e2e6d9bce949cbaab26584b7c9da34fa6c..65976f7e6cc1c8377814ff9d2a21be61a0b6bca3 100644 --- a/nucleus/device.go +++ b/nucleus/device.go @@ -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 diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index 85bdff01b87db80b0fe4b636ece5cdb0d5decea5..1223465136be59f5119516b054a1560228d29d28 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -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 }