From ff928b38b5bdd1fbd3dc07957bfd58294cba0b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Sterba?= <andre.sterba@stud.h-da.de> Date: Mon, 10 May 2021 13:12:27 +0200 Subject: [PATCH] WIP --- nucleus/device.go | 12 ++++++++++++ nucleus/principalNetworkDomain.go | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/nucleus/device.go b/nucleus/device.go index dc5fdaaa9..e91807b49 100644 --- a/nucleus/device.go +++ b/nucleus/device.go @@ -6,6 +6,18 @@ import ( "github.com/openconfig/ygot/ygot" ) +type DeviceIdentifier interface { + IsDeviceIdentifier() +} + +type StringIdentifier string + +func (si StringIdentifier) IsDeviceIdentifier() {} + +type UUIDIdentifier uuid.UUID + +func (ui UUIDIdentifier) IsDeviceIdentifier() {} + // Device represents an Orchestrated Network Device (OND) which is managed by // nucleus type Device struct { diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index 1760b057f..ffe549a23 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -223,6 +223,20 @@ func (pnd *pndImplementation) addDevice(device *Device) error { return nil } +func (pnd *pndImplementation) getDevice(identifier DeviceIdentifier) (*Device, error) { + stringIdentifier, ok := identifier.(StringIdentifier) + if ok { + return pnd.getDeviceByName(string(stringIdentifier)) + } + + uuidIdentifier, ok := identifier.(UUIDIdentifier) + if ok { + return pnd.getDeviceByUUID(uuid.UUID(uuidIdentifier)) + } + + return nil, &ErrNotFound{id: identifier} +} + func (pnd *pndImplementation) getDeviceByUUID(id uuid.UUID) (*Device, error) { return pnd.devices.get(id) } -- GitLab