]>
Commit | Line | Data |
---|---|---|
d2e6a577 FG |
1 | from __future__ import print_function |
2 | from textwrap import dedent | |
b32b8144 | 3 | import logging |
d2e6a577 | 4 | from ceph_volume.util import system |
3a9019d9 | 5 | from ceph_volume.util.arg_validators import exclude_group_options |
b32b8144 FG |
6 | from ceph_volume import decorators, terminal |
7 | from .common import create_parser, rollback_osd | |
d2e6a577 FG |
8 | from .prepare import Prepare |
9 | from .activate import Activate | |
10 | ||
b32b8144 FG |
11 | logger = logging.getLogger(__name__) |
12 | ||
d2e6a577 FG |
13 | |
14 | class Create(object): | |
15 | ||
16 | help = 'Create a new OSD from an LVM device' | |
17 | ||
18 | def __init__(self, argv): | |
19 | self.argv = argv | |
20 | ||
21 | @decorators.needs_root | |
22 | def create(self, args): | |
23 | if not args.osd_fsid: | |
24 | args.osd_fsid = system.generate_uuid() | |
b32b8144 FG |
25 | prepare_step = Prepare([]) |
26 | prepare_step.safe_prepare(args) | |
27 | osd_id = prepare_step.osd_id | |
28 | try: | |
29 | # we try this for activate only when 'creating' an OSD, because a rollback should not | |
30 | # happen when doing normal activation. For example when starting an OSD, systemd will call | |
31 | # activate, which would never need to be rolled back. | |
32 | Activate([]).activate(args) | |
33 | except Exception: | |
28e407b8 | 34 | logger.exception('lvm activate was unable to complete, while creating the OSD') |
b32b8144 FG |
35 | logger.info('will rollback OSD ID creation') |
36 | rollback_osd(args, osd_id) | |
37 | raise | |
38 | terminal.success("ceph-volume lvm create successful for: %s" % args.data) | |
d2e6a577 FG |
39 | |
40 | def main(self): | |
41 | sub_command_help = dedent(""" | |
42 | Create an OSD by assigning an ID and FSID, registering them with the | |
43 | cluster with an ID and FSID, formatting and mounting the volume, adding | |
44 | all the metadata to the logical volumes using LVM tags, and starting | |
45 | the OSD daemon. | |
46 | ||
d2e6a577 FG |
47 | Example calls for supported scenarios: |
48 | ||
b5b8bbf5 FG |
49 | Filestore |
50 | --------- | |
d2e6a577 FG |
51 | |
52 | Existing logical volume (lv) or device: | |
53 | ||
b5b8bbf5 | 54 | ceph-volume lvm create --filestore --data {vg name/lv name} --journal /path/to/device |
d2e6a577 FG |
55 | |
56 | Or: | |
57 | ||
b5b8bbf5 | 58 | ceph-volume lvm create --filestore --data {vg name/lv name} --journal {vg name/lv name} |
d2e6a577 FG |
59 | |
60 | """) | |
61 | parser = create_parser( | |
62 | prog='ceph-volume lvm create', | |
63 | description=sub_command_help, | |
64 | ) | |
65 | if len(self.argv) == 0: | |
66 | print(sub_command_help) | |
67 | return | |
3a9019d9 | 68 | exclude_group_options(parser, groups=['filestore', 'bluestore'], argv=self.argv) |
d2e6a577 | 69 | args = parser.parse_args(self.argv) |
3efd9988 FG |
70 | # Default to bluestore here since defaulting it in add_argument may |
71 | # cause both to be True | |
b32b8144 | 72 | if not args.bluestore and not args.filestore: |
3efd9988 | 73 | args.bluestore = True |
d2e6a577 | 74 | self.create(args) |