summaryrefslogtreecommitdiff
path: root/ironic_python_agent/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'ironic_python_agent/utils.py')
-rw-r--r--ironic_python_agent/utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/ironic_python_agent/utils.py b/ironic_python_agent/utils.py
index 2c71827a..0257cfb1 100644
--- a/ironic_python_agent/utils.py
+++ b/ironic_python_agent/utils.py
@@ -17,6 +17,7 @@ import errno
import glob
import io
import os
+import re
import shutil
import subprocess
import tarfile
@@ -60,6 +61,9 @@ COLLECT_LOGS_COMMANDS = {
}
+DEVICE_EXTRACTOR = re.compile(r'^(?:(.*\d)p|(.*\D))(?:\d+)$')
+
+
def execute(*cmd, **kwargs):
"""Convenience wrapper around ironic_lib's execute() method.
@@ -436,3 +440,16 @@ def get_ssl_client_options(conf):
else:
cert = None
return verify, cert
+
+
+def extract_device(part):
+ """Extract the device from a partition name or path.
+
+ :param part: the partition
+ :return: a device if success, None otherwise
+ """
+
+ m = DEVICE_EXTRACTOR.match(part)
+ if not m:
+ return None
+ return (m.group(1) or m.group(2))