Commit 564e686d authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Context component:

- added default values to context/topology UUID generation functions
- extended endpoint UUID generation function to allow default values for ontext/topology
parent 733dd98b
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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),
+1 −1
Original line number Diff line number Diff line
@@ -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:
+5 −2
Original line number Diff line number Diff line
@@ -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()