diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go index 84fe3f70fa10e8ea087b82f11a35205300b9d995..8a02188159b6bcc5372e45b2d84d87dc1153fb88 100644 --- a/nucleus/cli-handling.go +++ b/nucleus/cli-handling.go @@ -8,7 +8,6 @@ package nucleus import ( "context" - "encoding/json" "errors" "io" "net" @@ -261,9 +260,8 @@ func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetReq 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 { + //check if the device exists + if !pnd.ContainsDevice(uuidDevice) { err := errors.New("Couldnt find device: UUID is wrong") log.Info(err) return &pb.DeviceGetReply{Message: err.Error()}, err @@ -276,11 +274,11 @@ func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetReq return &pb.DeviceGetReply{Message: err.Error()}, err } - d, err := json.MarshalIndent(device, "", "\t") + d, err := pnd.MarshalDevice(uuidDevice) if err != nil { log.Info(err) return &pb.DeviceGetReply{Message: err.Error()}, err } - return &pb.DeviceGetReply{Message: string(string(d))}, nil + return &pb.DeviceGetReply{Message: d}, nil } diff --git a/nucleus/device.go b/nucleus/device.go index 427fd049bba6b43d05ca9f7e9e03962f44f5da12..dcad6b388de25a0e8be66dd852a2bdd1edc00b70 100644 --- a/nucleus/device.go +++ b/nucleus/device.go @@ -10,13 +10,13 @@ type Device struct { ygot.GoStruct // SBI is the device's southbound interface implementation - SBI SouthboundInterface `json:"-"` + SBI SouthboundInterface // Config is the device's config. Under revision - Config DeviceConfig `json:"-"` + Config DeviceConfig // Transport is the device's Transport implementation - Transport Transport `json:"-"` + Transport Transport } //NewDevice creates a Device diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index ea2e519838a335d9f39c8c78666a3e5f087eb999..7ea7f83b828164e37d14235bc2adb7818616fb3d 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -2,6 +2,8 @@ package nucleus import ( "context" + + "encoding/json" "github.com/google/uuid" ) @@ -12,12 +14,13 @@ type PrincipalNetworkDomain interface { AddSbi(SouthboundInterface) error RemoveSbi(string) error AddDevice(*Device) error - RemoveDevice(uuid uuid.UUID) error + RemoveDevice(uuid.UUID) error Request(uuid.UUID, string) error RequestAll(string) error GetName() string GetDescription() string - GetDevice(uuid.UUID) (*Device, bool) + MarshalDevice(uuid.UUID) (string, error) + ContainsDevice(uuid.UUID) bool GetSBIs() map[string]SouthboundInterface } @@ -46,9 +49,10 @@ 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) +//HasDevice checks if the given device uuid is registered for this PND +func (pnd *pndImplementation) ContainsDevice(uuid uuid.UUID) bool { + _, exists := pnd.devices[uuid] + return exists } //GetDescription returns the current description of the PND @@ -120,6 +124,16 @@ func (pnd *pndImplementation) getDevice(uuid uuid.UUID) (*Device, bool) { return device, exists } +func (pnd *pndImplementation) MarshalDevice(uuid uuid.UUID) (string, error) { + d := pnd.devices[uuid] + json, err := json.MarshalIndent(d.GoStruct, "", "\t") + if err != nil { + return "", err + } + + return string(json), nil +} + //Request sends a request for a specific device func (pnd *pndImplementation) Request(uuid uuid.UUID, path string) error { d := pnd.devices[uuid]