From e29d124bb360e247afdbc6285ed3601dd45dff2e Mon Sep 17 00:00:00 2001 From: Jan Fajerski Date: Fri, 11 Sep 2020 16:35:00 +0200 Subject: [PATCH] ceph-volume inventory: add option to filter unwanted devices Some device we never want to pass to the batch subcommand. For now this includes devices that have a partition or are mounted on the machine. One goal is to filter the root device, so it is not included on a batch command and thus would contribute to its implicit sizing calculation. Signed-off-by: Jan Fajerski (cherry picked from commit 7d168ad7bdbb6d6d5231a4ae540ab03040b49a38) - removed the lsmdisk import from src/ceph-volume/ceph_volume/util/device.py --- src/ceph-volume/ceph_volume/inventory/main.py | 15 ++++++++++++++- .../ceph_volume/tests/devices/lvm/test_common.py | 1 - src/ceph-volume/ceph_volume/util/device.py | 16 +++++++++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/ceph-volume/ceph_volume/inventory/main.py b/src/ceph-volume/ceph_volume/inventory/main.py index 1d821b602be18..f4b392e4173dd 100644 --- a/src/ceph-volume/ceph_volume/inventory/main.py +++ b/src/ceph-volume/ceph_volume/inventory/main.py @@ -31,11 +31,24 @@ class Inventory(object): default='plain', help='Output format', ) + parser.add_argument( + '--filter-for-batch', + action='store_true', + help=('Filter devices unsuitable to pass to an OSD service spec, ' + 'no effect when is passed'), + default=False, + ) self.args = parser.parse_args(self.argv) if self.args.path: self.format_report(Device(self.args.path)) else: - self.format_report(Devices()) + self.format_report(Devices(self.args.filter_for_batch)) + + def get_report(self): + if self.args.path: + return Device(self.args.path).json_report() + else: + return Devices(self.args.filter_for_batch).json_report() def format_report(self, inventory): if self.args.format == 'json': diff --git a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_common.py b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_common.py index c6b8a3d945508..fe792d5ab99a2 100644 --- a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_common.py +++ b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_common.py @@ -1,4 +1,3 @@ -import pytest from ceph_volume.devices.lvm import common diff --git a/src/ceph-volume/ceph_volume/util/device.py b/src/ceph-volume/ceph_volume/util/device.py index 0fde00ccd2469..c6888e159a21b 100644 --- a/src/ceph-volume/ceph_volume/util/device.py +++ b/src/ceph-volume/ceph_volume/util/device.py @@ -4,7 +4,7 @@ import os from functools import total_ordering from ceph_volume import sys_info, process from ceph_volume.api import lvm -from ceph_volume.util import disk +from ceph_volume.util import disk, system from ceph_volume.util.constants import ceph_disk_guids report_template = """ @@ -26,13 +26,15 @@ class Devices(object): A container for Device instances with reporting """ - def __init__(self, devices=None): + def __init__(self, devices=None, filter_for_batch=False): if not sys_info.devices: sys_info.devices = disk.get_devices() self.devices = [Device(k) for k in sys_info.devices.keys()] + if filter_for_batch: + self.devices = [d for d in self.devices if d.available_lvm_batch] - def pretty_report(self, all=True): + def pretty_report(self): output = [ report_template.format( dev='Device Path', @@ -480,6 +482,14 @@ class Device(object): return len(rejected) == 0, rejected + @property + def available_lvm_batch(self): + if self.sys_api.get("partitions"): + return False + if system.device_is_mounted(self.path): + return False + return self.is_device or self.is_lv + class CephDiskDevice(object): """ -- 2.39.5