1 from __future__
import print_function
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
11 def activate_filestore(lvs
):
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')
23 osd_journal
= osd_journal
.lv_path
26 raise RuntimeError('unable to detect an lv or device journal for OSD %s' % osd_id
)
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
])
34 # ensure that the symlink for the journal is there
35 if not os
.path
.exists(osd_journal
):
37 destination
= '/var/lib/ceph/osd/%s-%s/journal' % (conf
.cluster
, osd_id
)
38 process
.run(['sudo', 'ln', '-s', source
, destination
])
40 # make sure that the journal has proper permissions
41 system
.chown(osd_journal
)
43 # enable the ceph-volume unit for this OSD
44 systemctl
.enable_volume(osd_id
, osd_fsid
, 'lvm')
47 systemctl
.start_osd(osd_id
)
50 def activate_bluestore(lvs
):
55 class Activate(object):
57 help = 'Discover and mount the LVM device associated with an OSD ID and start the Ceph OSD'
59 def __init__(self
, argv
):
62 @decorators.needs_root
63 def activate(self
, args
):
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
})
68 raise RuntimeError('could not find osd.%s with fsid %s' % (args
.osd_id
, args
.osd_fsid
))
69 activate_filestore(lvs
)
72 sub_command_help
= dedent("""
73 Activate OSDs by discovering them with LVM and mounting them in their
74 appropriate destination:
76 ceph-volume lvm activate {ID} {FSID}
78 The lvs associated with the OSD need to have been prepared previously,
79 so that all needed tags and metadata exist.
82 parser
= argparse
.ArgumentParser(
83 prog
='ceph-volume lvm activate',
84 formatter_class
=argparse
.RawDescriptionHelpFormatter
,
85 description
=sub_command_help
,
92 help='The ID of the OSD, usually an integer, like 0'
98 help='The FSID of the OSD, similar to a SHA1'
102 action
='store_true', default
=False,
103 help='filestore objectstore (not yet implemented)',
107 action
='store_true', default
=True,
108 help='filestore objectstore (current default)',
110 if len(self
.argv
) == 0:
111 print(sub_command_help
)
113 args
= parser
.parse_args(self
.argv
)