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

added NewDevice() for Device

parent a1b198fd
No related branches found
No related tags found
3 merge requests!97Resolve "PND handling via CLI and database",!91"Overhaul Architecture",!90Develop
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment