Coverage for /builds/BuildGrid/buildgrid/buildgrid/client/capabilities.py: 42.86%
14 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-22 21:04 +0000
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-22 21:04 +0000
1# Copyright (C) 2018 Bloomberg LP
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# <http://www.apache.org/licenses/LICENSE-2.0>
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
16import logging
17import grpc
19from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2, remote_execution_pb2_grpc
22class CapabilitiesInterface:
23 """Interface for calls the the Capabilities Service."""
25 def __init__(self, channel):
26 """Initialises an instance of the capabilities service.
28 Args:
29 channel (grpc.Channel): A gRPC channel to the CAS endpoint.
30 """
31 self.__logger = logging.getLogger(__name__)
32 self.__stub = remote_execution_pb2_grpc.CapabilitiesStub(channel)
34 def get_capabilities(self, instance_name):
35 """Returns the capabilities or the server to the user.
37 Args:
38 instance_name (str): The name of the instance."""
40 request = remote_execution_pb2.GetCapabilitiesRequest(instance_name=instance_name)
41 try:
42 return self.__stub.GetCapabilities(request)
44 except grpc.RpcError as e:
45 self.__logger.debug(e)
46 raise ConnectionError(e.details())