Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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. 

14 

15 

16import logging 

17import grpc 

18 

19from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2, remote_execution_pb2_grpc 

20 

21 

22class CapabilitiesInterface: 

23 """Interface for calls the the Capabilities Service.""" 

24 

25 def __init__(self, channel): 

26 """Initialises an instance of the capabilities service. 

27 

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) 

33 

34 def get_capabilities(self, instance_name): 

35 """Returns the capabilities or the server to the user. 

36 

37 Args: 

38 instance_name (str): The name of the instance.""" 

39 

40 request = remote_execution_pb2.GetCapabilitiesRequest(instance_name=instance_name) 

41 try: 

42 return self.__stub.GetCapabilities(request) 

43 

44 except grpc.RpcError as e: 

45 self.__logger.debug(e) 

46 raise ConnectionError(e.details())