]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/systemd/main.py
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', '<osd id>-<osd uuid>-<device type>']
61 ['/path/to/ceph-volume-systemd', '<type>-<extra metadata>']
66 '/usr/bin/ceph-volume-systemd',
67 'lvm-0-8715BEB4-15C5-49DE-BA6F-401086EC7B41'
70 The first part of the argument is the only interesting bit, which contains
71 the metadata needed to proxy the call to ``ceph-volume`` itself.
73 Reusing the example, the proxy call to ``ceph-volume`` would look like::
75 ceph-volume lvm trigger 0-8715BEB4-15C5-49DE-BA6F-401086EC7B41
77 That means that ``lvm`` is used as the subcommand and it is **expected**
78 that a ``trigger`` sub-commmand will be present to make sense of the extra
82 log
.setup(name
='ceph-volume-systemd.log', log_path
='/var/log/ceph/ceph-volume-systemd.log')
83 logger
= logging
.getLogger('systemd')
85 args
= args
if args
is not None else sys
.argv
89 raise RuntimeError('no arguments supplied')
90 sub_command
= parse_subcommand(suffix
)
91 extra_data
= parse_extra_data(suffix
)
92 logger
.info('raw systemd input received: %s', suffix
)
93 logger
.info('parsed sub-command: %s, extra data: %s', sub_command
, extra_data
)
94 command
= ['ceph-volume', sub_command
, 'trigger', extra_data
]
96 tries
= os
.environ
.get('CEPH_VOLUME_SYSTEMD_TRIES', 30)
97 interval
= os
.environ
.get('CEPH_VOLUME_SYSTEMD_INTERVAL', 5)
100 # don't log any output to the terminal, just rely on stderr/stdout
102 process
.run(command
, terminal_logging
=False)
103 logger
.info('successfully trggered activation for: %s', extra_data
)
105 except RuntimeError as error
:
106 logger
.warning(error
)
107 logger
.warning('failed activating OSD, retries left: %s', tries
)