From 833544b140b08e2ec906a529e57bacf1ae92d3cb Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Mon, 30 Nov 2020 15:10:30 +0530 Subject: [PATCH] ceph-volume: move get_lvs_from_path() to api/lvm.py This makes this method reusable across ceph-volume codebase. Signed-off-by: Rishabh Dave (cherry picked from commit 0ea399c01143673f0225b1b4a48136af75b0b6c5) --- src/ceph-volume/ceph_volume/api/lvm.py | 11 +++++++++++ .../ceph_volume/devices/lvm/listing.py | 19 +------------------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/ceph-volume/ceph_volume/api/lvm.py b/src/ceph-volume/ceph_volume/api/lvm.py index 68e3204add095..4d0262f3aee85 100644 --- a/src/ceph-volume/ceph_volume/api/lvm.py +++ b/src/ceph-volume/ceph_volume/api/lvm.py @@ -1188,3 +1188,14 @@ def get_lv_by_fullname(full_name): except ValueError: res_lv = None return res_lv + +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 diff --git a/src/ceph-volume/ceph_volume/devices/lvm/listing.py b/src/ceph-volume/ceph_volume/devices/lvm/listing.py index de19790511bfe..44d5063ce37e0 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/listing.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/listing.py @@ -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]})] -- 2.39.5