2 This file is used only by systemd units that are passing their instance suffix
3 as arguments to this script so that it can parse the suffix into arguments that
4 ``ceph-volume <sub command>`` can consume
10 from ceph_volume import log, process
11 from ceph_volume.exceptions import SuffixParsingError
14 def parse_subcommand(string):
15 subcommand = string.split('-', 1)[0]
17 raise SuffixParsingError('subcommand', string)
21 def parse_extra_data(string):
22 # get the subcommand to split on that
23 sub_command = parse_subcommand(string)
25 # the split will leave data with a dash, so remove that
26 data = string.split(sub_command)[-1]
28 raise SuffixParsingError('data', string)
29 return data.lstrip('-')
32 def parse_osd_id(string):
33 osd_id = string.split('-', 1)[0]
35 raise SuffixParsingError('OSD id', string)
38 raise SuffixParsingError('OSD id', string)
41 def parse_osd_uuid(string):
42 osd_id = '%s-' % parse_osd_id(string)
43 osd_subcommand = '-%s' % parse_subcommand(string)
45 trimmed_suffix = string.split(osd_id)[-1]
46 # now remove the sub command
47 osd_uuid = trimmed_suffix.split(osd_subcommand)[0]
49 raise SuffixParsingError('OSD uuid', string)
55 Main entry point for the ``ceph-volume-systemd`` executable. ``args`` are
56 optional for easier testing of arguments.
58 Expected input is similar to::
60 ['/path/to/ceph-volume-systemd', '<type>-<extra metadata>']
65 '/usr/bin/ceph-volume-systemd',
66 'lvm-0-8715BEB4-15C5-49DE-BA6F-401086EC7B41'
69 The first part of the argument is the only interesting bit, which contains
70 the metadata needed to proxy the call to ``ceph-volume`` itself.
72 Reusing the example, the proxy call to ``ceph-volume`` would look like::
74 ceph-volume lvm trigger 0-8715BEB4-15C5-49DE-BA6F-401086EC7B41
76 That means that ``lvm`` is used as the subcommand and it is **expected**
77 that a ``trigger`` sub-commmand will be present to make sense of the extra
81 log.setup(name='ceph-volume-systemd.log', log_path='/var/log/ceph/ceph-volume-systemd.log')
82 logger = logging.getLogger('systemd')
84 args = args if args is not None else sys.argv
88 raise RuntimeError('no arguments supplied')
89 sub_command = parse_subcommand(suffix)
90 extra_data = parse_extra_data(suffix)
91 logger.info('raw systemd input received: %s', suffix)
92 logger.info('parsed sub-command: %s, extra data: %s', sub_command, extra_data)
93 command = ['ceph-volume', sub_command, 'trigger', extra_data]
95 tries = os.environ.get('CEPH_VOLUME_SYSTEMD_TRIES', 30)
96 interval = os.environ.get('CEPH_VOLUME_SYSTEMD_INTERVAL', 5)
99 # don't log any output to the terminal, just rely on stderr/stdout
101 process.run(command, terminal_logging=False)
102 logger.info('successfully trggered activation for: %s', extra_data)
104 except RuntimeError as error:
105 logger.warning(error)
106 logger.warning('failed activating OSD, retries left: %s', tries)