Commit dabf2dd7 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Logical Resources component:

- Rearranged internal database module
parent ebf58ce0
Loading
Loading
Loading
Loading
+3 −3
Changes for src/logical_resources/service/LogicalResourcesServicerImpl.py: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -19,12 +19,12 @@ from common.proto.logical_resources_pb2 import (
    TypedResourceList
)
from common.proto.logical_resources_pb2_grpc import LogicalResourcesServicer
from logical_resources.database import Database as InternalDatabase
from .database.Database import Database as InternalDatabase

LOGGER = logging.getLogger(__name__)
METRICS_POOL = MetricsPool('LogicalResource', 'RPC')
METRICS_POOL = MetricsPool('LogicalResources', 'RPC')

class LogicalResourceServicerImpl(LogicalResourcesServicer):
class LogicalResourcesServicerImpl(LogicalResourcesServicer):
    def __init__(self) -> None:
        LOGGER.debug('Creating Servicer...')
        self.db = InternalDatabase()
+2 −2
Changes for src/logical_resources/service/database/Database.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict, List, Optional, Tuple
from service.service.tools.object_uuid import get_uuid_from_string
from typing import Optional
from .UuidTools import get_uuid_from_string

class Database:
    def __init__(self):
+41 −0
Changes for src/logical_resources/service/database/UuidTools.py: 41 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2026 ETSI 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 typing import Optional, Union
from uuid import UUID, uuid5

# Generate a UUIDv5-like from the SHA-1 of "TFS" and no namespace to be used as the NAMESPACE for all
# the context UUIDs generated. For efficiency purposes, the UUID is hardcoded; however, it is produced
# using the following code:
#    from hashlib import sha1
#    from uuid import UUID
#    hash = sha1(bytes('TFS', 'utf-8')).digest()
#    NAMESPACE_TFS = UUID(bytes=hash[:16], version=5)
NAMESPACE_TFS = UUID('200e3a1f-2223-534f-a100-758e29c37f40')

def get_uuid_from_string(str_uuid_or_name : Union[str, UUID], prefix_for_name : Optional[str] = None) -> str:
    # if UUID given, assume it is already a valid UUID
    if isinstance(str_uuid_or_name, UUID): return str_uuid_or_name
    if not isinstance(str_uuid_or_name, str):
        MSG = 'Parameter({:s}) cannot be used to produce a UUID'
        raise Exception(MSG.format(str(repr(str_uuid_or_name))))
    try:
        # try to parse as UUID
        return str(UUID(str_uuid_or_name))
    except: # pylint: disable=bare-except
        # produce a UUID within TFS namespace from parameter
        if prefix_for_name is not None:
            str_uuid_or_name = '{:s}/{:s}'.format(prefix_for_name, str_uuid_or_name)
        return str(uuid5(NAMESPACE_TFS, str_uuid_or_name))
+13 −0
Changes for src/logical_resources/service/database/__init__.py: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2026 ETSI 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.