1 from ceph_volume
.util
import arg_validators
2 from ceph_volume
import process
3 from ceph_volume
import terminal
7 def rollback_osd(args
, osd_id
=None):
9 When the process of creating or preparing fails, the OSD needs to be either
10 purged (ID fully removed) or destroyed (ID persists). This is important
11 because otherwise it would leave the ID around, which can cause confusion
12 if relying on the automatic (OSD.N + 1) behavior.
14 When the OSD id is specified in the command line explicitly (with
15 ``--osd-id``) , the the ID is then preserved with a soft removal (``ceph
16 osd destroy``), otherwise it is fully removed with ``purge``.
19 # it means that it wasn't generated, so there is nothing to rollback here
22 # once here, this is an error condition that needs to be rolled back
23 terminal
.error('Was unable to complete a new OSD, will rollback changes')
25 if args
.osd_id
is None:
26 terminal
.error('OSD will be fully purged from the cluster, because the ID was generated')
27 # the ID wasn't passed in explicitly, so make sure it is fully removed
29 'ceph', 'osd', 'purge',
31 '--yes-i-really-mean-it'])
33 terminal
.error('OSD will be destroyed, keeping the ID because it was provided with --osd-id')
34 # the ID was passed explicitly, so allow to re-use by using `destroy`
36 'ceph', 'osd', 'destroy',
37 osd_name
% args
.osd_id
,
38 '--yes-i-really-mean-it'])
41 def common_parser(prog
, description
):
43 Both prepare and create share the same parser, those are defined here to
46 parser
= argparse
.ArgumentParser(
48 formatter_class
=argparse
.RawDescriptionHelpFormatter
,
49 description
=description
,
51 required_args
= parser
.add_argument_group('required arguments')
54 help='(filestore) A logical volume (vg_name/lv_name), or path to a device',
56 required_args
.add_argument(
59 type=arg_validators
.LVPath(),
60 help='OSD data path. A physical device or logical volume',
67 help='(filestore) Size (in GB) for the journal',
72 help='Use the bluestore objectstore',
77 help='Use the filestore objectstore',
81 help='Reuse an existing OSD id',
85 help='Reuse an existing OSD fsid',
90 help='(bluestore) Path to bluestore block.db logical volume or device',
95 help='(bluestore) Path to bluestore block.wal logical volume or device',
98 '--crush-device-class',
99 dest
='crush_device_class',
100 help='Crush device class to assign this OSD to',
105 help='Enable device encryption via dm-crypt',
107 # Do not parse args, so that consumers can do something before the args get
108 # parsed triggering argparse behavior
112 create_parser
= common_parser
# noqa
113 prepare_parser
= common_parser
# noqa