Scheduled maintenance on Saturday, 27 September 2025, from 07:00 AM to 4:00 PM GMT (09:00 AM to 6:00 PM CEST) - some services may be unavailable -

Skip to content
Snippets Groups Projects
Select Git revision
  • 60b2387f2c1d4a29c0daa4b5e632cc5ca94817a3
  • master default
  • feat/320-cttc-ietf-simap-basic-support-with-kafka-yang-push
  • cnit_tapi
  • feat/292-cttc-implement-integration-test-for-ryu-openflow
  • feat/314-tid-new-service-for-ipowdm-configuration-fron-orchestrator-to-ipowdm-controller
  • feat/327-tid-new-service-to-ipowdm-controller-to-manage-transceivers-configuration-on-external-agent
  • cnit-p2mp-premerge
  • feat/325-tid-nbi-e2e-to-manage-e2e-path-computation
  • feat/307-update-python-version-service
  • feat/326-tid-external-management-of-devices-telemetry-nbi
  • openroadm-flex-grid
  • feat/310-cttc-implement-nbi-connector-to-interface-with-osm-client
  • develop protected
  • feat/324-tid-nbi-ietf_l3vpn-deploy-fail
  • feat/321-add-support-for-gnmi-configuration-via-proto
  • feat/322-add-read-support-for-ipinfusion-devices-via-netconf
  • feat/323-add-support-for-restconf-protocol-in-devices
  • feat/policy-refactor
  • feat/192-cttc-implement-telemetry-backend-collector-gnmi-openconfig
  • feat/307-update-python-version
  • feat/telemetry-collector-int
  • v5.0.0 protected
  • v4.0.0 protected
  • demo-dpiab-eucnc2024
  • v3.0.0 protected
  • v2.1.0 protected
  • v2.0.0 protected
  • v1.0.0 protected
29 results

Device.py

Blame
  • Lluis Gifre's avatar
    Lluis Gifre Renom authored
    - definition of context API
    - implementation of inmemory and Redis backend engines
    - implementation of unit tests for both engines
    60b2387f
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Device.py 3.45 KiB
    from __future__ import annotations
    from typing import TYPE_CHECKING, Dict
    from ..entity._Entity import _Entity
    from ..entity.EntityAttributes import EntityAttributes
    from ..entity.EntityCollection import EntityCollection
    from .Endpoint import Endpoint
    from .Keys import KEY_DEVICE, KEY_DEVICE_ENDPOINTS
    from .OperationalStatus import OperationalStatus, to_operationalstatus_enum
    
    if TYPE_CHECKING:
        from .Context import Context
        from .Topology import Topology
    
    VALIDATORS = {
        'device_type': lambda v: v is None or isinstance(v, str),
        'device_config': lambda v: v is None or isinstance(v, str),
        'device_operational_status': lambda v: v is None or isinstance(v, OperationalStatus),
    }
    
    TRANSCODERS = {
        'device_operational_status': {
            OperationalStatus: lambda v: v.value,
            str              : lambda v: to_operationalstatus_enum(v),
        }
    }
    
    class Device(_Entity):
        def __init__(self, device_uuid : str, parent : 'Topology'):
            super().__init__(parent=parent)
            self._device_uuid = device_uuid
            self._topology_uuid = self._parent.topology_uuid
            self._context_uuid = self._parent.context_uuid
            self._attributes = EntityAttributes(self, KEY_DEVICE, VALIDATORS, transcoders=TRANSCODERS)
            self._endpoints = EntityCollection(self, KEY_DEVICE_ENDPOINTS)
    
        @property
        def parent(self) -> 'Topology': return self._parent
    
        @property
        def context(self) -> 'Context': return self._parent.context
    
        @property
        def context_uuid(self) -> str: return self.context.context_uuid
    
        @property
        def topology_uuid(self) -> str: return self.parent.topology_uuid
    
        @property
        def device_uuid(self) -> str: return self._device_uuid
    
        @property
        def attributes(self) -> EntityAttributes: return self._attributes
    
        @property
        def endpoints(self) -> EntityCollection: return self._endpoints
    
        def endpoint(self, endpoint_uuid : str) -> Endpoint: return Endpoint(endpoint_uuid, self)
    
        def create(self, type : str, config : str, operational_status : OperationalStatus) -> 'Device':
            self.update(update_attributes={
                'device_type': type,
                'device_config': config,
                'device_operational_status': operational_status,
            })
            self.parent.devices.add(self.device_uuid)
            return self
    
        def update(self, update_attributes={}, remove_attributes=[]) -> 'Device':
            self.attributes.update(update_attributes=update_attributes, remove_attributes=remove_attributes)
            return self
    
        def delete(self) -> None:
            for endpoint_uuid in self.endpoints.get(): self.endpoint(endpoint_uuid).delete()
            remove_attributes = ['device_type', 'device_config', 'device_operational_status']
            self.update(remove_attributes=remove_attributes)
            self.parent.devices.delete(self.device_uuid)
    
        def dump(self) -> Dict:
            attributes = self.attributes.get()
            dev_op_status = attributes.get('device_operational_status', None)
            if isinstance(dev_op_status, OperationalStatus): dev_op_status = dev_op_status.value
            endpoints = [self.endpoint(endpoint_uuid).dump() for endpoint_uuid in self.endpoints.get()]
            return {
                'device_id': {'device_id': {'uuid': self.device_uuid}},
                'device_type': attributes.get('device_type', None),
                'device_config': {'device_config': attributes.get('device_config', None)},
                'devOperationalStatus': dev_op_status,
                'endpointList': endpoints
            }