From 2ebf4317b5733e0880935b970bc454709e6ce861 Mon Sep 17 00:00:00 2001 From: Andrew Schoen Date: Wed, 6 Mar 2019 16:52:33 -0600 Subject: [PATCH] ceph-volume: update `simple scan` to scan all running OSDs If no argument is passed to `ceph-volume simple scan` it will inspect any running osds and scan them if they were created by ceph-disk. Signed-off-by: Andrew Schoen (cherry picked from commit 28e454ec30f867ae1229c66d263bcd608654553f) --- .../ceph_volume/devices/simple/scan.py | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/ceph-volume/ceph_volume/devices/simple/scan.py b/src/ceph-volume/ceph_volume/devices/simple/scan.py index 5efe3d513aa1f..3e0d5395a13ba 100644 --- a/src/ceph-volume/ceph_volume/devices/simple/scan.py +++ b/src/ceph-volume/ceph_volume/devices/simple/scan.py @@ -7,6 +7,7 @@ import os from textwrap import dedent from ceph_volume import decorators, terminal, conf from ceph_volume.api import lvm +from ceph_volume.systemd import systemctl from ceph_volume.util import arg_validators, system, disk, encryption from ceph_volume.util.device import Device @@ -330,25 +331,40 @@ class Scan(object): metavar='OSD_PATH', type=arg_validators.OSDPath(), nargs='?', + default=None, help='Path to an existing OSD directory or OSD data partition' ) - if len(self.argv) == 0: - print(sub_command_help) - return - args = parser.parse_args(self.argv) - device = Device(args.osd_path) - if device.is_partition: - if device.ceph_disk.type != 'data': - label = device.ceph_disk.partlabel - msg = 'Device must be the ceph data partition, but PARTLABEL reported: "%s"' % label - raise RuntimeError(msg) + paths = [] + if args.osd_path: + paths.append(args.osd_path) + else: + osd_ids = systemctl.get_running_osd_ids() + for osd_id in osd_ids: + paths.append("/var/lib/ceph/osd/{}-{}".format( + conf.cluster, + osd_id, + )) # Capture some environment status, so that it can be reused all over self.device_mounts = system.get_mounts(devices=True) self.path_mounts = system.get_mounts(paths=True) - self.encryption_metadata = encryption.legacy_encrypted(args.osd_path) - self.is_encrypted = self.encryption_metadata['encrypted'] - self.scan(args) + for path in paths: + args.osd_path = path + device = Device(args.osd_path) + if device.is_partition: + if device.ceph_disk.type != 'data': + label = device.ceph_disk.partlabel + msg = 'Device must be the ceph data partition, but PARTLABEL reported: "%s"' % label + raise RuntimeError(msg) + + self.encryption_metadata = encryption.legacy_encrypted(args.osd_path) + self.is_encrypted = self.encryption_metadata['encrypted'] + + device = Device(self.encryption_metadata['device']) + if not device.is_ceph_disk_member: + terminal.warning("Ignoring %s because it's not a ceph-disk created osd." % path) + else: + self.scan(args) -- 2.39.5