Skip to content

Commit eb0519b

Browse files
cephadm: add --dry-run option to cephadm {enter,logs,unit} commands
Add a --dry-run option to the cephadm enter, cephadm logs, and cephadm unit commands. Like cephadm shell --dry-run, this causes cephadm to print the command it would have run rather than running said command. This allows the user to copy and edit or otherwise hack on the output to make variations on these comands without having to teach cephadm all the possible options and switches those commands make take. For instance I can follow recent mgr logging like so: ``` $(/tmp/cephadm logs -i mgr --dry-run | sed 's/ / --since=-1s -f /') ``` Signed-off-by: John Mulligan <[email protected]>
1 parent 9149a1e commit eb0519b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/cephadm/cephadm.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3171,6 +3171,9 @@ def command_enter(ctx: CephadmContext) -> int:
31713171
container_args=container_args,
31723172
)
31733173
command = c.exec_cmd(command)
3174+
if ctx.dry_run:
3175+
print(' '.join(shlex.quote(arg) for arg in command))
3176+
return 0
31743177
return call_timeout(ctx, command, ctx.timeout)
31753178

31763179
##################################
@@ -3238,9 +3241,13 @@ def command_unit(ctx: CephadmContext) -> int:
32383241
unit_name = lookup_unit_name_by_daemon_name(
32393242
ctx, ident.fsid, ident.daemon_name
32403243
)
3244+
command = ['systemctl', ctx.command, unit_name]
3245+
if ctx.dry_run:
3246+
print(' '.join(shlex.quote(arg) for arg in command))
3247+
return 0
32413248
_, _, code = call(
32423249
ctx,
3243-
['systemctl', ctx.command, unit_name],
3250+
command,
32443251
verbosity=CallVerbosity.VERBOSE,
32453252
desc='',
32463253
)
@@ -3260,6 +3267,9 @@ def command_logs(ctx: CephadmContext) -> None:
32603267
if ctx.command:
32613268
cmd.extend(ctx.command)
32623269

3270+
if ctx.dry_run:
3271+
print(' '.join(shlex.quote(arg) for arg in cmd))
3272+
return
32633273
# call this directly, without our wrapper, so that we get an unmolested
32643274
# stdout with logger prefixing.
32653275
logger.debug('Running command: %s' % ' '.join(cmd))
@@ -4770,6 +4780,10 @@ def _get_parser():
47704780
'--fsid',
47714781
help='cluster FSID')
47724782
_name_opts(parser_enter)
4783+
parser_enter.add_argument(
4784+
'--dry-run',
4785+
action='store_true',
4786+
help='print, but do not execute, the command to enter the container')
47734787
parser_enter.add_argument(
47744788
'command', nargs=argparse.REMAINDER,
47754789
help='command')
@@ -4818,6 +4832,10 @@ def _get_parser():
48184832
parser_unit.add_argument(
48194833
'--fsid',
48204834
help='cluster FSID')
4835+
parser_unit.add_argument(
4836+
'--dry-run',
4837+
action='store_true',
4838+
help='print, but do not execute, the unit command')
48214839
_name_opts(parser_unit)
48224840

48234841
parser_unit_install = subparsers.add_parser(
@@ -4835,6 +4853,10 @@ def _get_parser():
48354853
'--fsid',
48364854
help='cluster FSID')
48374855
_name_opts(parser_logs)
4856+
parser_logs.add_argument(
4857+
'--dry-run',
4858+
action='store_true',
4859+
help='print, but do not execute, the command to show the logs')
48384860
parser_logs.add_argument(
48394861
'command', nargs='*',
48404862
help='additional journalctl args')

0 commit comments

Comments
 (0)