Skip to content

Commit 3a46586

Browse files
author
Jay Faulkner
committed
Add example for custom disk erasure
It's a common use case for operators to need to use vendor utilities to erase block devices. This adds an example that specifically addresses this use case. Change-Id: I20dfc37e04466dc0ded9571637818e8f6fb10216
1 parent c7aec77 commit 3a46586

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

examples/README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ Use Cases include:
1515
* Implementing erase_device() using a vendor-provided utility for a given
1616
disk model.
1717

18+
``custom-disk-erase``
19+
---------------------
20+
21+
This example manager is meant to demonstrate good patterns for developing a
22+
hardware manager to perform disk erasure using a custom vendor utility.
23+
24+
Use case:
25+
* Ensuring block devices of a specific model are erased using custom code
26+
1827
``business-logic``
1928
------------------
2029

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[metadata]
2+
name = example-disk-eraser
3+
author = Jay Faulkner
4+
author-email = jay@jvf.cc
5+
summary = IPA Example Hardware Managers: Example Disk Eraser
6+
license = Apache-2
7+
classifier =
8+
Intended Audience :: Developers
9+
Operating System :: OS Independent
10+
License :: OSI Approved :: Apache Software License
11+
Programming Language :: Python :: 3
12+
Development Status :: 4 - Beta
13+
14+
[files]
15+
modules =
16+
example_disk_eraser
17+
18+
[entry_points]
19+
ironic_python_agent.hardware_managers =
20+
example_disk_eraser = example_disk_eraser:ExampleDiskEraserHardwareManager
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python
2+
import setuptools
3+
4+
setuptools.setup(
5+
setup_requires=['pbr'],
6+
pbr=True)

0 commit comments

Comments
 (0)