]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/ceph-volume/ceph_volume/devices/lvm/common.py
update ceph source to reef 18.2.0
[ceph.git] / ceph / src / ceph-volume / ceph_volume / devices / lvm / common.py
index 869fcf20016d74cb14e16aa31f32cc98082d8ab3..35e53181aff07021d83df92eb31d02ef5e4ed4ad 100644 (file)
@@ -1,19 +1,18 @@
-from ceph_volume.util import arg_validators
-from ceph_volume import process
+from ceph_volume.util import arg_validators, disk
+from ceph_volume import process, conf
 from ceph_volume import terminal
+from ceph_volume.devices.lvm.zap import Zap
 import argparse
 
-
 def rollback_osd(args, osd_id=None):
     """
-    When the process of creating or preparing fails, the OSD needs to be either
-    purged (ID fully removed) or destroyed (ID persists). This is important
-    because otherwise it would leave the ID around, which can cause confusion
-    if relying on the automatic (OSD.N + 1) behavior.
-
-    When the OSD id is specified in the command line explicitly (with
-    ``--osd-id``) , the the ID is then preserved with a soft removal (``ceph
-    osd destroy``), otherwise it is fully removed with ``purge``.
+    When the process of creating or preparing fails, the OSD needs to be
+    destroyed so that the ID can be reused.  This prevents from leaving the ID
+    around as "used" on the monitor, which can cause confusion if expecting
+    sequential OSD IDs.
+
+    The usage of `destroy-new` allows this to be done without requiring the
+    admin keyring (otherwise needed for destroy and purge commands)
     """
     if not osd_id:
         # it means that it wasn't generated, so there is nothing to rollback here
@@ -22,20 +21,119 @@ def rollback_osd(args, osd_id=None):
     # once here, this is an error condition that needs to be rolled back
     terminal.error('Was unable to complete a new OSD, will rollback changes')
     osd_name = 'osd.%s'
-    if args.osd_id is None:
-        terminal.error('OSD will be fully purged from the cluster, because the ID was generated')
-        # the ID wasn't passed in explicitly, so make sure it is fully removed
-        process.run([
-            'ceph', 'osd', 'purge',
-            osd_name % osd_id,
-            '--yes-i-really-mean-it'])
-    else:
-        terminal.error('OSD will be destroyed, keeping the ID because it was provided with --osd-id')
-        # the ID was passed explicitly, so allow to re-use by using `destroy`
-        process.run([
-            'ceph', 'osd', 'destroy',
-            osd_name % args.osd_id,
-            '--yes-i-really-mean-it'])
+    bootstrap_keyring = '/var/lib/ceph/bootstrap-osd/%s.keyring' % conf.cluster
+    cmd = [
+        'ceph',
+        '--cluster', conf.cluster,
+        '--name', 'client.bootstrap-osd',
+        '--keyring', bootstrap_keyring,
+        'osd', 'purge-new', osd_name % osd_id,
+        '--yes-i-really-mean-it',
+    ]
+
+    process.run(cmd)
+    Zap(['--destroy', '--osd-id', osd_id]).main()
+
+
+common_args = {
+    '--data': {
+        'help': 'OSD data path. A physical device or logical volume',
+        'required': True,
+        'type': arg_validators.ValidDataDevice(as_string=True),
+        #'default':,
+        #'type':,
+    },
+    '--data-size': {
+        'help': 'Size of data LV in case a device was passed in --data',
+        'default': '0',
+        'type': disk.Size.parse
+    },
+    '--data-slots': {
+        'help': ('Intended number of slots on data device. The new OSD gets one'
+              'of those slots or 1/nth of the available capacity'),
+        'type': int,
+        'default': 1,
+    },
+    '--osd-id': {
+        'help': 'Reuse an existing OSD id',
+        'default': None,
+        'type': arg_validators.valid_osd_id,
+    },
+    '--osd-fsid': {
+        'help': 'Reuse an existing OSD fsid',
+        'default': None,
+    },
+    '--cluster-fsid': {
+        'help': 'Specify the cluster fsid, useful when no ceph.conf is available',
+        'default': None,
+    },
+    '--crush-device-class': {
+        'dest': 'crush_device_class',
+        'help': 'Crush device class to assign this OSD to',
+        'default': "",
+    },
+    '--dmcrypt': {
+        'action': 'store_true',
+        'help': 'Enable device encryption via dm-crypt',
+    },
+    '--no-systemd': {
+        'dest': 'no_systemd',
+        'action': 'store_true',
+        'help': 'Skip creating and enabling systemd units and starting OSD services when activating',
+    },
+}
+
+bluestore_args = {
+    '--bluestore': {
+        'action': 'store_true',
+        'help': 'Use the bluestore objectstore',
+    },
+    '--block.db': {
+        'dest': 'block_db',
+        'help': 'Path to bluestore block.db logical volume or device',
+        'type': arg_validators.ValidDevice(as_string=True),
+    },
+    '--block.db-size': {
+        'dest': 'block_db_size',
+        'help': 'Size of block.db LV in case device was passed in --block.db',
+        'default': '0',
+        'type': disk.Size.parse
+    },
+    '--block.db-slots': {
+        'dest': 'block_db_slots',
+        'help': ('Intended number of slots on db device. The new OSD gets one'
+              'of those slots or 1/nth of the available capacity'),
+        'type': int,
+        'default': 1,
+    },
+    '--block.wal': {
+        'dest': 'block_wal',
+        'help': 'Path to bluestore block.wal logical volume or device',
+        'type': arg_validators.ValidDevice(as_string=True),
+    },
+    '--block.wal-size': {
+        'dest': 'block_wal_size',
+        'help': 'Size of block.wal LV in case device was passed in --block.wal',
+        'default': '0',
+        'type': disk.Size.parse
+    },
+    '--block.wal-slots': {
+        'dest': 'block_wal_slots',
+        'help': ('Intended number of slots on wal device. The new OSD gets one'
+              'of those slots or 1/nth of the available capacity'),
+        'type': int,
+        'default': 1,
+    },
+}
+
+
+def get_default_args():
+    defaults = {}
+    def format_name(name):
+        return name.strip('-').replace('-', '_').replace('.', '_')
+    for argset in (common_args, bluestore_args):
+        defaults.update({format_name(name): val.get('default', None) for name, val in argset.items()})
+    return defaults
 
 
 def common_parser(prog, description):
@@ -49,67 +147,13 @@ def common_parser(prog, description):
         description=description,
     )
 
-    required_group = parser.add_argument_group('required arguments')
-    filestore_group = parser.add_argument_group('filestore')
     bluestore_group = parser.add_argument_group('bluestore')
 
-    required_group.add_argument(
-        '--data',
-        required=True,
-        type=arg_validators.LVPath(),
-        help='OSD data path. A physical device or logical volume',
-    )
-
-    filestore_group.add_argument(
-        '--filestore',
-        action='store_true',
-        help='Use the filestore objectstore',
-    )
-
-    filestore_group.add_argument(
-        '--journal',
-        help='(REQUIRED) A logical volume (vg_name/lv_name), or path to a device',
-    )
-
-    bluestore_group.add_argument(
-        '--bluestore',
-        action='store_true',
-        help='Use the bluestore objectstore',
-    )
-
-    bluestore_group.add_argument(
-        '--block.db',
-        dest='block_db',
-        help='Path to bluestore block.db logical volume or device',
-    )
-
-    bluestore_group.add_argument(
-        '--block.wal',
-        dest='block_wal',
-        help='Path to bluestore block.wal logical volume or device',
-    )
-
-    parser.add_argument(
-        '--osd-id',
-        help='Reuse an existing OSD id',
-    )
+    for name, kwargs in common_args.items():
+        parser.add_argument(name, **kwargs)
 
-    parser.add_argument(
-        '--osd-fsid',
-        help='Reuse an existing OSD fsid',
-    )
-
-    parser.add_argument(
-        '--crush-device-class',
-        dest='crush_device_class',
-        help='Crush device class to assign this OSD to',
-    )
-
-    parser.add_argument(
-        '--dmcrypt',
-        action='store_true',
-        help='Enable device encryption via dm-crypt',
-    )
+    for name, kwargs in bluestore_args.items():
+        bluestore_group.add_argument(name, **kwargs)
 
     # Do not parse args, so that consumers can do something before the args get
     # parsed triggering argparse behavior