Loading proto/context.proto +89 −48 Original line number Original line Diff line number Diff line Loading @@ -2,35 +2,40 @@ syntax = "proto3"; package context; package context; service ContextService { service ContextService { rpc GetContextIds (Empty ) returns (ContextIdList ) {} rpc ListContextIds (Empty ) returns ( ContextIdList ) {} rpc GetContexts (Empty ) returns (ContextList ) {} rpc ListContexts (Empty ) returns ( ContextList ) {} rpc GetContext (ContextId ) returns ( Context ) {} rpc GetContext (ContextId ) returns ( Context ) {} rpc SetContext (Context ) returns ( ContextId ) {} rpc SetContext (Context ) returns ( ContextId ) {} rpc DeleteContext (ContextId ) returns (Empty ) {} rpc RemoveContext (ContextId ) returns ( Empty ) {} rpc GetContextEvents (Empty ) returns (stream ContextEvent ) {} rpc GetTopologyIds(ContextId ) returns (TopologyIdList) {} rpc ListTopologyIds (ContextId ) returns ( TopologyIdList) {} rpc GetTopologies (ContextId ) returns (TopologyList ) {} rpc ListTopologies (ContextId ) returns ( TopologyList ) {} rpc GetTopology (TopologyId) returns ( Topology ) {} rpc GetTopology (TopologyId) returns ( Topology ) {} rpc SetTopology (Topology ) returns ( TopologyId ) {} rpc SetTopology (Topology ) returns ( TopologyId ) {} rpc DeleteTopology(TopologyId) returns (Empty ) {} rpc RemoveTopology (TopologyId) returns ( Empty ) {} rpc GetTopologyEvents(Empty ) returns (stream TopologyEvent ) {} rpc GetDeviceIds (Empty ) returns (DeviceIdList ) {} rpc ListDeviceIds (Empty ) returns ( DeviceIdList ) {} rpc GetDevices (Empty ) returns (DeviceList ) {} rpc ListDevices (Empty ) returns ( DeviceList ) {} rpc GetDevice (DeviceId ) returns ( Device ) {} rpc GetDevice (DeviceId ) returns ( Device ) {} rpc SetDevice (Device ) returns ( DeviceId ) {} rpc SetDevice (Device ) returns ( DeviceId ) {} rpc RemoveDevice (DeviceId ) returns ( Empty ) {} rpc RemoveDevice (DeviceId ) returns ( Empty ) {} rpc GetDeviceEvents (Empty ) returns (stream DeviceEvent ) {} rpc GetLinkIds (Empty ) returns (LinkIdList ) {} rpc ListLinkIds (Empty ) returns ( LinkIdList ) {} rpc GetLinks (Empty ) returns (LinkList ) {} rpc ListLinks (Empty ) returns ( LinkList ) {} rpc GetLink (LinkId ) returns ( Link ) {} rpc GetLink (LinkId ) returns ( Link ) {} rpc SetLink (Link ) returns ( LinkId ) {} rpc SetLink (Link ) returns ( LinkId ) {} rpc DeleteLink (LinkId ) returns (Empty ) {} rpc RemoveLink (LinkId ) returns ( Empty ) {} rpc GetLinkEvents (Empty ) returns (stream LinkEvent ) {} rpc GetServiceIds (ContextId ) returns (ServiceIdList ) {} rpc ListServiceIds (ContextId ) returns ( ServiceIdList ) {} rpc GetServices (ContextId ) returns (ServiceList ) {} rpc ListServices (ContextId ) returns ( ServiceList ) {} rpc GetService (ServiceId ) returns ( Service ) {} rpc GetService (ServiceId ) returns ( Service ) {} rpc SetService (Service ) returns ( ServiceId ) {} rpc SetService (Service ) returns ( ServiceId ) {} rpc DeleteService (ServiceId ) returns (Empty ) {} rpc RemoveService (ServiceId ) returns ( Empty ) {} rpc GetServiceEvents (Empty ) returns (stream ServiceEvent ) {} } } // ----- Generic ------------------------------------------------------------------------------------------------------- // ----- Generic ------------------------------------------------------------------------------------------------------- Loading @@ -40,6 +45,17 @@ message Uuid { string uuid = 1; string uuid = 1; } } enum EventTypeEnum { EVENTTYPE_UNDEFINED = 0; EVENTTYPE_CREATE = 1; EVENTTYPE_UPDATE = 2; EVENTTYPE_REMOVE = 3; } message Event { double timestamp = 1; EventTypeEnum event_type = 2; } // ----- Context ------------------------------------------------------------------------------------------------------- // ----- Context ------------------------------------------------------------------------------------------------------- message ContextId { message ContextId { Loading @@ -60,6 +76,11 @@ message ContextList { repeated Context contexts = 1; repeated Context contexts = 1; } } message ContextEvent { Event event = 1; ContextId context_id = 2; } // ----- Topology ------------------------------------------------------------------------------------------------------ // ----- Topology ------------------------------------------------------------------------------------------------------ message TopologyId { message TopologyId { Loading @@ -69,8 +90,8 @@ message TopologyId { message Topology { message Topology { TopologyId topology_id = 1; TopologyId topology_id = 1; repeated Device devices = 2; repeated DeviceId device_ids = 2; repeated Link links = 3; repeated LinkId link_ids = 3; } } message TopologyIdList { message TopologyIdList { Loading @@ -81,6 +102,11 @@ message TopologyList { repeated Topology topologies = 1; repeated Topology topologies = 1; } } message TopologyEvent { Event event = 1; TopologyId topology_id = 2; } // ----- Device -------------------------------------------------------------------------------------------------------- // ----- Device -------------------------------------------------------------------------------------------------------- message DeviceId { message DeviceId { Loading @@ -92,7 +118,7 @@ message Device { string device_type = 2; string device_type = 2; DeviceConfig device_config = 3; DeviceConfig device_config = 3; DeviceOperationalStatus devive_operational_status = 4; DeviceOperationalStatus devive_operational_status = 4; repeated DeviceDriver device_drivers = 5; repeated DeviceDriverEnum device_drivers = 5; repeated EndPoint endpoints = 6; repeated EndPoint endpoints = 6; } } Loading @@ -100,19 +126,19 @@ message DeviceConfig { repeated ConfigRule config_rules = 1; repeated ConfigRule config_rules = 1; } } enum DeviceDriver { enum DeviceDriverEnum { DRIVER_UNDEFINED = 0; // also used for emulated DEVICEDRIVER_UNDEFINED = 0; // also used for emulated DRIVER_OPENCONFIG = 1; DEVICEDRIVER_OPENCONFIG = 1; DRIVER_TRANSPORT_API = 2; DEVICEDRIVER_TRANSPORT_API = 2; DRIVER_P4 = 3; DEVICEDRIVER_P4 = 3; DRIVER_IETF_NETWORK_TOPOLOGY = 4; DEVICEDRIVER_IETF_NETWORK_TOPOLOGY = 4; DRIVER_ONF_TR_352 = 5; DEVICEDRIVER_ONF_TR_352 = 5; } } enum DeviceOperationalStatus { enum DeviceOperationalStatus { KEEP_STATUS = 0; // Do not change operational status of device (used in configure) UNDEFINED = 0; DISABLED = -1; DISABLED = 1; ENABLED = 1; ENABLED = 2; } } message DeviceIdList { message DeviceIdList { Loading @@ -123,6 +149,11 @@ message DeviceList { repeated Device devices = 1; repeated Device devices = 1; } } message DeviceEvent { Event event = 1; DeviceId device_id = 2; } // ----- Link ---------------------------------------------------------------------------------------------------------- // ----- Link ---------------------------------------------------------------------------------------------------------- message LinkId { message LinkId { Loading @@ -131,7 +162,7 @@ message LinkId { message Link { message Link { LinkId link_id = 1; LinkId link_id = 1; repeated EndPointId endpoints = 2; repeated EndPointId endpoint_ids = 2; } } message LinkIdList { message LinkIdList { Loading @@ -142,6 +173,11 @@ message LinkList { repeated Link links = 1; repeated Link links = 1; } } message LinkEvent { Event event = 1; LinkId link_id = 2; } // ----- Service ------------------------------------------------------------------------------------------------------- // ----- Service ------------------------------------------------------------------------------------------------------- message ServiceId { message ServiceId { Loading @@ -151,14 +187,14 @@ message ServiceId { message Service { message Service { ServiceId service_id = 1; ServiceId service_id = 1; ServiceType service_type = 2; ServiceTypeEnum service_type = 2; repeated EndPointId endpoints = 3; repeated EndPointId endpoint_ids = 3; repeated Constraint constraints = 4; repeated Constraint constraints = 4; ServiceState service_state = 5; ServiceState service_state = 5; ServiceConfig service_config = 6; ServiceConfig service_config = 6; } } enum ServiceType { enum ServiceTypeEnum { SERVICETYPE_UNKNOWN = 0; SERVICETYPE_UNKNOWN = 0; SERVICETYPE_L3NM = 1; SERVICETYPE_L3NM = 1; SERVICETYPE_L2NM = 2; SERVICETYPE_L2NM = 2; Loading Loading @@ -187,6 +223,11 @@ message ServiceList { repeated Service services = 1; repeated Service services = 1; } } message ServiceEvent { Event event = 1; ServiceId service_id = 2; } // ----- Endpoint ------------------------------------------------------------------------------------------------------ // ----- Endpoint ------------------------------------------------------------------------------------------------------ message EndPointId { message EndPointId { Loading @@ -202,14 +243,14 @@ message EndPoint { // ----- Configuration ------------------------------------------------------------------------------------------------- // ----- Configuration ------------------------------------------------------------------------------------------------- enum ConfigAction { enum ConfigActionEnum { CONFIGACTION_UNDEFINED = 0; CONFIGACTION_UNDEFINED = 0; CONFIGACTION_SET = 1; CONFIGACTION_SET = 1; CONFIGACTION_DELETE = 2; CONFIGACTION_DELETE = 2; } } message ConfigRule { message ConfigRule { ConfigAction action = 1; ConfigActionEnum action = 1; string resource_key = 2; string resource_key = 2; string resource_value = 3; string resource_value = 3; } } Loading src/context/service/database/_engine/Exceptions.py→src/common/orm/Exceptions.py +0 −0 File moved. View file src/context/service/database/_engine/Factory.py→src/common/orm/Factory.py +0 −0 File moved. View file src/context/service/database/_engine/_Database.py→src/common/orm/_Database.py +8 −4 Original line number Original line Diff line number Diff line import logging import logging from typing import List, Set from typing import List, Set from .backend._Backend import _Backend from .backend._Backend import _Backend from .object._Object import _Object from .fields.PrimaryKeyField import PrimaryKeyField from .model.Model import Model from .Exceptions import MutexException from .Exceptions import MutexException LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__) class _Database(_Object): class _Database(Model): def __init__(self, backend : _Backend): def __init__(self, backend : _Backend): if not issubclass(backend, _Backend): if not isinstance(backend, _Backend): str_class_path = '{}.{}'.format(_Backend.__module__, _Backend.__name__) str_class_path = '{}.{}'.format(_Backend.__module__, _Backend.__name__) raise AttributeError('backend must inherit from {}'.format(str_class_path)) raise AttributeError('backend must inherit from {}'.format(str_class_path)) self._backend = backend self._backend = backend super().__init__(self, 'root') super().__init__(self) self._acquired = False self._acquired = False self._owner_key = None self._owner_key = None Loading @@ -22,6 +23,9 @@ class _Database(_Object): @property @property def backend(self) -> _Backend: return self._backend def backend(self) -> _Backend: return self._backend @property def backend_key(self) -> str: return '' def __enter__(self) -> '_Database': def __enter__(self) -> '_Database': self._acquired, self._owner_key = self._backend.lock() self._acquired, self._owner_key = self._backend.lock() if not self._acquired: raise MutexException('Unable to acquire database lock') if not self._acquired: raise MutexException('Unable to acquire database lock') Loading src/common/tests/__init__.py→src/common/orm/__init__.py +0 −0 File moved. Loading
proto/context.proto +89 −48 Original line number Original line Diff line number Diff line Loading @@ -2,35 +2,40 @@ syntax = "proto3"; package context; package context; service ContextService { service ContextService { rpc GetContextIds (Empty ) returns (ContextIdList ) {} rpc ListContextIds (Empty ) returns ( ContextIdList ) {} rpc GetContexts (Empty ) returns (ContextList ) {} rpc ListContexts (Empty ) returns ( ContextList ) {} rpc GetContext (ContextId ) returns ( Context ) {} rpc GetContext (ContextId ) returns ( Context ) {} rpc SetContext (Context ) returns ( ContextId ) {} rpc SetContext (Context ) returns ( ContextId ) {} rpc DeleteContext (ContextId ) returns (Empty ) {} rpc RemoveContext (ContextId ) returns ( Empty ) {} rpc GetContextEvents (Empty ) returns (stream ContextEvent ) {} rpc GetTopologyIds(ContextId ) returns (TopologyIdList) {} rpc ListTopologyIds (ContextId ) returns ( TopologyIdList) {} rpc GetTopologies (ContextId ) returns (TopologyList ) {} rpc ListTopologies (ContextId ) returns ( TopologyList ) {} rpc GetTopology (TopologyId) returns ( Topology ) {} rpc GetTopology (TopologyId) returns ( Topology ) {} rpc SetTopology (Topology ) returns ( TopologyId ) {} rpc SetTopology (Topology ) returns ( TopologyId ) {} rpc DeleteTopology(TopologyId) returns (Empty ) {} rpc RemoveTopology (TopologyId) returns ( Empty ) {} rpc GetTopologyEvents(Empty ) returns (stream TopologyEvent ) {} rpc GetDeviceIds (Empty ) returns (DeviceIdList ) {} rpc ListDeviceIds (Empty ) returns ( DeviceIdList ) {} rpc GetDevices (Empty ) returns (DeviceList ) {} rpc ListDevices (Empty ) returns ( DeviceList ) {} rpc GetDevice (DeviceId ) returns ( Device ) {} rpc GetDevice (DeviceId ) returns ( Device ) {} rpc SetDevice (Device ) returns ( DeviceId ) {} rpc SetDevice (Device ) returns ( DeviceId ) {} rpc RemoveDevice (DeviceId ) returns ( Empty ) {} rpc RemoveDevice (DeviceId ) returns ( Empty ) {} rpc GetDeviceEvents (Empty ) returns (stream DeviceEvent ) {} rpc GetLinkIds (Empty ) returns (LinkIdList ) {} rpc ListLinkIds (Empty ) returns ( LinkIdList ) {} rpc GetLinks (Empty ) returns (LinkList ) {} rpc ListLinks (Empty ) returns ( LinkList ) {} rpc GetLink (LinkId ) returns ( Link ) {} rpc GetLink (LinkId ) returns ( Link ) {} rpc SetLink (Link ) returns ( LinkId ) {} rpc SetLink (Link ) returns ( LinkId ) {} rpc DeleteLink (LinkId ) returns (Empty ) {} rpc RemoveLink (LinkId ) returns ( Empty ) {} rpc GetLinkEvents (Empty ) returns (stream LinkEvent ) {} rpc GetServiceIds (ContextId ) returns (ServiceIdList ) {} rpc ListServiceIds (ContextId ) returns ( ServiceIdList ) {} rpc GetServices (ContextId ) returns (ServiceList ) {} rpc ListServices (ContextId ) returns ( ServiceList ) {} rpc GetService (ServiceId ) returns ( Service ) {} rpc GetService (ServiceId ) returns ( Service ) {} rpc SetService (Service ) returns ( ServiceId ) {} rpc SetService (Service ) returns ( ServiceId ) {} rpc DeleteService (ServiceId ) returns (Empty ) {} rpc RemoveService (ServiceId ) returns ( Empty ) {} rpc GetServiceEvents (Empty ) returns (stream ServiceEvent ) {} } } // ----- Generic ------------------------------------------------------------------------------------------------------- // ----- Generic ------------------------------------------------------------------------------------------------------- Loading @@ -40,6 +45,17 @@ message Uuid { string uuid = 1; string uuid = 1; } } enum EventTypeEnum { EVENTTYPE_UNDEFINED = 0; EVENTTYPE_CREATE = 1; EVENTTYPE_UPDATE = 2; EVENTTYPE_REMOVE = 3; } message Event { double timestamp = 1; EventTypeEnum event_type = 2; } // ----- Context ------------------------------------------------------------------------------------------------------- // ----- Context ------------------------------------------------------------------------------------------------------- message ContextId { message ContextId { Loading @@ -60,6 +76,11 @@ message ContextList { repeated Context contexts = 1; repeated Context contexts = 1; } } message ContextEvent { Event event = 1; ContextId context_id = 2; } // ----- Topology ------------------------------------------------------------------------------------------------------ // ----- Topology ------------------------------------------------------------------------------------------------------ message TopologyId { message TopologyId { Loading @@ -69,8 +90,8 @@ message TopologyId { message Topology { message Topology { TopologyId topology_id = 1; TopologyId topology_id = 1; repeated Device devices = 2; repeated DeviceId device_ids = 2; repeated Link links = 3; repeated LinkId link_ids = 3; } } message TopologyIdList { message TopologyIdList { Loading @@ -81,6 +102,11 @@ message TopologyList { repeated Topology topologies = 1; repeated Topology topologies = 1; } } message TopologyEvent { Event event = 1; TopologyId topology_id = 2; } // ----- Device -------------------------------------------------------------------------------------------------------- // ----- Device -------------------------------------------------------------------------------------------------------- message DeviceId { message DeviceId { Loading @@ -92,7 +118,7 @@ message Device { string device_type = 2; string device_type = 2; DeviceConfig device_config = 3; DeviceConfig device_config = 3; DeviceOperationalStatus devive_operational_status = 4; DeviceOperationalStatus devive_operational_status = 4; repeated DeviceDriver device_drivers = 5; repeated DeviceDriverEnum device_drivers = 5; repeated EndPoint endpoints = 6; repeated EndPoint endpoints = 6; } } Loading @@ -100,19 +126,19 @@ message DeviceConfig { repeated ConfigRule config_rules = 1; repeated ConfigRule config_rules = 1; } } enum DeviceDriver { enum DeviceDriverEnum { DRIVER_UNDEFINED = 0; // also used for emulated DEVICEDRIVER_UNDEFINED = 0; // also used for emulated DRIVER_OPENCONFIG = 1; DEVICEDRIVER_OPENCONFIG = 1; DRIVER_TRANSPORT_API = 2; DEVICEDRIVER_TRANSPORT_API = 2; DRIVER_P4 = 3; DEVICEDRIVER_P4 = 3; DRIVER_IETF_NETWORK_TOPOLOGY = 4; DEVICEDRIVER_IETF_NETWORK_TOPOLOGY = 4; DRIVER_ONF_TR_352 = 5; DEVICEDRIVER_ONF_TR_352 = 5; } } enum DeviceOperationalStatus { enum DeviceOperationalStatus { KEEP_STATUS = 0; // Do not change operational status of device (used in configure) UNDEFINED = 0; DISABLED = -1; DISABLED = 1; ENABLED = 1; ENABLED = 2; } } message DeviceIdList { message DeviceIdList { Loading @@ -123,6 +149,11 @@ message DeviceList { repeated Device devices = 1; repeated Device devices = 1; } } message DeviceEvent { Event event = 1; DeviceId device_id = 2; } // ----- Link ---------------------------------------------------------------------------------------------------------- // ----- Link ---------------------------------------------------------------------------------------------------------- message LinkId { message LinkId { Loading @@ -131,7 +162,7 @@ message LinkId { message Link { message Link { LinkId link_id = 1; LinkId link_id = 1; repeated EndPointId endpoints = 2; repeated EndPointId endpoint_ids = 2; } } message LinkIdList { message LinkIdList { Loading @@ -142,6 +173,11 @@ message LinkList { repeated Link links = 1; repeated Link links = 1; } } message LinkEvent { Event event = 1; LinkId link_id = 2; } // ----- Service ------------------------------------------------------------------------------------------------------- // ----- Service ------------------------------------------------------------------------------------------------------- message ServiceId { message ServiceId { Loading @@ -151,14 +187,14 @@ message ServiceId { message Service { message Service { ServiceId service_id = 1; ServiceId service_id = 1; ServiceType service_type = 2; ServiceTypeEnum service_type = 2; repeated EndPointId endpoints = 3; repeated EndPointId endpoint_ids = 3; repeated Constraint constraints = 4; repeated Constraint constraints = 4; ServiceState service_state = 5; ServiceState service_state = 5; ServiceConfig service_config = 6; ServiceConfig service_config = 6; } } enum ServiceType { enum ServiceTypeEnum { SERVICETYPE_UNKNOWN = 0; SERVICETYPE_UNKNOWN = 0; SERVICETYPE_L3NM = 1; SERVICETYPE_L3NM = 1; SERVICETYPE_L2NM = 2; SERVICETYPE_L2NM = 2; Loading Loading @@ -187,6 +223,11 @@ message ServiceList { repeated Service services = 1; repeated Service services = 1; } } message ServiceEvent { Event event = 1; ServiceId service_id = 2; } // ----- Endpoint ------------------------------------------------------------------------------------------------------ // ----- Endpoint ------------------------------------------------------------------------------------------------------ message EndPointId { message EndPointId { Loading @@ -202,14 +243,14 @@ message EndPoint { // ----- Configuration ------------------------------------------------------------------------------------------------- // ----- Configuration ------------------------------------------------------------------------------------------------- enum ConfigAction { enum ConfigActionEnum { CONFIGACTION_UNDEFINED = 0; CONFIGACTION_UNDEFINED = 0; CONFIGACTION_SET = 1; CONFIGACTION_SET = 1; CONFIGACTION_DELETE = 2; CONFIGACTION_DELETE = 2; } } message ConfigRule { message ConfigRule { ConfigAction action = 1; ConfigActionEnum action = 1; string resource_key = 2; string resource_key = 2; string resource_value = 3; string resource_value = 3; } } Loading
src/context/service/database/_engine/Exceptions.py→src/common/orm/Exceptions.py +0 −0 File moved. View file
src/context/service/database/_engine/Factory.py→src/common/orm/Factory.py +0 −0 File moved. View file
src/context/service/database/_engine/_Database.py→src/common/orm/_Database.py +8 −4 Original line number Original line Diff line number Diff line import logging import logging from typing import List, Set from typing import List, Set from .backend._Backend import _Backend from .backend._Backend import _Backend from .object._Object import _Object from .fields.PrimaryKeyField import PrimaryKeyField from .model.Model import Model from .Exceptions import MutexException from .Exceptions import MutexException LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__) class _Database(_Object): class _Database(Model): def __init__(self, backend : _Backend): def __init__(self, backend : _Backend): if not issubclass(backend, _Backend): if not isinstance(backend, _Backend): str_class_path = '{}.{}'.format(_Backend.__module__, _Backend.__name__) str_class_path = '{}.{}'.format(_Backend.__module__, _Backend.__name__) raise AttributeError('backend must inherit from {}'.format(str_class_path)) raise AttributeError('backend must inherit from {}'.format(str_class_path)) self._backend = backend self._backend = backend super().__init__(self, 'root') super().__init__(self) self._acquired = False self._acquired = False self._owner_key = None self._owner_key = None Loading @@ -22,6 +23,9 @@ class _Database(_Object): @property @property def backend(self) -> _Backend: return self._backend def backend(self) -> _Backend: return self._backend @property def backend_key(self) -> str: return '' def __enter__(self) -> '_Database': def __enter__(self) -> '_Database': self._acquired, self._owner_key = self._backend.lock() self._acquired, self._owner_key = self._backend.lock() if not self._acquired: raise MutexException('Unable to acquire database lock') if not self._acquired: raise MutexException('Unable to acquire database lock') Loading