diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go index a1172fdbc2353e5ae48edea5a5649dceadf1b5f7..10e4842c075e0439bfd18b9549ca3065d2e4678c 100644 --- a/nucleus/cli-handling.go +++ b/nucleus/cli-handling.go @@ -222,19 +222,9 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad } transport.SetConfig(cfg) - newDevice := Device{ - SBI: sbi, - Config: DeviceConfig{ - Uuid: uuid.New(), - Address: in.Device.Address, - Username: in.Device.Username, - Password: in.Device.Password, - }, - Transport: transport, - } - newDevice.GoStruct = sbi.Schema().Root - devicesMap := pnd.GetDevices() - devicesMap[newDevice.Config.Uuid] = &newDevice + newDevice := NewDevice(sbi, in.Device.Address, in.Device.Username, + in.Device.Password, transport) + pnd.AddDevice(newDevice) return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Config.Uuid.String()}, err } @@ -254,7 +244,7 @@ func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetReq err := errors.New("Couldnt find PND: UUID is wrong") return &pb.DeviceGetReply{Message: err.Error()}, err } - device, exists := s.core.principalNetworkDomains[uuidPND].GetDevices()[uuidDevice] + device, exists := s.core.principalNetworkDomains[uuidPND].GetDevice(uuidDevice) if exists != true { err := errors.New("Couldnt find device: UUID is wrong") return &pb.DeviceGetReply{Message: err.Error()}, err diff --git a/nucleus/device.go b/nucleus/device.go index 86ea4a08b204b1d13579a082754e28d937d4a700..d33e62b79b5bdbe4f91bf56c832c518f5e8dd1d2 100644 --- a/nucleus/device.go +++ b/nucleus/device.go @@ -19,6 +19,21 @@ type Device struct { Transport Transport `json:"-"` } +func NewDevice(sbi SouthboundInterface, addr, username, password string, + transport Transport) *Device { + return &Device{ + GoStruct: sbi.Schema().Root, + SBI: sbi, + Config: DeviceConfig{ + Uuid: uuid.New(), + Address: addr, + Username: username, + Password: password, + }, + Transport: transport, + } +} + type DeviceConfig struct { Uuid uuid.UUID Address string