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

Context component:

- Added logic to keep order of link endpoints
parent efed73e3
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!71OFC'23 + IETF L2VPN Device Driver + Device Controllers + Multiple small improvements
...@@ -64,13 +64,14 @@ def link_set(db_engine : Engine, request : Link) -> Tuple[Dict, bool]: ...@@ -64,13 +64,14 @@ def link_set(db_engine : Engine, request : Link) -> Tuple[Dict, bool]:
topology_uuids : Set[str] = set() topology_uuids : Set[str] = set()
related_topologies : List[Dict] = list() related_topologies : List[Dict] = list()
link_endpoints_data : List[Dict] = list() link_endpoints_data : List[Dict] = list()
for endpoint_id in request.link_endpoint_ids: for i,endpoint_id in enumerate(request.link_endpoint_ids):
endpoint_topology_uuid, _, endpoint_uuid = endpoint_get_uuid( endpoint_topology_uuid, _, endpoint_uuid = endpoint_get_uuid(
endpoint_id, allow_random=False) endpoint_id, allow_random=False)
link_endpoints_data.append({ link_endpoints_data.append({
'link_uuid' : link_uuid, 'link_uuid' : link_uuid,
'endpoint_uuid': endpoint_uuid, 'endpoint_uuid': endpoint_uuid,
'position' : i,
}) })
if endpoint_topology_uuid not in topology_uuids: if endpoint_topology_uuid not in topology_uuids:
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
# 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 import Column, DateTime, ForeignKey, String import operator
from sqlalchemy import CheckConstraint, Column, DateTime, ForeignKey, Integer, String
from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from typing import Dict from typing import Dict
...@@ -38,7 +39,7 @@ class LinkModel(_Base): ...@@ -38,7 +39,7 @@ class LinkModel(_Base):
'name' : self.link_name, 'name' : self.link_name,
'link_endpoint_ids': [ 'link_endpoint_ids': [
link_endpoint.endpoint.dump_id() link_endpoint.endpoint.dump_id()
for link_endpoint in self.link_endpoints for link_endpoint in sorted(self.link_endpoints, key=operator.attrgetter('position'))
], ],
} }
...@@ -47,6 +48,11 @@ class LinkEndPointModel(_Base): ...@@ -47,6 +48,11 @@ class LinkEndPointModel(_Base):
link_uuid = Column(ForeignKey('link.link_uuid', ondelete='CASCADE' ), primary_key=True) link_uuid = Column(ForeignKey('link.link_uuid', ondelete='CASCADE' ), primary_key=True)
endpoint_uuid = Column(ForeignKey('endpoint.endpoint_uuid', ondelete='RESTRICT'), primary_key=True, index=True) endpoint_uuid = Column(ForeignKey('endpoint.endpoint_uuid', ondelete='RESTRICT'), primary_key=True, index=True)
position = Column(Integer, nullable=False)
link = relationship('LinkModel', back_populates='link_endpoints', lazy='joined') link = relationship('LinkModel', back_populates='link_endpoints', lazy='joined')
endpoint = relationship('EndPointModel', lazy='joined') # back_populates='link_endpoints' endpoint = relationship('EndPointModel', lazy='joined') # back_populates='link_endpoints'
__table_args__ = (
CheckConstraint(position >= 0, name='check_position_value'),
)
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