Skip to content
Snippets Groups Projects
Commit 2824ac8c authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Pre-merge code cleanup

parent 71ab5950
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!284Resolve: "(CNIT) Multi-Granular Optical Nodes and Optical Transpoders management"
This commit is part of merge request !284. Comments created here will be created in the context of that merge request.
...@@ -34,13 +34,11 @@ class DeviceModel(_Base): ...@@ -34,13 +34,11 @@ class DeviceModel(_Base):
updated_at = Column(DateTime, nullable=False) updated_at = Column(DateTime, nullable=False)
#topology_devices = relationship('TopologyDeviceModel', back_populates='device') #topology_devices = relationship('TopologyDeviceModel', back_populates='device')
config_rules = relationship('DeviceConfigRuleModel', passive_deletes=True) # lazy='joined', back_populates='device' config_rules = relationship('DeviceConfigRuleModel', passive_deletes=True) # lazy='joined', back_populates='device'
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'
optical_config = relationship('OpticalConfigModel', passive_deletes=True)
# ------------------- Experimental -----------------------------------
optical_config= relationship('OpticalConfigModel',passive_deletes=True)
def dump_id(self) -> Dict: def dump_id(self) -> Dict:
return {'device_uuid': {'uuid': self.device_uuid}} return {'device_uuid': {'uuid': self.device_uuid}}
......
...@@ -33,9 +33,9 @@ class EndPointModel(_Base): ...@@ -33,9 +33,9 @@ class EndPointModel(_Base):
updated_at = Column(DateTime, nullable=False) updated_at = Column(DateTime, nullable=False)
endpoint_location = Column(String, nullable=True) endpoint_location = Column(String, nullable=True)
device = relationship('DeviceModel', back_populates='endpoints') # lazy='selectin' device = relationship('DeviceModel', back_populates='endpoints') # lazy='selectin'
topology = relationship('TopologyModel', lazy='selectin') topology = relationship('TopologyModel', lazy='selectin')
optical_link_endpoints = relationship('OpticalLinkEndPointModel', back_populates='endpoint' ) optical_link_endpoints = relationship('OpticalLinkEndPointModel', back_populates='endpoint' )
#link_endpoints = relationship('LinkEndPointModel', back_populates='endpoint' ) #link_endpoints = relationship('LinkEndPointModel', back_populates='endpoint' )
#service_endpoints = relationship('ServiceEndPointModel', back_populates='endpoint' ) #service_endpoints = relationship('ServiceEndPointModel', back_populates='endpoint' )
......
...@@ -12,75 +12,51 @@ ...@@ -12,75 +12,51 @@
# 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:
bin_num = "0b"
value =order_dict(value)
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)
sliced_num=bin_num[2:] sliced_num = bin_num[2:]
for i in range(len(sliced_num)): for i in range(len(sliced_num)):
slot[str(i+1)]=int(sliced_num[i]) slot[str(i+1)]=int(sliced_num[i])
return slot return slot
class C_Slot (SlotType):
start_point=0
class C_Slot(SlotType):
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)
sliced_num=bin_num[2:] sliced_num = bin_num[2:]
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):
start_point=100
class L_Slot (SlotType):
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)
sliced_num=bin_num[2:] sliced_num = bin_num[2:]
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
...@@ -89,11 +65,9 @@ class L_Slot (SlotType): ...@@ -89,11 +65,9 @@ class L_Slot (SlotType):
return slot return slot
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)
......
...@@ -27,12 +27,10 @@ class TopologyModel(_Base): ...@@ -27,12 +27,10 @@ class TopologyModel(_Base):
created_at = Column(DateTime, nullable=False) created_at = Column(DateTime, nullable=False)
updated_at = Column(DateTime, nullable=False) updated_at = Column(DateTime, nullable=False)
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'
topology_optical_links = relationship("TopologyOpticalLinkModel")
#-------------------------- Experimental ---------------------------
topology_optical_links= relationship("TopologyOpticalLinkModel")
def dump_id(self) -> Dict: def dump_id(self) -> Dict:
return { return {
...@@ -42,12 +40,11 @@ class TopologyModel(_Base): ...@@ -42,12 +40,11 @@ class TopologyModel(_Base):
def dump(self) -> Dict: def dump(self) -> Dict:
return { return {
'topology_id': self.dump_id(), 'topology_id' : self.dump_id(),
'name' : self.topology_name, 'name' : self.topology_name,
'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:
...@@ -64,11 +61,11 @@ class TopologyModel(_Base): ...@@ -64,11 +61,11 @@ class TopologyModel(_Base):
for ol in self.topology_optical_links for ol in self.topology_optical_links
] ]
return { return {
'topology_id': self.dump_id(), 'topology_id' : self.dump_id(),
'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):
...@@ -94,8 +91,8 @@ class TopologyLinkModel(_Base): ...@@ -94,8 +91,8 @@ class TopologyLinkModel(_Base):
class TopologyOpticalLinkModel(_Base): class TopologyOpticalLinkModel(_Base):
__tablename__ = 'topology_optical_link' __tablename__ = 'topology_optical_link'
topology_uuid = Column(ForeignKey('topology.topology_uuid', ondelete='RESTRICT'), primary_key=True, index=True) topology_uuid = Column(ForeignKey('topology.topology_uuid', ondelete='RESTRICT'), primary_key=True, index=True)
optical_link_uuid = Column(ForeignKey('opticallink.opticallink_uuid', ondelete='CASCADE' ), primary_key=True, index=True) optical_link_uuid = Column(ForeignKey('opticallink.opticallink_uuid', ondelete='CASCADE' ), primary_key=True, index=True)
topology = relationship('TopologyModel', lazy='selectin', viewonly=True) # back_populates='topology_optical_links' topology = relationship('TopologyModel', lazy='selectin', viewonly=True) # back_populates='topology_optical_links'
optical_link = relationship('OpticalLinkModel', lazy='selectin') # back_populates='topology_optical_links' optical_link = relationship('OpticalLinkModel', lazy='selectin') # back_populates='topology_optical_links'
...@@ -18,26 +18,21 @@ from common.method_wrappers.ServiceExceptions import InvalidArgumentsException ...@@ -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([
......
# 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()
...@@ -31,30 +38,27 @@ def transponder_get_uuid( ...@@ -31,30 +38,27 @@ def transponder_get_uuid(
('transponder uuid', opticalconfig_id), ('transponder uuid', opticalconfig_id),
], 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) -> str : def opticalconfig_get_uuid(
device_id : DeviceId, allow_random : bool = False
) -> 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'])
\ No newline at end of file
...@@ -17,26 +17,19 @@ from common.proto.context_pb2 import EndPointId ...@@ -17,26 +17,19 @@ from common.proto.context_pb2 import EndPointId
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 ._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
import logging
def optical_endpoint_get_uuid( def optical_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)
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}'.format( device_uuid) prefix_for_name = '{:s}'.format( device_uuid)
return device_uuid, get_uuid_from_string(raw_endpoint_uuid, prefix_for_name=prefix_for_name) return 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}'.format( device_uuid) prefix_for_name = '{:s}'.format( device_uuid)
return device_uuid, get_uuid_from_string(endpoint_name, prefix_for_name=prefix_for_name) return device_uuid, get_uuid_from_string(endpoint_name, prefix_for_name=prefix_for_name)
if allow_random: if allow_random:
return device_uuid, get_uuid_random() return device_uuid, get_uuid_random()
raise InvalidArgumentsException([ raise InvalidArgumentsException([
......
# 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.proto.context_pb2 import LinkId
from common.method_wrappers.ServiceExceptions import InvalidArgumentsException from common.method_wrappers.ServiceExceptions import InvalidArgumentsException
from common.proto.context_pb2 import LinkId
from ._Builder import get_uuid_from_string, get_uuid_random from ._Builder import get_uuid_from_string, get_uuid_random
optical_detail_sp="Optical_link_detail" optical_detail_sp = "Optical_link_detail"
def opticaldetail_get_uuid( def opticaldetail_get_uuid(
link_id : LinkId,allow_random=False link_id : LinkId,allow_random=False
) -> str: ) -> str:
link_uuid = link_id.link_uuid.uuid link_uuid = link_id.link_uuid.uuid
if len(link_uuid) > 0: if len(link_uuid) > 0:
str_uuid=f"{link_uuid}{optical_detail_sp}" str_uuid=f"{link_uuid}{optical_detail_sp}"
return get_uuid_from_string(str_uuid) return get_uuid_from_string(str_uuid)
if allow_random: return get_uuid_random()
if allow_random: return get_uuid_random()
raise InvalidArgumentsException([ raise InvalidArgumentsException([
('link_id.link_uuid.uuid', link_uuid), ('link_id.link_uuid.uuid', link_uuid),
], extra_details=['At least one is required to produce a Optical Link Detail UUID']) ], extra_details=['At least one is required to produce a Optical Link Detail UUID'])
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
from typing import Optional, Union from typing import Optional, Union
from uuid import UUID, uuid4, uuid5 from uuid import UUID, uuid4, uuid5
import logging
# Generate a UUIDv5-like from the SHA-1 of "TFS" and no namespace to be used as the NAMESPACE for all # Generate a UUIDv5-like from the SHA-1 of "TFS" and no namespace to be used as the NAMESPACE for all
# the context UUIDs generated. For efficiency purposes, the UUID is hardcoded; however, it is produced # the context UUIDs generated. For efficiency purposes, the UUID is hardcoded; however, it is produced
# using the following code: # using the following code:
...@@ -32,12 +32,10 @@ def get_uuid_from_string(str_uuid_or_name : Union[str, UUID], prefix_for_name : ...@@ -32,12 +32,10 @@ def get_uuid_from_string(str_uuid_or_name : Union[str, UUID], prefix_for_name :
raise Exception(MSG.format(str(repr(str_uuid_or_name)))) raise Exception(MSG.format(str(repr(str_uuid_or_name))))
try: try:
# try to parse as UUID # try to parse as UUID
return str(UUID(str_uuid_or_name)) return str(UUID(str_uuid_or_name))
except: # pylint: disable=bare-except except: # pylint: disable=bare-except
# produce a UUID within TFS namespace from parameter # produce a UUID within TFS namespace from parameter
if prefix_for_name is not None: if prefix_for_name is not None:
str_uuid_or_name = '{:s}/{:s}'.format(prefix_for_name, str_uuid_or_name) str_uuid_or_name = '{:s}/{:s}'.format(prefix_for_name, str_uuid_or_name)
return str(uuid5(NAMESPACE_TFS, str_uuid_or_name)) return str(uuid5(NAMESPACE_TFS, str_uuid_or_name))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment