]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: add two helper functions
authorGuillaume Abrioux <gabrioux@ibm.com>
Tue, 8 Aug 2023 12:06:41 +0000 (12:06 +0000)
committerGuillaume Abrioux <gabrioux@ibm.com>
Tue, 5 Sep 2023 13:23:25 +0000 (15:23 +0200)
this adds `get_lv_path_from_mapper()` and `get_mapper_from_lv_path()`
functions in api.lvm.

they will help translating either an LV path from `/dev/mapper/LV`
to the format `/dev/VG/LV` or the opposite.

Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
(cherry picked from commit c7164dfd599a1b406f9f1c870212cc0cbf08317d)

src/ceph-volume/ceph_volume/api/lvm.py

index 5277102da9b26c4b73d654756890e2cb30787ac8..9330e506382f508d2bdb39b28ee985c1fbcc5d1f 100644 (file)
@@ -6,6 +6,7 @@ set of utilities for interacting with LVM.
 import logging
 import os
 import uuid
+import re
 from itertools import repeat
 from math import floor
 from ceph_volume import process, util, conf
@@ -1210,3 +1211,39 @@ def get_lv_by_fullname(full_name):
     except ValueError:
         res_lv = None
     return res_lv
+
+def get_lv_path_from_mapper(mapper):
+    """
+    This functions translates a given mapper device under the format:
+    /dev/mapper/LV to the format /dev/VG/LV.
+    eg:
+    from:
+    /dev/mapper/ceph--c1a97e46--234c--46aa--a549--3ca1d1f356a9-osd--block--32e8e896--172e--4a38--a06a--3702598510ec
+    to:
+    /dev/ceph-c1a97e46-234c-46aa-a549-3ca1d1f356a9/osd-block-32e8e896-172e-4a38-a06a-3702598510ec
+    """
+    results = re.split(r'^\/dev\/mapper\/(.+\w)-(\w.+)', mapper)
+    results = list(filter(None, results))
+
+    if len(results) != 2:
+        return None
+
+    return f"/dev/{results[0].replace('--', '-')}/{results[1].replace('--', '-')}"
+
+def get_mapper_from_lv_path(lv_path):
+    """
+    This functions translates a given lv path under the format:
+    /dev/VG/LV to the format /dev/mapper/LV.
+    eg:
+    from:
+    /dev/ceph-c1a97e46-234c-46aa-a549-3ca1d1f356a9/osd-block-32e8e896-172e-4a38-a06a-3702598510ec
+    to:
+    /dev/mapper/ceph--c1a97e46--234c--46aa--a549--3ca1d1f356a9-osd--block--32e8e896--172e--4a38--a06a--3702598510ec
+    """
+    results = re.split(r'^\/dev\/(.+\w)-(\w.+)', lv_path)
+    results = list(filter(None, results))
+
+    if len(results) != 2:
+        return None
+
+    return f"/dev/mapper/{results[0].replace('-', '--')}/{results[1].replace('-', '--')}"