|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +# you may not use this file except in compliance with the License. |
| 3 | +# You may obtain a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | + |
| 13 | +from oslo_log import log |
| 14 | + |
| 15 | +from ironic_python_agent import exceptions |
| 16 | +from ironic_python_agent import hardware |
| 17 | + |
| 18 | +LOG = log.getLogger() |
| 19 | + |
| 20 | + |
| 21 | +def _is_supported_disk(block_device): |
| 22 | + # Helper methods are outside the class, to prevent them from being called |
| 23 | + # by dispatch_to_managers. |
| 24 | + # |
| 25 | + # This method would perform checks to see if this is a disk that is |
| 26 | + # supported by this custom hardware manager. |
| 27 | + return True |
| 28 | + |
| 29 | + |
| 30 | +class ExampleDiskEraserHardwareManager(hardware.HardwareManager): |
| 31 | + """Example hardware manager to support wiping a specific model disk""" |
| 32 | + |
| 33 | + # All hardware managers have a name and a version. |
| 34 | + # Version should be bumped anytime a change is introduced. This will |
| 35 | + # signal to Ironic that if automatic node cleaning is in progress to |
| 36 | + # restart it from the beginning, to ensure consistency. The value can |
| 37 | + # be anything; it's checked for equality against previously seen |
| 38 | + # name:manager pairs. |
| 39 | + HARDWARE_MANAGER_NAME = 'ExampleDiskEraserHardwareManager' |
| 40 | + HARDWARE_MANAGER_VERSION = '1' |
| 41 | + |
| 42 | + def evaluate_hardware_support(self): |
| 43 | + """Declare level of hardware support provided. |
| 44 | +
|
| 45 | + Since this example covers a case of supporting a specific device, |
| 46 | + for disk erasure, we're going to return SERVICE_PROVIDER statically, |
| 47 | + and actually do disk detection in erase_device method. |
| 48 | +
|
| 49 | + :returns: HardwareSupport level for this manager. |
| 50 | + """ |
| 51 | + return hardware.HardwareSupport.SERVICE_PROVIDER |
| 52 | + |
| 53 | + def erase_block_device(self, node, block_device): |
| 54 | + """Erases hardware via custom utility if supported.""" |
| 55 | + if not _is_supported_disk(block_device): |
| 56 | + raise exceptions.IncompatibleHardwareMethodError( |
| 57 | + "Not supported by this manager") |
| 58 | + |
| 59 | + # Put your code here to wipe the disk. |
0 commit comments