diff --git a/nucleus/device.go b/nucleus/device.go index dc5fdaaa9066a21e80cb1314668de90c6fdd0495..e91807b49e1726c8df5cd069e66443c696f8e3ec 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 1760b057f3e9aa02194a214a7cdad6484d088b65..ffe549a239e002720b87cd2b92773996c793ac44 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) }