Commit 6091ecff authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Context component:

- Fixed composition of PolicyRule messages
- Added position of endpoints in Link, Service, and Slice.
- Added sort of endpoints according to their position.
parent 19e76285
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -64,13 +64,14 @@ def link_set(db_engine : Engine, request : Link) -> Tuple[Dict, bool]:
    topology_uuids : Set[str] = set()
    related_topologies : 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_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:
+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ def service_set(db_engine : Engine, request : Service) -> Tuple[Dict, bool]:
        service_endpoints_data.append({
            'service_uuid' : service_uuid,
            'endpoint_uuid': endpoint_uuid,
            'position'     : i,
        })

    constraints = compose_constraints_data(request.service_constraints, now, service_uuid=service_uuid)
+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ def slice_set(db_engine : Engine, request : Slice) -> Tuple[Dict, bool]:
        slice_endpoints_data.append({
            'slice_uuid'   : slice_uuid,
            'endpoint_uuid': endpoint_uuid,
            'position'     : i,
        })

    slice_services_data : List[Dict] = list()
+8 −2
Original line number Diff line number Diff line
@@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# 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.orm import relationship
from typing import Dict
@@ -38,7 +39,7 @@ class LinkModel(_Base):
            'name'             : self.link_name,
            'link_endpoint_ids': [
                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):

    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)
    position      = Column(Integer, nullable=False)

    link     = relationship('LinkModel',     back_populates='link_endpoints', lazy='joined')
    endpoint = relationship('EndPointModel', lazy='joined') # back_populates='link_endpoints'

    __table_args__ = (
        CheckConstraint(position >= 0, name='check_position_value'),
    )
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ class PolicyRuleModel(_Base):
            'deviceList': [{'device_uuid': {'uuid': pr_d.device_uuid}} for pr_d in self.policyrule_devices],
        }
        if self.policyrule_kind == PolicyRuleKindEnum.SERVICE:
            result['serviceId'] = self.policyrule_service.dump_id(),
            result['serviceId'] = self.policyrule_service.dump_id()
        return {self.policyrule_kind.value: result}

class PolicyRuleDeviceModel(_Base):
Loading