From d38e8d95a42357483689c5280c6c29888d14c58a Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 5 Jul 2018 08:28:39 -0400 Subject: [PATCH] ceph-volume lvm.auto add --yes prompt to execute strategies Signed-off-by: Alfredo Deza --- .../ceph_volume/devices/lvm/auto.py | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/ceph-volume/ceph_volume/devices/lvm/auto.py b/src/ceph-volume/ceph_volume/devices/lvm/auto.py index 58ebf83aaca23..f8a2169a87ff3 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/auto.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/auto.py @@ -1,7 +1,7 @@ import argparse from textwrap import dedent from ceph_volume import terminal, decorators -from ceph_volume.util import disk +from ceph_volume.util import disk, prompt_bool from . import strategies @@ -86,7 +86,7 @@ def get_strategy(devices, args): for strategy in strategies: backend = strategy(devices) if backend: - return backend(devices) + return backend(devices, args) class Auto(object): @@ -101,11 +101,11 @@ class Auto(object): Usage: - ceph-volume lvm auto [{device}..] + ceph-volume lvm auto [DEVICE...] Optional reporting on possible outcomes is enabled with --report - ceph-volume lvm auto --report [{device}..] + ceph-volume lvm auto --report [DEVICE...] """) def __init__(self, argv): @@ -121,7 +121,7 @@ class Auto(object): devices = sorted(all_devices.items(), key=lambda x: (x[0], x[1]['size'])) return device_formatter(devices) - def print_help(self, sub_help): + def print_help(self): return self._help.format( detected_devices=self.get_devices(), ) @@ -133,7 +133,7 @@ class Auto(object): """ system_devices = disk.get_devices() if not devices: - return system_devices + return system_devices.values() parsed_devices = [] for device in devices: try: @@ -152,14 +152,25 @@ class Auto(object): else: raise RuntimeError('report format must be "pretty" or "json"') + def execute(self, args): + strategy = get_strategy(self.get_filtered_devices(args.devices), args) + if not args.yes: + strategy.report_pretty() + terminal.info('The above OSDs would be created if the operation continues') + if not prompt_bool('do you want to proceed? (yes/no)'): + terminal.error('aborting OSD provisioning for %s' % ','.join(args.devices)) + raise SystemExit(0) + + strategy.execute() + @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)), + description=self.print_help(), ) + parser.add_argument( 'devices', metavar='DEVICES', @@ -182,12 +193,27 @@ class Auto(object): action='store_true', help='Autodetect the objectstore by inspecting the OSD', ) + parser.add_argument( + '--yes', + action='store_true', + help='Avoid prompting for confirmation when provisioning', + ) parser.add_argument( '--format', help='output format, defaults to "pretty"', default='pretty', choices=['json', 'pretty'], ) + parser.add_argument( + '--dmcrypt', + action='store_true', + help='Enable device encryption via dm-crypt', + ) + parser.add_argument( + '--crush-device-class', + dest='crush_device_class', + help='Crush device class to assign this OSD to', + ) parser.add_argument( '--no-systemd', dest='no_systemd', @@ -195,8 +221,10 @@ class Auto(object): help='Skip creating and enabling systemd units and starting OSD services', ) args = parser.parse_args(self.argv) - if len(self.argv) <= 1: + + if not args.devices: return parser.print_help() + # Default to bluestore here since defaulting it in add_argument may # cause both to be True if not args.bluestore and not args.filestore: @@ -204,3 +232,5 @@ class Auto(object): if args.report: self.report(args) + else: + self.execute(args) -- 2.39.5