Commit 3bd88fe8 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Add support to get mdadm attribs on create

parent 1d3297d4
......@@ -15,7 +15,7 @@
"""Support class for mdadm."""
from typing import List
from typing import Dict, List
from idmslinux_installer.util.asyncsubprocess import (AsyncSubprocess,
OutputCallback)
......@@ -28,8 +28,8 @@ class Mdadm:
def __init__(self, load: bool = True):
"""Initialize our class and load system partition types."""
def create(self, md_device: str, level: int, devices: List[str], output_callback: OutputCallback = None):
"""Create RAID device."""
def create(self, md_device: str, level: int, devices: List[str], output_callback: OutputCallback = None) -> Dict[str, str]:
"""Create a RAID device and return the details in a dict."""
# If we didn't get an output_callback, set it to our own class method
if not output_callback:
......@@ -47,6 +47,22 @@ class Mdadm:
if proc.retcode != 0:
raise OSError(f'Failed to create md device {md_device} return code {proc.retcode}')
# Grab the UUID
proc = AsyncSubprocess(['mdadm', '--detail', '--export', md_device])
result = proc.run()
# Raise an exception if we didn't get a positive response back
if proc.retcode != 0:
raise OSError(f'Failed to get mdadm attributes from device {md_device} return code {proc.retcode}')
# Strip value, then split on the =
attribs: Dict[str, str] = {}
for line in result:
key, value = line.rstrip().split('=', 1)
attribs[key] = value
return attribs
def _default_output_callback(self, line: str):
line.rstrip()
print(f'mdadm: {line}')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment