Scheduled maintenance on Saturday, 27 September 2025, from 07:00 AM to 4:00 PM GMT (09:00 AM to 6:00 PM CEST) - some services may be unavailable -

Skip to content
Snippets Groups Projects
ConstraintModel.py 2.31 KiB
Newer Older
  • Learn to ignore specific revisions
  • Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (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.
    
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    import enum, json
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    from sqlalchemy import CheckConstraint, Column, DateTime, Enum, ForeignKey, Integer, String
    
    Carlos Manso's avatar
    Carlos Manso committed
    from sqlalchemy.dialects.postgresql import UUID
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    from typing import Dict
    from ._Base import _Base
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    # Enum values should match name of field in Constraint message
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    # - enum item name should be Constraint message type in upper case
    # - enum item value should be Constraint message type as it is in the proto files
    
    Carlos Manso's avatar
    Carlos Manso committed
    class ConstraintKindEnum(enum.Enum):
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        CUSTOM            = 'custom'
        SCHEDULE          = 'schedule'
        ENDPOINT_LOCATION = 'endpoint_location'
        ENDPOINT_PRIORITY = 'endpoint_priority'
        SLA_CAPACITY      = 'sla_capacity'
        SLA_LATENCY       = 'sla_latency'
        SLA_AVAILABILITY  = 'sla_availability'
        SLA_ISOLATION     = 'sla_isolation'
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    class ConstraintModel(_Base):
        __tablename__ = 'constraint'
    
        constraint_uuid = Column(UUID(as_uuid=False), primary_key=True)
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        service_uuid    = Column(ForeignKey('service.service_uuid', ondelete='CASCADE'), nullable=True)
        slice_uuid      = Column(ForeignKey('slice.slice_uuid',     ondelete='CASCADE'), nullable=True)
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        position        = Column(Integer, nullable=False)
        kind            = Column(Enum(ConstraintKindEnum), nullable=False)
        data            = Column(String, nullable=False)
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        created_at      = Column(DateTime, nullable=False)
        updated_at      = Column(DateTime, nullable=False)
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    
        __table_args__ = (
            CheckConstraint(position >= 0, name='check_position_value'),
            #UniqueConstraint('service_uuid', 'position', name='unique_per_service'),
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
            #UniqueConstraint('slice_uuid',   'position', name='unique_per_slice'  ),
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
        )
    
        def dump(self) -> Dict:
            return {self.kind.value: json.loads(self.data)}