From 564e686d7fcaf3ac10d2ba042e7cb0cd792f9a5f Mon Sep 17 00:00:00 2001 From: gifrerenom <lluis.gifre@cttc.es> Date: Thu, 19 Jan 2023 16:31:28 +0000 Subject: [PATCH] Context component: - added default values to context/topology UUID generation functions - extended endpoint UUID generation function to allow default values for ontext/topology --- src/context/service/database/uuids/Context.py | 8 ++++++-- src/context/service/database/uuids/EndPoint.py | 2 +- src/context/service/database/uuids/Topology.py | 7 +++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/context/service/database/uuids/Context.py b/src/context/service/database/uuids/Context.py index 1b798123e..aa62a9f48 100644 --- a/src/context/service/database/uuids/Context.py +++ b/src/context/service/database/uuids/Context.py @@ -12,12 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +from common.Constants import DEFAULT_CONTEXT_NAME from common.proto.context_pb2 import ContextId from common.method_wrappers.ServiceExceptions import InvalidArgumentsException from ._Builder import get_uuid_from_string, get_uuid_random def context_get_uuid( - context_id : ContextId, context_name : str = '', allow_random : bool = False + context_id : ContextId, context_name : str = '', allow_random : bool = False, allow_default : bool = False ) -> str: context_uuid = context_id.context_uuid.uuid @@ -25,7 +26,10 @@ def context_get_uuid( return get_uuid_from_string(context_uuid) if len(context_name) > 0: return get_uuid_from_string(context_name) - if allow_random: return get_uuid_random() + if allow_default: + get_uuid_from_string(DEFAULT_CONTEXT_NAME) + if allow_random: + return get_uuid_random() raise InvalidArgumentsException([ ('context_id.context_uuid.uuid', context_uuid), diff --git a/src/context/service/database/uuids/EndPoint.py b/src/context/service/database/uuids/EndPoint.py index f257d1b41..3ceb39c4b 100644 --- a/src/context/service/database/uuids/EndPoint.py +++ b/src/context/service/database/uuids/EndPoint.py @@ -23,7 +23,7 @@ def endpoint_get_uuid( endpoint_id : EndPointId, endpoint_name : str = '', allow_random : bool = False ) -> Tuple[str, str, str]: device_uuid = device_get_uuid(endpoint_id.device_id, allow_random=False) - _,topology_uuid = topology_get_uuid(endpoint_id.topology_id, allow_random=False) + _,topology_uuid = topology_get_uuid(endpoint_id.topology_id, allow_random=False, allow_default=True) raw_endpoint_uuid = endpoint_id.endpoint_uuid.uuid if len(raw_endpoint_uuid) > 0: diff --git a/src/context/service/database/uuids/Topology.py b/src/context/service/database/uuids/Topology.py index e23f95238..86423b097 100644 --- a/src/context/service/database/uuids/Topology.py +++ b/src/context/service/database/uuids/Topology.py @@ -13,21 +13,24 @@ # limitations under the License. from typing import Tuple +from common.Constants import DEFAULT_TOPOLOGY_NAME from common.proto.context_pb2 import TopologyId from common.method_wrappers.ServiceExceptions import InvalidArgumentsException from ._Builder import get_uuid_from_string, get_uuid_random from .Context import context_get_uuid def topology_get_uuid( - topology_id : TopologyId, topology_name : str = '', allow_random : bool = False + topology_id : TopologyId, topology_name : str = '', allow_random : bool = False, allow_default : bool = False ) -> Tuple[str, str]: - context_uuid = context_get_uuid(topology_id.context_id, allow_random=False) + context_uuid = context_get_uuid(topology_id.context_id, allow_random=False, allow_default=allow_default) raw_topology_uuid = topology_id.topology_uuid.uuid if len(raw_topology_uuid) > 0: return context_uuid, get_uuid_from_string(raw_topology_uuid, prefix_for_name=context_uuid) if len(topology_name) > 0: return context_uuid, get_uuid_from_string(topology_name, prefix_for_name=context_uuid) + if allow_default: + return context_uuid, get_uuid_from_string(DEFAULT_TOPOLOGY_NAME) if allow_random: return context_uuid, get_uuid_random() -- GitLab