]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: move get_lvs_from_path() to api/lvm.py 38368/head
authorRishabh Dave <ridave@redhat.com>
Mon, 30 Nov 2020 09:40:30 +0000 (15:10 +0530)
committerRishabh Dave <ridave@redhat.com>
Wed, 21 Apr 2021 13:00:09 +0000 (18:30 +0530)
This makes this method reusable across ceph-volume codebase.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/ceph-volume/ceph_volume/api/lvm.py
src/ceph-volume/ceph_volume/devices/lvm/listing.py

index 90f301f018dd889d34c9648200b0776ee41fccb9..67d7a8d1c8bd87abf62bea79ac4e6a3ccd55672d 100644 (file)
@@ -1164,3 +1164,15 @@ def get_device_lvs(device, name_prefix=''):
     lvs = _output_parser(stdout, LV_FIELDS)
     return [Volume(**lv) for lv in lvs if lv['lv_name'] and
             lv['lv_name'].startswith(name_prefix)]
+
+
+def get_lvs_from_path(devpath):
+    lvs = []
+    if os.path.isabs(devpath):
+        # we have a block device
+        lvs = get_device_lvs(devpath)
+        if not lvs:
+            # maybe this was a LV path /dev/vg_name/lv_name or /dev/mapper/
+            lvs = get_lvs(filters={'path': devpath})
+
+    return lvs
index de19790511bfe9220a7b36425e83a0f7c518dad4..44d5063ce37e09c559d4258bac5975b4f9954d1b 100644 (file)
@@ -2,7 +2,6 @@ from __future__ import print_function
 import argparse
 import json
 import logging
-import os.path
 from textwrap import dedent
 from ceph_volume import decorators
 from ceph_volume.api import lvm as api
@@ -140,22 +139,6 @@ class List(object):
         """
         return self.create_report(api.get_lvs())
 
-    def get_lvs_from_path(self, device):
-        lvs = []
-        if os.path.isabs(device):
-            # we have a block device
-            lvs = api.get_device_lvs(device)
-            if not lvs:
-                # maybe this was a LV path /dev/vg_name/lv_name or /dev/mapper/
-                lvs = api.get_lvs(filters={'path': device})
-        else:
-            # vg_name/lv_name was passed
-            vg_name, lv_name = device.split('/')
-            lvs = api.get_lvs(filters={'lv_name': lv_name,
-                                       'vg_name': vg_name})
-
-        return lvs
-
     def single_report(self, arg):
         """
         Generate a report for a single device. This can be either a logical
@@ -167,7 +150,7 @@ class List(object):
         if isinstance(arg, int) or arg.isdigit():
             lv = api.get_lvs_from_osd_id(arg)
         elif arg[0] == '/':
-            lv = self.get_lvs_from_path(arg)
+            lv = api.get_lvs_from_path(arg)
         else:
             lv = [api.get_single_lv(filters={'lv_name': arg.split('/')[1]})]