]>
Commit | Line | Data |
---|---|---|
b5b8bbf5 | 1 | from ceph_volume.util import arg_validators |
b32b8144 FG |
2 | from ceph_volume import process |
3 | from ceph_volume import terminal | |
d2e6a577 FG |
4 | import argparse |
5 | ||
6 | ||
b32b8144 FG |
7 | def rollback_osd(args, osd_id=None): |
8 | """ | |
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. | |
13 | ||
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``. | |
17 | """ | |
18 | if not osd_id: | |
19 | # it means that it wasn't generated, so there is nothing to rollback here | |
20 | return | |
21 | ||
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') | |
24 | osd_name = 'osd.%s' | |
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 | |
28 | process.run([ | |
29 | 'ceph', 'osd', 'purge', | |
30 | osd_name % osd_id, | |
31 | '--yes-i-really-mean-it']) | |
32 | else: | |
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` | |
35 | process.run([ | |
36 | 'ceph', 'osd', 'destroy', | |
37 | osd_name % args.osd_id, | |
38 | '--yes-i-really-mean-it']) | |
39 | ||
40 | ||
d2e6a577 FG |
41 | def common_parser(prog, description): |
42 | """ | |
43 | Both prepare and create share the same parser, those are defined here to | |
44 | avoid duplication | |
45 | """ | |
46 | parser = argparse.ArgumentParser( | |
47 | prog=prog, | |
48 | formatter_class=argparse.RawDescriptionHelpFormatter, | |
49 | description=description, | |
50 | ) | |
51 | required_args = parser.add_argument_group('required arguments') | |
52 | parser.add_argument( | |
53 | '--journal', | |
3efd9988 | 54 | help='(filestore) A logical volume (vg_name/lv_name), or path to a device', |
d2e6a577 FG |
55 | ) |
56 | required_args.add_argument( | |
57 | '--data', | |
58 | required=True, | |
b5b8bbf5 | 59 | type=arg_validators.LVPath(), |
3efd9988 | 60 | help='OSD data path. A physical device or logical volume', |
d2e6a577 FG |
61 | ) |
62 | parser.add_argument( | |
63 | '--journal-size', | |
64 | default=5, | |
65 | metavar='GB', | |
66 | type=int, | |
3efd9988 | 67 | help='(filestore) Size (in GB) for the journal', |
d2e6a577 FG |
68 | ) |
69 | parser.add_argument( | |
70 | '--bluestore', | |
3efd9988 FG |
71 | action='store_true', |
72 | help='Use the bluestore objectstore', | |
d2e6a577 FG |
73 | ) |
74 | parser.add_argument( | |
75 | '--filestore', | |
3efd9988 FG |
76 | action='store_true', |
77 | help='Use the filestore objectstore', | |
d2e6a577 FG |
78 | ) |
79 | parser.add_argument( | |
80 | '--osd-id', | |
81 | help='Reuse an existing OSD id', | |
82 | ) | |
83 | parser.add_argument( | |
84 | '--osd-fsid', | |
85 | help='Reuse an existing OSD fsid', | |
86 | ) | |
3efd9988 FG |
87 | parser.add_argument( |
88 | '--block.db', | |
89 | dest='block_db', | |
90 | help='(bluestore) Path to bluestore block.db logical volume or device', | |
91 | ) | |
92 | parser.add_argument( | |
93 | '--block.wal', | |
94 | dest='block_wal', | |
95 | help='(bluestore) Path to bluestore block.wal logical volume or device', | |
96 | ) | |
b32b8144 FG |
97 | parser.add_argument( |
98 | '--crush-device-class', | |
99 | dest='crush_device_class', | |
100 | help='Crush device class to assign this OSD to', | |
101 | ) | |
102 | parser.add_argument( | |
103 | '--dmcrypt', | |
104 | action='store_true', | |
105 | help='Enable device encryption via dm-crypt', | |
106 | ) | |
d2e6a577 FG |
107 | # Do not parse args, so that consumers can do something before the args get |
108 | # parsed triggering argparse behavior | |
109 | return parser | |
110 | ||
111 | ||
112 | create_parser = common_parser # noqa | |
113 | prepare_parser = common_parser # noqa |