Newer
Older
# 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 sqlalchemy import CheckConstraint, Column, DateTime, Enum, ForeignKey, Integer, String
from .enums.ConstraintAction import ORM_ConstraintActionEnum
# Enum values should match name of field in Constraint message
# - 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
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'
Shayan Hajipour
committed
QOS_PROFILE = 'qos_profile'
class ServiceConstraintModel(_Base):
__tablename__ = 'service_constraint'
constraint_uuid = Column(UUID(as_uuid=False), primary_key=True)
service_uuid = Column(ForeignKey('service.service_uuid', ondelete='CASCADE'), nullable=False) #, index=True
position = Column(Integer, nullable=False)
kind = Column(Enum(ConstraintKindEnum), nullable=False)
action = Column(Enum(ORM_ConstraintActionEnum), nullable=False)
created_at = Column(DateTime, nullable=False)
updated_at = Column(DateTime, nullable=False)
__table_args__ = (
CheckConstraint(position >= 0, name='check_position_value'),
#UniqueConstraint('service_uuid', 'position', name='unique_per_service'),
return {
'action': self.action.value,
self.kind.value: json.loads(self.data),
}
class SliceConstraintModel(_Base):
__tablename__ = 'slice_constraint'
constraint_uuid = Column(UUID(as_uuid=False), primary_key=True)
slice_uuid = Column(ForeignKey('slice.slice_uuid', ondelete='CASCADE'), nullable=False) #, index=True
position = Column(Integer, nullable=False)
kind = Column(Enum(ConstraintKindEnum), nullable=False)
action = Column(Enum(ORM_ConstraintActionEnum), nullable=False)
data = Column(String, nullable=False)
created_at = Column(DateTime, nullable=False)
updated_at = Column(DateTime, nullable=False)
__table_args__ = (
CheckConstraint(position >= 0, name='check_position_value'),
#UniqueConstraint('slice_uuid', 'position', name='unique_per_slice' ),
return {
'action': self.action.value,
self.kind.value: json.loads(self.data),
}