Skip to content
Snippets Groups Projects
Commit ac1f6f07 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Common - Tools - Context Query:

- Added method to request device/endpoint names from a list of endpoint identifiers
parent f1fc0d45
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!44Improvement to show names instead of UUIDs for devices and endpoints in WebUI
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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.
import logging
from typing import Dict, List, Set, Tuple
from common.proto.context_pb2 import EndPointId, EndPointIdList
from context.client.ContextClient import ContextClient
LOGGER = logging.getLogger(__name__)
TYPE_DEVICE_NAMES = Dict[str, str] # device_uuid => device_name
TYPE_ENDPOINTS_DATA = Dict[str, Tuple[str, str]] # endpoint_uuid => (endpoint_name, endpoint_type)
TYPE_NAME_MAPS = Tuple[TYPE_DEVICE_NAMES, TYPE_ENDPOINTS_DATA]
def get_endpoint_names(context_client : ContextClient, endpoint_ids : List[EndPointId]) -> TYPE_NAME_MAPS:
endpoint_uuids_to_names : Set[str] = set()
endpoint_id_list = EndPointIdList()
for endpoint_id in endpoint_ids:
endpoint_uuid = endpoint_id.endpoint_uuid.uuid
if endpoint_uuid in endpoint_uuids_to_names: continue
endpoint_id_list.endpoint_ids.add().CopyFrom(endpoint_id) # pylint: disable=no-member
endpoint_uuids_to_names.add(endpoint_uuid)
endpoint_names = context_client.ListEndPointNames(endpoint_id_list)
device_names : TYPE_DEVICE_NAMES = dict()
endpoints_data : TYPE_ENDPOINTS_DATA = dict()
for endpoint_name in endpoint_names.endpoint_names:
device_uuid = endpoint_name.endpoint_id.device_id.device_uuid.uuid
device_names[device_uuid] = endpoint_name.device_name
endpoint_uuid = endpoint_name.endpoint_id.endpoint_uuid.uuid
endpoints_data[endpoint_uuid] = (endpoint_name.endpoint_name, endpoint_name.endpoint_type)
return device_names, endpoints_data
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment