Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/client/capabilities.py: 100.00%
14 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-10-04 17:48 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-10-04 17:48 +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 grpc
18from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2, remote_execution_pb2_grpc
19from buildgrid.server.logging import buildgrid_logger
21LOGGER = buildgrid_logger(__name__)
24class CapabilitiesInterface:
25 """Interface for calls the the Capabilities Service."""
27 def __init__(self, channel: grpc.Channel) -> None:
28 """Initialises an instance of the capabilities service.
30 Args:
31 channel (grpc.Channel): A gRPC channel to the CAS endpoint.
32 """
33 self.__stub = remote_execution_pb2_grpc.CapabilitiesStub(channel)
35 def get_capabilities(self, instance_name: str) -> remote_execution_pb2.ServerCapabilities:
36 """Returns the capabilities or the server to the user.
38 Args:
39 instance_name (str): The name of the instance."""
41 request = remote_execution_pb2.GetCapabilitiesRequest(instance_name=instance_name)
42 try:
43 return self.__stub.GetCapabilities(request)
45 except grpc.RpcError as e:
46 LOGGER.debug(e)
47 raise ConnectionError(e.details())