Loading src/context/service/database/models/DeviceModel.py +5 −7 Original line number Original line Diff line number Diff line Loading @@ -38,8 +38,6 @@ class DeviceModel(_Base): endpoints = relationship('EndPointModel', passive_deletes=True) # lazy='joined', back_populates='device' endpoints = relationship('EndPointModel', passive_deletes=True) # lazy='joined', back_populates='device' components = relationship('ComponentModel', passive_deletes=True) # lazy='joined', back_populates='device' components = relationship('ComponentModel', passive_deletes=True) # lazy='joined', back_populates='device' controller = relationship('DeviceModel', remote_side=[device_uuid], passive_deletes=True) # lazy='joined', back_populates='device' controller = relationship('DeviceModel', remote_side=[device_uuid], passive_deletes=True) # lazy='joined', back_populates='device' # ------------------- Experimental ----------------------------------- optical_config = relationship('OpticalConfigModel', passive_deletes=True) optical_config = relationship('OpticalConfigModel', passive_deletes=True) def dump_id(self) -> Dict: def dump_id(self) -> Dict: Loading src/context/service/database/models/Slot.py +16 −42 Original line number Original line Diff line number Diff line Loading @@ -12,34 +12,20 @@ # See the License for the specific language governing permissions and # See the License for the specific language governing permissions and # limitations under the License. # limitations under the License. from sqlalchemy.types import TypeDecorator, Integer from common.tools.object_factory.OpticalLink import order_dict import logging from sqlalchemy.types import PickleType , TypeDecorator ,Integer class SlotType(TypeDecorator): class SlotType(TypeDecorator): impl = Integer impl = Integer def process_bind_param(self, value, dialect): def process_bind_param(self, value, dialect): if value is not None: if value is not None: value =order_dict(value) bin_num = "0b" bin_num = "0b" for i,(key,val) in enumerate(value.items()): for i,(key,val) in enumerate(value.items()): bin_num =bin_num + f"{val}" bin_num =bin_num + f"{val}" int_num = int(bin_num,2) int_num = int(bin_num,2) return int_num return int_num def process_result_value(self, value, dialect): def process_result_value(self, value, dialect): if value is not None: if value is not None: slot = dict() slot = dict() bin_num = bin(value) bin_num = bin(value) Loading @@ -48,14 +34,10 @@ class SlotType(TypeDecorator): slot[str(i+1)]=int(sliced_num[i]) slot[str(i+1)]=int(sliced_num[i]) return slot return slot class C_Slot(SlotType): class C_Slot(SlotType): start_point = 0 start_point = 0 def process_result_value(self, value, dialect): def process_result_value(self, value, dialect): if value is not None: if value is not None: slot = dict() slot = dict() bin_num = bin(value) bin_num = bin(value) Loading @@ -63,20 +45,14 @@ class C_Slot (SlotType): if (len(sliced_num) != 20) : if (len(sliced_num) != 20) : for i in range(0,20 - len(sliced_num)): for i in range(0,20 - len(sliced_num)): sliced_num = '0' + sliced_num sliced_num = '0' + sliced_num for i in range(len(sliced_num)): for i in range(len(sliced_num)): slot[str(self.start_point+i+1)]=int(sliced_num[i]) slot[str(self.start_point+i+1)]=int(sliced_num[i]) return slot return slot class L_Slot (SlotType): class L_Slot (SlotType): start_point = 100 start_point = 100 def process_result_value(self, value, dialect): def process_result_value(self, value, dialect): if value is not None: if value is not None: slot = dict() slot = dict() bin_num = bin(value) bin_num = bin(value) Loading @@ -91,9 +67,7 @@ class L_Slot (SlotType): class S_Slot (SlotType): class S_Slot (SlotType): start_point = 500 start_point = 500 def process_result_value(self, value, dialect): def process_result_value(self, value, dialect): if value is not None: if value is not None: slot= dict() slot= dict() bin_num = bin(value) bin_num = bin(value) Loading src/context/service/database/models/TopologyModel.py +18 −21 Original line number Original line Diff line number Diff line Loading @@ -30,8 +30,6 @@ class TopologyModel(_Base): context = relationship('ContextModel', back_populates='topologies', lazy='selectin') context = relationship('ContextModel', back_populates='topologies', lazy='selectin') topology_devices = relationship('TopologyDeviceModel') # back_populates='topology' topology_devices = relationship('TopologyDeviceModel') # back_populates='topology' topology_links = relationship('TopologyLinkModel' ) # back_populates='topology' topology_links = relationship('TopologyLinkModel' ) # back_populates='topology' #-------------------------- Experimental --------------------------- topology_optical_links = relationship("TopologyOpticalLinkModel") topology_optical_links = relationship("TopologyOpticalLinkModel") def dump_id(self) -> Dict: def dump_id(self) -> Dict: Loading @@ -47,7 +45,6 @@ class TopologyModel(_Base): 'device_ids' : [{'device_uuid': {'uuid': td.device_uuid }} for td in self.topology_devices ], 'device_ids' : [{'device_uuid': {'uuid': td.device_uuid }} for td in self.topology_devices ], 'link_ids' : [{'link_uuid' : {'uuid': tl.link_uuid }} for tl in self.topology_links ], 'link_ids' : [{'link_uuid' : {'uuid': tl.link_uuid }} for tl in self.topology_links ], 'optical_link_ids': [{'link_uuid' : {'uuid': to.optical_link_uuid}} for to in self.topology_optical_links], 'optical_link_ids': [{'link_uuid' : {'uuid': to.optical_link_uuid}} for to in self.topology_optical_links], } } def dump_details(self) -> Dict: def dump_details(self) -> Dict: Loading @@ -68,7 +65,7 @@ class TopologyModel(_Base): 'name' : self.topology_name, 'name' : self.topology_name, 'devices' : devices, 'devices' : devices, 'links' : links, 'links' : links, 'optical_links':optical_links 'optical_links': optical_links, } } class TopologyDeviceModel(_Base): class TopologyDeviceModel(_Base): Loading src/context/service/database/uuids/EndPoint.py +0 −5 Original line number Original line Diff line number Diff line Loading @@ -18,26 +18,21 @@ from common.method_wrappers.ServiceExceptions import InvalidArgumentsException from ._Builder import get_uuid_from_string, get_uuid_random from ._Builder import get_uuid_from_string, get_uuid_random from .Device import device_get_uuid from .Device import device_get_uuid from .Topology import topology_get_uuid from .Topology import topology_get_uuid import logging def endpoint_get_uuid( def endpoint_get_uuid( endpoint_id : EndPointId, endpoint_name : str = '', allow_random : bool = False endpoint_id : EndPointId, endpoint_name : str = '', allow_random : bool = False ) -> Tuple[str, str, str]: ) -> Tuple[str, str, str]: device_uuid = device_get_uuid(endpoint_id.device_id, allow_random=False) device_uuid = device_get_uuid(endpoint_id.device_id, allow_random=False) _,topology_uuid = topology_get_uuid(endpoint_id.topology_id, allow_random=False, allow_default=True) _,topology_uuid = topology_get_uuid(endpoint_id.topology_id, allow_random=False, allow_default=True) raw_endpoint_uuid = endpoint_id.endpoint_uuid.uuid raw_endpoint_uuid = endpoint_id.endpoint_uuid.uuid if len(raw_endpoint_uuid) > 0: if len(raw_endpoint_uuid) > 0: prefix_for_name = '{:s}/{:s}'.format(topology_uuid, device_uuid) prefix_for_name = '{:s}/{:s}'.format(topology_uuid, device_uuid) return topology_uuid, device_uuid, get_uuid_from_string(raw_endpoint_uuid, prefix_for_name=prefix_for_name) return topology_uuid, device_uuid, get_uuid_from_string(raw_endpoint_uuid, prefix_for_name=prefix_for_name) if len(endpoint_name) > 0: if len(endpoint_name) > 0: prefix_for_name = '{:s}/{:s}'.format(topology_uuid, device_uuid) prefix_for_name = '{:s}/{:s}'.format(topology_uuid, device_uuid) return topology_uuid, device_uuid, get_uuid_from_string(endpoint_name, prefix_for_name=prefix_for_name) return topology_uuid, device_uuid, get_uuid_from_string(endpoint_name, prefix_for_name=prefix_for_name) if allow_random: if allow_random: return topology_uuid, device_uuid, get_uuid_random() return topology_uuid, device_uuid, get_uuid_random() raise InvalidArgumentsException([ raise InvalidArgumentsException([ Loading src/context/service/database/uuids/OpticalConfig.py +23 −19 Original line number Original line Diff line number Diff line # Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from common.method_wrappers.ServiceExceptions import InvalidArgumentsException from common.method_wrappers.ServiceExceptions import InvalidArgumentsException from ._Builder import get_uuid_from_string, get_uuid_random from common.proto.context_pb2 import DeviceId from common.proto.context_pb2 import DeviceId from ._Builder import get_uuid_from_string, get_uuid_random def channel_get_uuid( def channel_get_uuid( channel_name : str , device_id : str, allow_random : bool = False channel_name : str , device_id : str, allow_random : bool = False ) -> str: ) -> str: if len(channel_name) > 0: if len(channel_name) > 0: return get_uuid_from_string(channel_name) + device_id return get_uuid_from_string(channel_name) + device_id if allow_random: return get_uuid_random() if allow_random: return get_uuid_random() raise InvalidArgumentsException([ raise InvalidArgumentsException([ ('channel uuid', channel_name), ('channel uuid', channel_name), ], extra_details=['Channel name is required to produce a channel UUID']) ], extra_details=['Channel name is required to produce a channel UUID']) def transponder_get_uuid( def transponder_get_uuid( opticalconfig_id : str, allow_random : bool = False opticalconfig_id : str, allow_random : bool = False ) -> str: ) -> str: if opticalconfig_id is not None: if opticalconfig_id is not None: return get_uuid_from_string(f"{opticalconfig_id}-transponder") return get_uuid_from_string(f"{opticalconfig_id}-transponder") if allow_random: return get_uuid_random() if allow_random: return get_uuid_random() Loading @@ -32,29 +39,26 @@ def transponder_get_uuid( ], extra_details=['opticalconfig id is required to produce a transponder UUID']) ], extra_details=['opticalconfig id is required to produce a transponder UUID']) def roadm_get_uuid( def roadm_get_uuid( opticalconfig_id : str, allow_random : bool = False opticalconfig_id : str, allow_random : bool = False ) -> str: ) -> str: if opticalconfig_id is not None: if opticalconfig_id is not None: return get_uuid_from_string(f"{opticalconfig_id}-roadm") return get_uuid_from_string(f"{opticalconfig_id}-roadm") if allow_random: return get_uuid_random() raise InvalidArgumentsException([ raise InvalidArgumentsException([ ('roadm uuid', opticalconfig_id), ('roadm uuid', opticalconfig_id), ], extra_details=['opticalconfig id is required to produce a roadm UUID']) ], extra_details=['opticalconfig id is required to produce a roadm UUID']) def opticalconfig_get_uuid( device_id : DeviceId, allow_random : bool = False def opticalconfig_get_uuid ( device_id: DeviceId, allow_random : bool = False) -> str : ) -> str: device_uuid = device_id.device_uuid.uuid device_uuid = device_id.device_uuid.uuid if (len(device_uuid)>0): if (len(device_uuid)>0): return get_uuid_from_string(f"{device_uuid}_opticalconfig") return get_uuid_from_string(f"{device_uuid}_opticalconfig") if allow_random: return get_uuid_random() if allow_random: return get_uuid_random() raise InvalidArgumentsException([ raise InvalidArgumentsException([ ('DeviceId ', device_id), ('DeviceId ', device_id), ], extra_details=['device_id is required to produce a OpticalConfig UUID']) ], extra_details=['device_id is required to produce a OpticalConfig UUID']) Loading
src/context/service/database/models/DeviceModel.py +5 −7 Original line number Original line Diff line number Diff line Loading @@ -38,8 +38,6 @@ class DeviceModel(_Base): endpoints = relationship('EndPointModel', passive_deletes=True) # lazy='joined', back_populates='device' endpoints = relationship('EndPointModel', passive_deletes=True) # lazy='joined', back_populates='device' components = relationship('ComponentModel', passive_deletes=True) # lazy='joined', back_populates='device' components = relationship('ComponentModel', passive_deletes=True) # lazy='joined', back_populates='device' controller = relationship('DeviceModel', remote_side=[device_uuid], passive_deletes=True) # lazy='joined', back_populates='device' controller = relationship('DeviceModel', remote_side=[device_uuid], passive_deletes=True) # lazy='joined', back_populates='device' # ------------------- Experimental ----------------------------------- optical_config = relationship('OpticalConfigModel', passive_deletes=True) optical_config = relationship('OpticalConfigModel', passive_deletes=True) def dump_id(self) -> Dict: def dump_id(self) -> Dict: Loading
src/context/service/database/models/Slot.py +16 −42 Original line number Original line Diff line number Diff line Loading @@ -12,34 +12,20 @@ # See the License for the specific language governing permissions and # See the License for the specific language governing permissions and # limitations under the License. # limitations under the License. from sqlalchemy.types import TypeDecorator, Integer from common.tools.object_factory.OpticalLink import order_dict import logging from sqlalchemy.types import PickleType , TypeDecorator ,Integer class SlotType(TypeDecorator): class SlotType(TypeDecorator): impl = Integer impl = Integer def process_bind_param(self, value, dialect): def process_bind_param(self, value, dialect): if value is not None: if value is not None: value =order_dict(value) bin_num = "0b" bin_num = "0b" for i,(key,val) in enumerate(value.items()): for i,(key,val) in enumerate(value.items()): bin_num =bin_num + f"{val}" bin_num =bin_num + f"{val}" int_num = int(bin_num,2) int_num = int(bin_num,2) return int_num return int_num def process_result_value(self, value, dialect): def process_result_value(self, value, dialect): if value is not None: if value is not None: slot = dict() slot = dict() bin_num = bin(value) bin_num = bin(value) Loading @@ -48,14 +34,10 @@ class SlotType(TypeDecorator): slot[str(i+1)]=int(sliced_num[i]) slot[str(i+1)]=int(sliced_num[i]) return slot return slot class C_Slot(SlotType): class C_Slot(SlotType): start_point = 0 start_point = 0 def process_result_value(self, value, dialect): def process_result_value(self, value, dialect): if value is not None: if value is not None: slot = dict() slot = dict() bin_num = bin(value) bin_num = bin(value) Loading @@ -63,20 +45,14 @@ class C_Slot (SlotType): if (len(sliced_num) != 20) : if (len(sliced_num) != 20) : for i in range(0,20 - len(sliced_num)): for i in range(0,20 - len(sliced_num)): sliced_num = '0' + sliced_num sliced_num = '0' + sliced_num for i in range(len(sliced_num)): for i in range(len(sliced_num)): slot[str(self.start_point+i+1)]=int(sliced_num[i]) slot[str(self.start_point+i+1)]=int(sliced_num[i]) return slot return slot class L_Slot (SlotType): class L_Slot (SlotType): start_point = 100 start_point = 100 def process_result_value(self, value, dialect): def process_result_value(self, value, dialect): if value is not None: if value is not None: slot = dict() slot = dict() bin_num = bin(value) bin_num = bin(value) Loading @@ -91,9 +67,7 @@ class L_Slot (SlotType): class S_Slot (SlotType): class S_Slot (SlotType): start_point = 500 start_point = 500 def process_result_value(self, value, dialect): def process_result_value(self, value, dialect): if value is not None: if value is not None: slot= dict() slot= dict() bin_num = bin(value) bin_num = bin(value) Loading
src/context/service/database/models/TopologyModel.py +18 −21 Original line number Original line Diff line number Diff line Loading @@ -30,8 +30,6 @@ class TopologyModel(_Base): context = relationship('ContextModel', back_populates='topologies', lazy='selectin') context = relationship('ContextModel', back_populates='topologies', lazy='selectin') topology_devices = relationship('TopologyDeviceModel') # back_populates='topology' topology_devices = relationship('TopologyDeviceModel') # back_populates='topology' topology_links = relationship('TopologyLinkModel' ) # back_populates='topology' topology_links = relationship('TopologyLinkModel' ) # back_populates='topology' #-------------------------- Experimental --------------------------- topology_optical_links = relationship("TopologyOpticalLinkModel") topology_optical_links = relationship("TopologyOpticalLinkModel") def dump_id(self) -> Dict: def dump_id(self) -> Dict: Loading @@ -47,7 +45,6 @@ class TopologyModel(_Base): 'device_ids' : [{'device_uuid': {'uuid': td.device_uuid }} for td in self.topology_devices ], 'device_ids' : [{'device_uuid': {'uuid': td.device_uuid }} for td in self.topology_devices ], 'link_ids' : [{'link_uuid' : {'uuid': tl.link_uuid }} for tl in self.topology_links ], 'link_ids' : [{'link_uuid' : {'uuid': tl.link_uuid }} for tl in self.topology_links ], 'optical_link_ids': [{'link_uuid' : {'uuid': to.optical_link_uuid}} for to in self.topology_optical_links], 'optical_link_ids': [{'link_uuid' : {'uuid': to.optical_link_uuid}} for to in self.topology_optical_links], } } def dump_details(self) -> Dict: def dump_details(self) -> Dict: Loading @@ -68,7 +65,7 @@ class TopologyModel(_Base): 'name' : self.topology_name, 'name' : self.topology_name, 'devices' : devices, 'devices' : devices, 'links' : links, 'links' : links, 'optical_links':optical_links 'optical_links': optical_links, } } class TopologyDeviceModel(_Base): class TopologyDeviceModel(_Base): Loading
src/context/service/database/uuids/EndPoint.py +0 −5 Original line number Original line Diff line number Diff line Loading @@ -18,26 +18,21 @@ from common.method_wrappers.ServiceExceptions import InvalidArgumentsException from ._Builder import get_uuid_from_string, get_uuid_random from ._Builder import get_uuid_from_string, get_uuid_random from .Device import device_get_uuid from .Device import device_get_uuid from .Topology import topology_get_uuid from .Topology import topology_get_uuid import logging def endpoint_get_uuid( def endpoint_get_uuid( endpoint_id : EndPointId, endpoint_name : str = '', allow_random : bool = False endpoint_id : EndPointId, endpoint_name : str = '', allow_random : bool = False ) -> Tuple[str, str, str]: ) -> Tuple[str, str, str]: device_uuid = device_get_uuid(endpoint_id.device_id, allow_random=False) device_uuid = device_get_uuid(endpoint_id.device_id, allow_random=False) _,topology_uuid = topology_get_uuid(endpoint_id.topology_id, allow_random=False, allow_default=True) _,topology_uuid = topology_get_uuid(endpoint_id.topology_id, allow_random=False, allow_default=True) raw_endpoint_uuid = endpoint_id.endpoint_uuid.uuid raw_endpoint_uuid = endpoint_id.endpoint_uuid.uuid if len(raw_endpoint_uuid) > 0: if len(raw_endpoint_uuid) > 0: prefix_for_name = '{:s}/{:s}'.format(topology_uuid, device_uuid) prefix_for_name = '{:s}/{:s}'.format(topology_uuid, device_uuid) return topology_uuid, device_uuid, get_uuid_from_string(raw_endpoint_uuid, prefix_for_name=prefix_for_name) return topology_uuid, device_uuid, get_uuid_from_string(raw_endpoint_uuid, prefix_for_name=prefix_for_name) if len(endpoint_name) > 0: if len(endpoint_name) > 0: prefix_for_name = '{:s}/{:s}'.format(topology_uuid, device_uuid) prefix_for_name = '{:s}/{:s}'.format(topology_uuid, device_uuid) return topology_uuid, device_uuid, get_uuid_from_string(endpoint_name, prefix_for_name=prefix_for_name) return topology_uuid, device_uuid, get_uuid_from_string(endpoint_name, prefix_for_name=prefix_for_name) if allow_random: if allow_random: return topology_uuid, device_uuid, get_uuid_random() return topology_uuid, device_uuid, get_uuid_random() raise InvalidArgumentsException([ raise InvalidArgumentsException([ Loading
src/context/service/database/uuids/OpticalConfig.py +23 −19 Original line number Original line Diff line number Diff line # Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from common.method_wrappers.ServiceExceptions import InvalidArgumentsException from common.method_wrappers.ServiceExceptions import InvalidArgumentsException from ._Builder import get_uuid_from_string, get_uuid_random from common.proto.context_pb2 import DeviceId from common.proto.context_pb2 import DeviceId from ._Builder import get_uuid_from_string, get_uuid_random def channel_get_uuid( def channel_get_uuid( channel_name : str , device_id : str, allow_random : bool = False channel_name : str , device_id : str, allow_random : bool = False ) -> str: ) -> str: if len(channel_name) > 0: if len(channel_name) > 0: return get_uuid_from_string(channel_name) + device_id return get_uuid_from_string(channel_name) + device_id if allow_random: return get_uuid_random() if allow_random: return get_uuid_random() raise InvalidArgumentsException([ raise InvalidArgumentsException([ ('channel uuid', channel_name), ('channel uuid', channel_name), ], extra_details=['Channel name is required to produce a channel UUID']) ], extra_details=['Channel name is required to produce a channel UUID']) def transponder_get_uuid( def transponder_get_uuid( opticalconfig_id : str, allow_random : bool = False opticalconfig_id : str, allow_random : bool = False ) -> str: ) -> str: if opticalconfig_id is not None: if opticalconfig_id is not None: return get_uuid_from_string(f"{opticalconfig_id}-transponder") return get_uuid_from_string(f"{opticalconfig_id}-transponder") if allow_random: return get_uuid_random() if allow_random: return get_uuid_random() Loading @@ -32,29 +39,26 @@ def transponder_get_uuid( ], extra_details=['opticalconfig id is required to produce a transponder UUID']) ], extra_details=['opticalconfig id is required to produce a transponder UUID']) def roadm_get_uuid( def roadm_get_uuid( opticalconfig_id : str, allow_random : bool = False opticalconfig_id : str, allow_random : bool = False ) -> str: ) -> str: if opticalconfig_id is not None: if opticalconfig_id is not None: return get_uuid_from_string(f"{opticalconfig_id}-roadm") return get_uuid_from_string(f"{opticalconfig_id}-roadm") if allow_random: return get_uuid_random() raise InvalidArgumentsException([ raise InvalidArgumentsException([ ('roadm uuid', opticalconfig_id), ('roadm uuid', opticalconfig_id), ], extra_details=['opticalconfig id is required to produce a roadm UUID']) ], extra_details=['opticalconfig id is required to produce a roadm UUID']) def opticalconfig_get_uuid( device_id : DeviceId, allow_random : bool = False def opticalconfig_get_uuid ( device_id: DeviceId, allow_random : bool = False) -> str : ) -> str: device_uuid = device_id.device_uuid.uuid device_uuid = device_id.device_uuid.uuid if (len(device_uuid)>0): if (len(device_uuid)>0): return get_uuid_from_string(f"{device_uuid}_opticalconfig") return get_uuid_from_string(f"{device_uuid}_opticalconfig") if allow_random: return get_uuid_random() if allow_random: return get_uuid_random() raise InvalidArgumentsException([ raise InvalidArgumentsException([ ('DeviceId ', device_id), ('DeviceId ', device_id), ], extra_details=['device_id is required to produce a OpticalConfig UUID']) ], extra_details=['device_id is required to produce a OpticalConfig UUID'])