Coverage for /builds/BuildGrid/buildgrid/buildgrid/bot/hardware/interface.py: 100.00%
11 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.
16from buildgrid._exceptions import FailedPreconditionError
19class HardwareInterface:
20 """Class to configure hardware and check requirements of a :class:`Lease`.
22 In the future this could also be used to request and display
23 the status of hardware.
24 """
26 def __init__(self, worker):
27 """Initialises a new :class:`HardwareInstance`.
29 Args:
30 worker (:class:`Worker`)
31 """
32 self._worker = worker
34 def configure_hardware(self, requirements):
35 """Configure's hardware and checks to see if the requirements can
36 be met.
38 Args:
39 requirements (:class:`Worker`): Requirements for the job.
40 """
41 worker = self._worker
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}]")
48 def get_worker_pb2(self):
49 """Returns the protobuffer representation of the :class:`Worker`."""
50 return self._worker.get_pb2()