]> git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/devices/lvm/activate.py
7787aabd18bfd741d0d8282a0d18df7d1486f0e9
[ceph.git] / ceph / src / ceph-volume / ceph_volume / devices / lvm / activate.py
1 from __future__ import print_function
2 import argparse
3 import os
4 from textwrap import dedent
5 from ceph_volume import process, conf, decorators
6 from ceph_volume.util import system
7 from ceph_volume.systemd import systemctl
8 from . import api
9
10
11 def activate_filestore(lvs):
12 # find the osd
13 osd_lv = lvs.get(lv_tags={'ceph.type': 'data'})
14 osd_id = osd_lv.tags['ceph.osd_id']
15 # it may have a volume with a journal
16 osd_journal_lv = lvs.get(lv_tags={'ceph.type': 'journal'})
17 # TODO: add sensible error reporting if this is ever the case
18 # blow up with a KeyError if this doesn't exist
19 osd_fsid = osd_lv.tags['ceph.osd_fsid']
20 if not osd_journal_lv:
21 osd_journal = osd_lv.tags.get('ceph.journal_device')
22 else:
23 osd_journal = osd_journal.lv_path
24
25 if not osd_journal:
26 raise RuntimeError('unable to detect an lv or device journal for OSD %s' % osd_id)
27
28 # mount the osd
29 source = osd_lv.lv_path
30 destination = '/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id)
31 if not system.is_mounted(source, destination=destination):
32 process.run(['sudo', 'mount', '-v', source, destination])
33
34 # ensure that the symlink for the journal is there
35 if not os.path.exists(osd_journal):
36 source = osd_journal
37 destination = '/var/lib/ceph/osd/%s-%s/journal' % (conf.cluster, osd_id)
38 process.run(['sudo', 'ln', '-s', source, destination])
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
50 def activate_bluestore(lvs):
51 # TODO
52 pass
53
54
55 class 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
66 lvs.filter(lv_tags={'ceph.osd_id': args.osd_id, 'ceph.osd_fsid': args.osd_fsid})
67 if not lvs:
68 raise RuntimeError('could not find osd.%s with fsid %s' % (args.osd_id, args.osd_fsid))
69 activate_filestore(lvs)
70
71 def main(self):
72 sub_command_help = dedent("""
73 Activate OSDs by discovering them with LVM and mounting them in their
74 appropriate destination:
75
76 ceph-volume lvm activate {ID} {FSID}
77
78 The lvs associated with the OSD need to have been prepared previously,
79 so that all needed tags and metadata exist.
80
81 """)
82 parser = argparse.ArgumentParser(
83 prog='ceph-volume lvm activate',
84 formatter_class=argparse.RawDescriptionHelpFormatter,
85 description=sub_command_help,
86 )
87
88 parser.add_argument(
89 'osd_id',
90 metavar='ID',
91 nargs='?',
92 help='The ID of the OSD, usually an integer, like 0'
93 )
94 parser.add_argument(
95 'osd_fsid',
96 metavar='FSID',
97 nargs='?',
98 help='The FSID of the OSD, similar to a SHA1'
99 )
100 parser.add_argument(
101 '--bluestore',
102 action='store_true', default=False,
103 help='filestore objectstore (not yet implemented)',
104 )
105 parser.add_argument(
106 '--filestore',
107 action='store_true', default=True,
108 help='filestore objectstore (current default)',
109 )
110 if len(self.argv) == 0:
111 print(sub_command_help)
112 return
113 args = parser.parse_args(self.argv)
114 self.activate(args)