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

removed GetDevices instead ContainsDevice is added

ContainsDevice() is enough to check if the given device uuid is present
in the current pnds device map.
For the cli device printing a JSONMarshal function was added.
parent f86fac1f
No related branches found
No related tags found
3 merge requests!97Resolve "PND handling via CLI and database",!91"Overhaul Architecture",!90Develop
Pipeline #63950 passed with warnings
This commit is part of merge request !91. Comments created here will be created in the context of that merge request.
......@@ -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
}
......@@ -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
......
......@@ -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]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment