1 from __future__
import print_function
3 from textwrap
import dedent
4 from ceph_volume
import process
, conf
, decorators
5 from ceph_volume
.util
import system
, disk
6 from ceph_volume
.systemd
import systemctl
10 def activate_filestore(lvs
):
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
:
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'])
24 osd_journal
= osd_lv
.tags
['ceph.journal_device']
27 raise RuntimeError('unable to detect an lv or device journal for OSD %s' % osd_id
)
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
])
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
])
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 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
})
71 raise RuntimeError('could not find osd.%s with fsid %s' % (args
.osd_id
, args
.osd_fsid
))
72 activate_filestore(lvs
)
75 sub_command_help
= dedent("""
76 Activate OSDs by discovering them with LVM and mounting them in their
77 appropriate destination:
79 ceph-volume lvm activate {ID} {FSID}
81 The lvs associated with the OSD need to have been prepared previously,
82 so that all needed tags and metadata exist.
85 parser
= argparse
.ArgumentParser(
86 prog
='ceph-volume lvm activate',
87 formatter_class
=argparse
.RawDescriptionHelpFormatter
,
88 description
=sub_command_help
,
95 help='The ID of the OSD, usually an integer, like 0'
101 help='The FSID of the OSD, similar to a SHA1'
105 action
='store_true', default
=False,
106 help='filestore objectstore (not yet implemented)',
110 action
='store_true', default
=True,
111 help='filestore objectstore (current default)',
113 if len(self
.argv
) == 0:
114 print(sub_command_help
)
116 args
= parser
.parse_args(self
.argv
)