]> git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/devices/lvm/create.py
update sources to 12.2.7
[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.
46
47 Example calls for supported scenarios:
48
49 Filestore
50 ---------
51
52 Existing logical volume (lv) or device:
53
54 ceph-volume lvm create --filestore --data {vg name/lv name} --journal /path/to/device
55
56 Or:
57
58 ceph-volume lvm create --filestore --data {vg name/lv name} --journal {vg name/lv name}
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
68 exclude_group_options(parser, groups=['filestore', 'bluestore'], argv=self.argv)
69 args = parser.parse_args(self.argv)
70 # Default to bluestore here since defaulting it in add_argument may
71 # cause both to be True
72 if not args.bluestore and not args.filestore:
73 args.bluestore = True
74 self.create(args)