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

Common - Context Queries:

- added get_device helper method
parent d8a8c635
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!34Context Scalability extensions using CockroachDB + Removal of Stateful database inside Device + other
......@@ -12,11 +12,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import List, Set
from common.proto.context_pb2 import ContextId, Device, Empty, Topology, TopologyId
import grpc, logging
from typing import List, Optional, Set
from common.proto.context_pb2 import ContextId, Device, DeviceId, Empty, Topology, TopologyId
from common.tools.object_factory.Topology import json_topology_id
from context.client.ContextClient import ContextClient
LOGGER = logging.getLogger(__name__)
def get_device(context_client : ContextClient, device_uuid : str, rw_copy : bool = False) -> Optional[Device]:
try:
# pylint: disable=no-member
device_id = DeviceId()
device_id.device_uuid.uuid = device_uuid
ro_device = context_client.GetDevice(device_id)
if not rw_copy: return ro_device
rw_device = Device()
rw_device.CopyFrom(ro_device)
return rw_device
except grpc.RpcError:
#LOGGER.exception('Unable to get Device({:s})'.format(str(device_uuid)))
return None
def get_existing_device_uuids(context_client : ContextClient) -> Set[str]:
existing_device_ids = context_client.ListDeviceIds(Empty())
existing_device_uuids = {device_id.device_uuid.uuid for device_id in existing_device_ids.device_ids}
......
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