1 from __future__ import print_function
3 from textwrap import dedent
4 from ceph_volume.exceptions import SuffixParsingError
5 from ceph_volume import decorators
6 from .activate import Activate
9 def parse_osd_id(string):
10 osd_id = string.split('-', 1)[0]
12 raise SuffixParsingError('OSD id', string)
15 raise SuffixParsingError('OSD id', string)
18 def parse_osd_uuid(string):
19 osd_id = '%s-' % parse_osd_id(string)
21 osd_uuid = string.split(osd_id, 1)[-1]
23 raise SuffixParsingError('OSD uuid', string)
27 class Trigger(object):
29 help = 'systemd helper to activate an OSD'
31 def __init__(self, argv):
34 @decorators.needs_root
36 sub_command_help = dedent("""
37 ** DO NOT USE DIRECTLY **
38 This tool is meant to help the systemd unit that knows about OSDs.
40 Proxy OSD activation to ``ceph-volume lvm activate`` by parsing the
41 input from systemd, detecting the UUID and ID associated with an OSD::
43 ceph-volume lvm trigger {SYSTEMD-DATA}
45 The systemd "data" is expected to be in the format of::
49 The lvs associated with the OSD need to have been prepared previously,
50 so that all needed tags and metadata exist.
52 parser = argparse.ArgumentParser(
53 prog='ceph-volume lvm trigger',
54 formatter_class=argparse.RawDescriptionHelpFormatter,
55 description=sub_command_help,
60 metavar='SYSTEMD_DATA',
62 help='Data from a systemd unit containing ID and UUID of the OSD, like asdf-lkjh-0'
64 if len(self.argv) == 0:
65 print(sub_command_help)
67 args = parser.parse_args(self.argv)
68 osd_id = parse_osd_id(args.systemd_data)
69 osd_uuid = parse_osd_uuid(args.systemd_data)
70 Activate(['--auto-detect-objectstore', osd_id, osd_uuid]).main()