diff --git a/src/context/service/database/Connection.py b/src/context/service/database/Connection.py index de45151a5ca95e974e940503aaade83a47faf46c..529c02d6e29b6434b3da0ec03593634b3ab87f08 100644 --- a/src/context/service/database/Connection.py +++ b/src/context/service/database/Connection.py @@ -74,7 +74,7 @@ def connection_set(db_engine : Engine, messagebroker : MessageBroker, request : _,service_uuid = service_get_uuid(request.service_id, allow_random=False) settings = grpc_message_to_json_string(request.settings), - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) connection_data = [{ 'connection_uuid': connection_uuid, diff --git a/src/context/service/database/Context.py b/src/context/service/database/Context.py index f0cd36f83fb3588976a3fcf515e2e97bd9613f4c..f3ef214c3715ac8c6110e3d5a18c2fb744d2d6db 100644 --- a/src/context/service/database/Context.py +++ b/src/context/service/database/Context.py @@ -82,7 +82,8 @@ def context_set(db_engine : Engine, messagebroker : MessageBroker, request : Con if len(request.slice_ids) > 0: # pragma: no cover LOGGER.warning('Items in field "slice_ids" ignored. This field is used for retrieval purposes only.') - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) + context_data = [{ 'context_uuid': context_uuid, 'context_name': context_name, diff --git a/src/context/service/database/Device.py b/src/context/service/database/Device.py index 930b5299f9c77243e5d26c453d051e3ecb455e27..7515f8d68227bd26f5d5384756186394492e5e53 100644 --- a/src/context/service/database/Device.py +++ b/src/context/service/database/Device.py @@ -92,7 +92,7 @@ def device_set(db_engine : Engine, messagebroker : MessageBroker, request : Devi oper_status = grpc_to_enum__device_operational_status(request.device_operational_status) device_drivers = [grpc_to_enum__device_driver(d) for d in request.device_drivers] - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) topology_uuids : Set[str] = set() related_topologies : List[Dict] = list() diff --git a/src/context/service/database/Link.py b/src/context/service/database/Link.py index deef3769cb64e34ae6c300f562c31983a8807286..6244a8517f66280893acb10944a235666beb80d4 100644 --- a/src/context/service/database/Link.py +++ b/src/context/service/database/Link.py @@ -22,11 +22,12 @@ from common.proto.context_pb2 import Empty, EventTypeEnum, Link, LinkId, LinkIdL from common.message_broker.MessageBroker import MessageBroker from common.method_wrappers.ServiceExceptions import NotFoundException from common.tools.object_factory.Link import json_link_id -from context.service.database.uuids.Topology import topology_get_uuid +from .models.enums.LinkType import grpc_to_enum__link_type_enum from .models.LinkModel import LinkModel, LinkEndPointModel from .models.TopologyModel import TopologyLinkModel, TopologyModel from .uuids.EndPoint import endpoint_get_uuid from .uuids.Link import link_get_uuid +from .uuids.Topology import topology_get_uuid from .Events import notify_event_context, notify_event_link, notify_event_topology LOGGER = logging.getLogger(__name__) @@ -68,7 +69,9 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) link_name = raw_link_uuid if len(raw_link_name) == 0 else raw_link_name link_uuid = link_get_uuid(request.link_id, link_name=link_name, allow_random=True) - now = datetime.datetime.utcnow() + link_type = grpc_to_enum__link_type_enum(request.link_type) + + now = datetime.datetime.now(datetime.timezone.utc) topology_uuids : Set[str] = set() related_topologies : List[Dict] = list() @@ -117,6 +120,7 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) link_data = [{ 'link_uuid' : link_uuid, 'link_name' : link_name, + 'link_type' : link_type, 'total_capacity_gbps' : total_capacity_gbps, 'used_capacity_gbps' : used_capacity_gbps, 'created_at' : now, @@ -129,6 +133,7 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) index_elements=[LinkModel.link_uuid], set_=dict( link_name = stmt.excluded.link_name, + link_type = stmt.excluded.link_type, total_capacity_gbps = stmt.excluded.total_capacity_gbps, used_capacity_gbps = stmt.excluded.used_capacity_gbps, updated_at = stmt.excluded.updated_at, diff --git a/src/context/service/database/OpticalLink.py b/src/context/service/database/OpticalLink.py index 53fd7bdb5a5964376c6ffb94c6b130b6744f7215..1f45daf43bb805e750b1742e6e4ea7e18039cc43 100644 --- a/src/context/service/database/OpticalLink.py +++ b/src/context/service/database/OpticalLink.py @@ -64,7 +64,7 @@ def optical_link_set(db_engine : Engine, messagebroker : MessageBroker, request link_name = raw_link_uuid if len(raw_link_name) == 0 else raw_link_name link_uuid = link_get_uuid(request.link_id, link_name=link_name, allow_random=True) - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) # By default, always add link to default Context/Topology topology_uuids : Set[str] = set() diff --git a/src/context/service/database/PolicyRule.py b/src/context/service/database/PolicyRule.py index 3d59c59b3ade828450924404d081e237b7a37c1f..ad38838fc127aaee1927f9e44ac0791cef105300 100644 --- a/src/context/service/database/PolicyRule.py +++ b/src/context/service/database/PolicyRule.py @@ -84,7 +84,7 @@ def policyrule_set(db_engine : Engine, messagebroker : MessageBroker, request : 'actionList': json_policyrule_basic.get('actionList', []), }, sort_keys=True) - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) policyrule_data = [{ 'policyrule_uuid' : policyrule_uuid, diff --git a/src/context/service/database/Service.py b/src/context/service/database/Service.py index c789b291bd15bda1a49d8dd68e78d1875adccfb7..62f07e4fbe4f90af7834358cc79d4c8cb82934f4 100644 --- a/src/context/service/database/Service.py +++ b/src/context/service/database/Service.py @@ -91,7 +91,7 @@ def service_set(db_engine : Engine, messagebroker : MessageBroker, request : Ser service_status = grpc_to_enum__service_status(request.service_status.service_status) - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) service_endpoints_data : List[Dict] = list() for i,endpoint_id in enumerate(request.service_endpoint_ids): @@ -180,7 +180,8 @@ def service_unset(db_engine : Engine, messagebroker : MessageBroker, request : S ['should be == request.service_id.context_id.context_uuid.uuid({:s})'.format(raw_context_uuid)]) service_endpoint_uuids.add(endpoint_get_uuid(endpoint_id, allow_random=False)[2]) - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) + constraints = compose_constraints_data(request.service_constraints, now, service_uuid=service_uuid) config_rules = compose_config_rules_data(request.service_config.config_rules, now, service_uuid=service_uuid) diff --git a/src/context/service/database/Slice.py b/src/context/service/database/Slice.py index 18620e6fc76bbbbf6f445767d92a108f84c20a06..84e210e025e750613387a18c4c7eef4618cdfcdb 100644 --- a/src/context/service/database/Slice.py +++ b/src/context/service/database/Slice.py @@ -89,7 +89,7 @@ def slice_set(db_engine : Engine, messagebroker : MessageBroker, request : Slice slice_status = grpc_to_enum__slice_status(request.slice_status.slice_status) - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) slice_endpoints_data : List[Dict] = list() for i,endpoint_id in enumerate(request.slice_endpoint_ids): @@ -222,7 +222,8 @@ def slice_unset(db_engine : Engine, messagebroker : MessageBroker, request : Sli for subslice_id in request.slice_subslice_ids } - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) + constraints = compose_constraints_data(request.slice_constraints, now, slice_uuid=slice_uuid) config_rules = compose_config_rules_data(request.slice_config.config_rules, now, slice_uuid=slice_uuid) diff --git a/src/context/service/database/Topology.py b/src/context/service/database/Topology.py index ba2649c69abb025988e576f4978479bc05a5d657..1ee5d16422e94d2b9a2ed4dede461a14e97434ec 100644 --- a/src/context/service/database/Topology.py +++ b/src/context/service/database/Topology.py @@ -134,7 +134,8 @@ def topology_set(db_engine : Engine, messagebroker : MessageBroker, request : To MSG += 'Items in field "link_ids" ignored. This field is used for retrieval purposes only.' LOGGER.warning(MSG) - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.timezone.utc) + topology_data = [{ 'context_uuid' : context_uuid, 'topology_uuid': topology_uuid, diff --git a/src/context/service/database/models/LinkModel.py b/src/context/service/database/models/LinkModel.py index 423e39832201cc19d98a106b136fb545f4e24b7d..1bfa532d843bce4e078ef087fa4659b6fec75ceb 100644 --- a/src/context/service/database/models/LinkModel.py +++ b/src/context/service/database/models/LinkModel.py @@ -13,17 +13,22 @@ # limitations under the License. import operator -from sqlalchemy import CheckConstraint, Column, DateTime, Float, ForeignKey, Integer, String +from sqlalchemy import ( + CheckConstraint, Column, DateTime, Enum, Float, ForeignKey, Integer, String +) from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import relationship from typing import Dict +from common.proto.context_pb2 import LinkTypeEnum from ._Base import _Base +from .enums.LinkType import ORM_LinkTypeEnum class LinkModel(_Base): __tablename__ = 'link' link_uuid = Column(UUID(as_uuid=False), primary_key=True) link_name = Column(String, nullable=False) + link_type = Column(Enum(ORM_LinkTypeEnum), nullable=False) total_capacity_gbps = Column(Float, nullable=True) used_capacity_gbps = Column(Float, nullable=True) created_at = Column(DateTime, nullable=False) @@ -44,11 +49,14 @@ class LinkModel(_Base): result = { 'link_id' : self.dump_id(), 'name' : self.link_name, + 'link_type' : self.link_type.value, 'link_endpoint_ids': [ link_endpoint.endpoint.dump_id() for link_endpoint in sorted(self.link_endpoints, key=operator.attrgetter('position')) ], } + if self.link_type is None: + self.link_type = LinkTypeEnum.LINKTYPE_UNKNOWN if self.total_capacity_gbps is not None: attributes : Dict = result.setdefault('attributes', dict()) attributes.setdefault('total_capacity_gbps', self.total_capacity_gbps)