Loading src/context/service/database/Link.py +3 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ from sqlalchemy.engine import Engine from sqlalchemy.orm import Session, selectinload, sessionmaker from sqlalchemy_cockroachdb import run_transaction from typing import Dict, List, Optional, Set, Tuple from common.proto.context_pb2 import Empty, EventTypeEnum, Link, LinkId, LinkIdList, LinkList, TopologyId from common.proto.context_pb2 import ( Empty, EventTypeEnum, Link, LinkId, LinkIdList, LinkList, TopologyId ) from common.message_broker.MessageBroker import MessageBroker from common.method_wrappers.ServiceExceptions import NotFoundException from common.tools.object_factory.Link import json_link_id Loading src/context/service/database/OpticalLink.py +5 −5 Original line number Diff line number Diff line Loading @@ -66,9 +66,10 @@ def optical_link_set(db_engine : Engine, messagebroker : MessageBroker, request now = datetime.datetime.now(datetime.timezone.utc) # By default, always add link to default Context/Topology topology_uuids : Set[str] = set() related_topologies : List[Dict] = list() # By default, always add link to default Context/Topology _,topology_uuid = topology_get_uuid(TopologyId(), allow_random=False, allow_default=True) related_topologies.append({ 'topology_uuid': topology_uuid, Loading @@ -77,15 +78,14 @@ def optical_link_set(db_engine : Engine, messagebroker : MessageBroker, request topology_uuids.add(topology_uuid) link_endpoints_data : List[Dict] = list() for i,endpoint_id in enumerate(request.link_endpoint_ids): endpoint_topology_uuid, endpoint_device_uuid, endpoint_uuid = endpoint_get_uuid( endpoint_id, endpoint_name="", allow_random=True) endpoint_topology_uuid, _, endpoint_uuid = endpoint_get_uuid( endpoint_id, allow_random=False) link_endpoints_data.append({ 'link_uuid' : link_uuid, 'endpoint_uuid': endpoint_uuid, 'position' : i, }) if endpoint_topology_uuid not in topology_uuids: Loading src/context/service/database/models/OpticalLinkModel.py +11 −4 Original line number Diff line number Diff line Loading @@ -12,8 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. from sqlalchemy import Column, DateTime, ForeignKey, Integer, String ,Boolean import operator from sqlalchemy import ( Boolean, CheckConstraint, Column, DateTime, ForeignKey, Integer, String ) from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import relationship from typing import Dict Loading Loading @@ -59,7 +61,7 @@ class OpticalLinkModel(_Base): }, 'link_endpoint_ids' : [ optical_endpoint.endpoint.dump_id() for optical_endpoint in self.opticallink_endpoints for optical_endpoint in sorted(self.opticallink_endpoints, key=operator.attrgetter('position')) ], } return result Loading @@ -69,6 +71,11 @@ class OpticalLinkEndPointModel(_Base): link_uuid = Column(ForeignKey('opticallink.opticallink_uuid', ondelete='CASCADE' ), primary_key=True) endpoint_uuid = Column(ForeignKey('endpoint.endpoint_uuid', ondelete='RESTRICT'), primary_key=True, index=True) position = Column(Integer, nullable=False) optical_link = relationship('OpticalLinkModel', back_populates='opticallink_endpoints') endpoint = relationship('EndPointModel', lazy='selectin') __table_args__ = ( CheckConstraint(position >= 0, name='check_position_value'), ) Loading
src/context/service/database/Link.py +3 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ from sqlalchemy.engine import Engine from sqlalchemy.orm import Session, selectinload, sessionmaker from sqlalchemy_cockroachdb import run_transaction from typing import Dict, List, Optional, Set, Tuple from common.proto.context_pb2 import Empty, EventTypeEnum, Link, LinkId, LinkIdList, LinkList, TopologyId from common.proto.context_pb2 import ( Empty, EventTypeEnum, Link, LinkId, LinkIdList, LinkList, TopologyId ) from common.message_broker.MessageBroker import MessageBroker from common.method_wrappers.ServiceExceptions import NotFoundException from common.tools.object_factory.Link import json_link_id Loading
src/context/service/database/OpticalLink.py +5 −5 Original line number Diff line number Diff line Loading @@ -66,9 +66,10 @@ def optical_link_set(db_engine : Engine, messagebroker : MessageBroker, request now = datetime.datetime.now(datetime.timezone.utc) # By default, always add link to default Context/Topology topology_uuids : Set[str] = set() related_topologies : List[Dict] = list() # By default, always add link to default Context/Topology _,topology_uuid = topology_get_uuid(TopologyId(), allow_random=False, allow_default=True) related_topologies.append({ 'topology_uuid': topology_uuid, Loading @@ -77,15 +78,14 @@ def optical_link_set(db_engine : Engine, messagebroker : MessageBroker, request topology_uuids.add(topology_uuid) link_endpoints_data : List[Dict] = list() for i,endpoint_id in enumerate(request.link_endpoint_ids): endpoint_topology_uuid, endpoint_device_uuid, endpoint_uuid = endpoint_get_uuid( endpoint_id, endpoint_name="", allow_random=True) endpoint_topology_uuid, _, endpoint_uuid = endpoint_get_uuid( endpoint_id, allow_random=False) link_endpoints_data.append({ 'link_uuid' : link_uuid, 'endpoint_uuid': endpoint_uuid, 'position' : i, }) if endpoint_topology_uuid not in topology_uuids: Loading
src/context/service/database/models/OpticalLinkModel.py +11 −4 Original line number Diff line number Diff line Loading @@ -12,8 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. from sqlalchemy import Column, DateTime, ForeignKey, Integer, String ,Boolean import operator from sqlalchemy import ( Boolean, CheckConstraint, Column, DateTime, ForeignKey, Integer, String ) from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import relationship from typing import Dict Loading Loading @@ -59,7 +61,7 @@ class OpticalLinkModel(_Base): }, 'link_endpoint_ids' : [ optical_endpoint.endpoint.dump_id() for optical_endpoint in self.opticallink_endpoints for optical_endpoint in sorted(self.opticallink_endpoints, key=operator.attrgetter('position')) ], } return result Loading @@ -69,6 +71,11 @@ class OpticalLinkEndPointModel(_Base): link_uuid = Column(ForeignKey('opticallink.opticallink_uuid', ondelete='CASCADE' ), primary_key=True) endpoint_uuid = Column(ForeignKey('endpoint.endpoint_uuid', ondelete='RESTRICT'), primary_key=True, index=True) position = Column(Integer, nullable=False) optical_link = relationship('OpticalLinkModel', back_populates='opticallink_endpoints') endpoint = relationship('EndPointModel', lazy='selectin') __table_args__ = ( CheckConstraint(position >= 0, name='check_position_value'), )