]> git.proxmox.com Git - ceph.git/blame - ceph/src/ceph-volume/ceph_volume/devices/lvm/activate.py
update sources to v12.2.1
[ceph.git] / ceph / src / ceph-volume / ceph_volume / devices / lvm / activate.py
CommitLineData
d2e6a577
FG
1from __future__ import print_function
2import argparse
d2e6a577
FG
3from textwrap import dedent
4from ceph_volume import process, conf, decorators
181888fb 5from ceph_volume.util import system, disk
d2e6a577
FG
6from ceph_volume.systemd import systemctl
7from . import api
8
9
10def activate_filestore(lvs):
11 # find the osd
12 osd_lv = lvs.get(lv_tags={'ceph.type': 'data'})
13 osd_id = osd_lv.tags['ceph.osd_id']
14 # it may have a volume with a journal
15 osd_journal_lv = lvs.get(lv_tags={'ceph.type': 'journal'})
16 # TODO: add sensible error reporting if this is ever the case
17 # blow up with a KeyError if this doesn't exist
18 osd_fsid = osd_lv.tags['ceph.osd_fsid']
19 if not osd_journal_lv:
181888fb
FG
20 # must be a disk partition, by quering blkid by the uuid we are ensuring that the
21 # device path is always correct
22 osd_journal = disk.get_device_from_partuuid(osd_lv.tags['ceph.journal_uuid'])
d2e6a577 23 else:
181888fb 24 osd_journal = osd_lv.tags['ceph.journal_device']
d2e6a577
FG
25
26 if not osd_journal:
27 raise RuntimeError('unable to detect an lv or device journal for OSD %s' % osd_id)
28
29 # mount the osd
30 source = osd_lv.lv_path
31 destination = '/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id)
32 if not system.is_mounted(source, destination=destination):
33 process.run(['sudo', 'mount', '-v', source, destination])
34
181888fb
FG
35 # always re-do the symlink regardless if it exists, so that the journal
36 # device path that may have changed can be mapped correctly every time
37 destination = '/var/lib/ceph/osd/%s-%s/journal' % (conf.cluster, osd_id)
38 process.run(['sudo', 'ln', '-snf', osd_journal, destination])
d2e6a577
FG
39
40 # make sure that the journal has proper permissions
41 system.chown(osd_journal)
42
43 # enable the ceph-volume unit for this OSD
44 systemctl.enable_volume(osd_id, osd_fsid, 'lvm')
45
46 # start the OSD
47 systemctl.start_osd(osd_id)
48
49
50def activate_bluestore(lvs):
51 # TODO
52 pass
53
54
55class Activate(object):
56
57 help = 'Discover and mount the LVM device associated with an OSD ID and start the Ceph OSD'
58
59 def __init__(self, argv):
60 self.argv = argv
61
62 @decorators.needs_root
63 def activate(self, args):
64 lvs = api.Volumes()
65 # filter them down for the OSD ID and FSID we need to activate
181888fb
FG
66 if args.osd_id and args.osd_fsid:
67 lvs.filter(lv_tags={'ceph.osd_id': args.osd_id, 'ceph.osd_fsid': args.osd_fsid})
68 elif args.osd_fsid and not args.osd_id:
69 lvs.filter(lv_tags={'ceph.osd_fsid': args.osd_fsid})
d2e6a577
FG
70 if not lvs:
71 raise RuntimeError('could not find osd.%s with fsid %s' % (args.osd_id, args.osd_fsid))
72 activate_filestore(lvs)
73
74 def main(self):
75 sub_command_help = dedent("""
76 Activate OSDs by discovering them with LVM and mounting them in their
77 appropriate destination:
78
79 ceph-volume lvm activate {ID} {FSID}
80
81 The lvs associated with the OSD need to have been prepared previously,
82 so that all needed tags and metadata exist.
83
84 """)
85 parser = argparse.ArgumentParser(
86 prog='ceph-volume lvm activate',
87 formatter_class=argparse.RawDescriptionHelpFormatter,
88 description=sub_command_help,
89 )
90
91 parser.add_argument(
92 'osd_id',
93 metavar='ID',
94 nargs='?',
95 help='The ID of the OSD, usually an integer, like 0'
96 )
97 parser.add_argument(
98 'osd_fsid',
99 metavar='FSID',
100 nargs='?',
101 help='The FSID of the OSD, similar to a SHA1'
102 )
103 parser.add_argument(
104 '--bluestore',
105 action='store_true', default=False,
106 help='filestore objectstore (not yet implemented)',
107 )
108 parser.add_argument(
109 '--filestore',
110 action='store_true', default=True,
111 help='filestore objectstore (current default)',
112 )
113 if len(self.argv) == 0:
114 print(sub_command_help)
115 return
116 args = parser.parse_args(self.argv)
117 self.activate(args)