From: Alfredo Deza Date: Thu, 3 May 2018 15:05:42 +0000 (-0400) Subject: ceph-volume devices.auto initial take on auto sub-command X-Git-Tag: v12.2.8~70^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a6e014aa8fa08b345edc13bf89eea760437f8935;p=ceph.git ceph-volume devices.auto initial take on auto sub-command Signed-off-by: Alfredo Deza (cherry picked from commit e3b04c9677c273f91e0a9de35dcd68c578d124db) --- diff --git a/src/ceph-volume/ceph_volume/devices/auto/main.py b/src/ceph-volume/ceph_volume/devices/auto/main.py new file mode 100644 index 000000000000..d9b50195f74d --- /dev/null +++ b/src/ceph-volume/ceph_volume/devices/auto/main.py @@ -0,0 +1,70 @@ +import argparse +from textwrap import dedent +from ceph_volume import terminal, decorators +from ceph_volume.util import disk + + +device_list_template = """ + * {path: <25} {size: <10} {state}""" + + +def device_formatter(devices): + lines = [] + for path, details in devices: + lines.append(device_list_template.format( + path=path, size=details['human_readable_size'], + state='solid' if details['rotational'] == '0' else 'rotational') + ) + + return ''.join(lines) + + +class Auto(object): + + help = 'Auto-detect devices for multi-OSD provisioning with minimal interaction' + + _help = dedent(""" + Automatically detect devices ready for OSD provisioning based on configurable strategies. + + Detected devices: + {detected_devices} + + Current strategy: {strategy_name} + Path: {strategy_path} + + """) + + # TODO: add the reporting sub-command here (list?) + mapper = { + } + + def __init__(self, argv): + self.argv = argv + + def get_devices(self): + all_devices = disk.get_devices() + # remove devices with partitions + # XXX Should be optional when getting device info + for device, detail in all_devices.items(): + if detail.get('partitions') != {}: + del all_devices[device] + devices = sorted(all_devices.items(), key=lambda x: (x[0], x[1]['size'])) + return device_formatter(devices) + + def print_help(self, sub_help): + return self._help.format( + detected_devices=self.get_devices(), + strategy_name='default', + strategy_path='/etc/ceph/osd/strategies/default') + + @decorators.needs_root + def main(self): + terminal.dispatch(self.mapper, self.argv) + parser = argparse.ArgumentParser( + prog='ceph-volume auto', + formatter_class=argparse.RawDescriptionHelpFormatter, + description=self.print_help(terminal.subhelp(self.mapper)), + ) + parser.parse_args(self.argv) + if len(self.argv) <= 1: + return parser.print_help()