diff --git a/src/webui/service/slice/routes.py b/src/webui/service/slice/routes.py index dd23e64694046ccc01e8b6df2736be35c3c6d708..f56c50f46d8c9df083a943a91704e7d16352e5a2 100644 --- a/src/webui/service/slice/routes.py +++ b/src/webui/service/slice/routes.py @@ -13,13 +13,14 @@ # limitations under the License. import json -from typing import Dict, Optional +from typing import Dict, Optional, Tuple import grpc from flask import current_app, redirect, render_template, Blueprint, flash, session, url_for +from common.method_wrappers.ServiceExceptions import InvalidArgumentsException from common.proto.context_pb2 import IsolationLevelEnum, Slice, SliceId, SliceStatusEnum, EndPointId, SliceConfig, ConfigRule from common.tools.context_queries.Context import get_context from common.tools.context_queries.EndPoint import get_endpoint_names -from common.tools.context_queries.Slice import get_slice_by_uuid +from common.tools.context_queries.Slice import get_slice_by_uuid, get_uuid_from_string from common.Constants import DEFAULT_CONTEXT_NAME from context.client.ContextClient import ContextClient from slice.client.SliceClient import SliceClient @@ -63,6 +64,25 @@ def get_ietf_data_from_config(slice_request: Slice, resource_key: str) -> Dict: return json.loads(config_rule.custom.resource_value) +def endpoint_get_uuid( + endpoint_id : EndPointId, endpoint_name : str = '', allow_random : bool = False +) -> Tuple[str, str, str]: + device_uuid = endpoint_id.device_id.device_uuid.uuid + topology_uuid = endpoint_id.topology_id.topology_uuid.uuid + raw_endpoint_uuid = endpoint_id.endpoint_uuid.uuid + + if len(raw_endpoint_uuid) > 0: + prefix_for_name = '{:s}/{:s}'.format(topology_uuid, device_uuid) + return topology_uuid, device_uuid, get_uuid_from_string(raw_endpoint_uuid, prefix_for_name=prefix_for_name) + if len(endpoint_name) > 0: + prefix_for_name = '{:s}/{:s}'.format(topology_uuid, device_uuid) + return topology_uuid, device_uuid, get_uuid_from_string(endpoint_name, prefix_for_name=prefix_for_name) + + raise InvalidArgumentsException([ + ('endpoint_id.endpoint_uuid.uuid', raw_endpoint_uuid), + ('name', endpoint_name), + ], extra_details=['At least one is required to produce a EndPoint UUID']) + def get_slice_endpoints(slice_obj: Slice) -> list[EndPointId]: ''' Get the list of endpoint ids for a slice. @@ -70,19 +90,27 @@ def get_slice_endpoints(slice_obj: Slice) -> list[EndPointId]: otherwise return the slice's list of endpoint ids. ''' try: + first_slice_endpoint_id = slice_obj.slice_endpoint_ids[0] + topology_uuid = first_slice_endpoint_id.topology_id.topology_uuid.uuid + context_uuid = slice_obj.slice_id.context_id.context_uuid.uuid running_ietf_data = get_ietf_data_from_config(slice_obj, RUNNING_RESOURCE_KEY) slice_service = running_ietf_data["network-slice-services"]["slice-service"][0] slice_sdps = slice_service["sdps"]["sdp"] list_endpoint_ids = [] for sdp in slice_sdps: endpoint = EndPointId() - endpoint.topology_id.context_id.context_uuid.uuid = DEFAULT_CONTEXT_NAME - device_uuid = sdp["node-id"] + endpoint.topology_id.context_id.context_uuid.uuid = context_uuid + endpoint.topology_id.topology_uuid.uuid = topology_uuid + device_uuid = get_uuid_from_string(sdp["node-id"]) endpoint.device_id.device_uuid.uuid = device_uuid attachment_circuits = sdp["attachment-circuits"]["attachment-circuit"] - endpoint_uuid = attachment_circuits[0]["ac-tp-id"] + endpoint_name = attachment_circuits[0]["ac-tp-id"] + endpoint.endpoint_uuid.uuid = endpoint_name + _, _, endpoint_uuid = endpoint_get_uuid(endpoint) endpoint.endpoint_uuid.uuid = endpoint_uuid list_endpoint_ids.append(endpoint) + del slice_obj.slice_endpoint_ids[:] + slice_obj.slice_endpoint_ids.extend(list_endpoint_ids) except ConfigRuleNotFoundError: # The slice does not have `running_ietf_slice` config rule, return slice's list of endpoint ids