]> git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/devices/lvm/create.py
update ceph source to reef 18.2.0
[ceph.git] / ceph / src / ceph-volume / ceph_volume / devices / lvm / create.py
1 from __future__ import print_function
2 from textwrap import dedent
3 import logging
4 from ceph_volume.util import system
5 from ceph_volume.util.arg_validators import exclude_group_options
6 from ceph_volume import decorators, terminal
7 from .common import create_parser, rollback_osd
8 from .prepare import Prepare
9 from .activate import Activate
10
11 logger = logging.getLogger(__name__)
12
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()
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:
34 logger.exception('lvm activate was unable to complete, while creating the OSD')
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)
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. This is a convenience command that combines the prepare
46 and activate steps.
47
48 Encryption is supported via dmcrypt and the --dmcrypt flag.
49
50 Existing logical volume (lv):
51
52 ceph-volume lvm create --data {vg/lv}
53
54 Existing block device (a logical volume will be created):
55
56 ceph-volume lvm create --data /path/to/device
57
58 Optionally, can consume db and wal block devices, partitions or logical
59 volumes. A device will get a logical volume, partitions and existing
60 logical volumes will be used as is:
61
62 ceph-volume lvm create --data {vg/lv} --block.wal {partition} --block.db {/path/to/device}
63 """)
64 parser = create_parser(
65 prog='ceph-volume lvm create',
66 description=sub_command_help,
67 )
68 if len(self.argv) == 0:
69 print(sub_command_help)
70 return
71 exclude_group_options(parser, groups=['bluestore'], argv=self.argv)
72 args = parser.parse_args(self.argv)
73 # Default to bluestore here since defaulting it in add_argument may
74 # cause both to be True
75 if not args.bluestore:
76 args.bluestore = True
77 self.create(args)