]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume inventory: add option to filter unwanted devices
authorJan Fajerski <jfajerski@suse.com>
Fri, 11 Sep 2020 14:35:00 +0000 (16:35 +0200)
committerJan Fajerski <jfajerski@suse.com>
Fri, 2 Oct 2020 08:09:51 +0000 (10:09 +0200)
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 <jfajerski@suse.com>
(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
src/ceph-volume/ceph_volume/tests/devices/lvm/test_common.py
src/ceph-volume/ceph_volume/util/device.py

index 1d821b602be18329330a800174e90ab1738074f7..f4b392e4173dd51357913831cb0568fe1e6f11bc 100644 (file)
@@ -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 <path> 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':
index c6b8a3d94550816884aab29200cb4c7bad6017c6..fe792d5ab99a2743f5e8d6b9e6de4eb258d1c075 100644 (file)
@@ -1,4 +1,3 @@
-import pytest
 from ceph_volume.devices.lvm import common
 
 
index 0fde00ccd2469cb152d1c82336be6984b32f8f20..c6888e159a21b1751dfa022f0bcd75ec7e4956e0 100644 (file)
@@ -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):
     """