diff --git a/src/context/service/database/uuids/Context.py b/src/context/service/database/uuids/Context.py index 1b798123e08fbbbf5402cbde31e44a4729b7b0e9..aa62a9f48878ac0765451809707b3ae04b717f0f 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 f257d1b41caeec7f3f87443ada74cf06ffe1f39f..3ceb39c4b478b30ece3c940b921bbb351583742b 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 e23f95238724b0a68c8b2948e0fb8ce79107da51..86423b0979655db9197497a5500ea44aebe740c6 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()