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