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 

16from buildgrid._exceptions import FailedPreconditionError 

17 

18 

19class HardwareInterface: 

20 """Class to configure hardware and check requirements of a :class:`Lease`. 

21 

22 In the future this could also be used to request and display 

23 the status of hardware. 

24 """ 

25 

26 def __init__(self, worker): 

27 """Initialises a new :class:`HardwareInstance`. 

28 

29 Args: 

30 worker (:class:`Worker`) 

31 """ 

32 self._worker = worker 

33 

34 def configure_hardware(self, requirements): 

35 """Configure's hardware and checks to see if the requirements can 

36 be met. 

37 

38 Args: 

39 requirements (:class:`Worker`): Requirements for the job. 

40 """ 

41 worker = self._worker 

42 

43 for config_requirement in requirements.configs: 

44 if config_requirement.key not in worker.configs: 

45 raise FailedPreconditionError("Requirements can't be met. " 

46 f"Requirements=[{config_requirement}]") 

47 

48 def get_worker_pb2(self): 

49 """Returns the protobuffer representation of the :class:`Worker`.""" 

50 return self._worker.get_pb2()