]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add --dry-run option to cephadm {enter,logs,unit} commands 64076/head
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 12 May 2025 20:09:05 +0000 (16:09 -0400)
committerAdam King <adking@redhat.com>
Sat, 21 Jun 2025 18:08:13 +0000 (14:08 -0400)
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 <jmulligan@redhat.com>
(cherry picked from commit eb0519b6f88eee2ad07adccbdca6415aded5f4b1)

src/cephadm/cephadm.py

index 6a9606f51ebb0cc604f227f70960d1c7296d41ec..5a6be98bcbd8d7e19b9bff9cee734c7878ddb2b1 100755 (executable)
@@ -3171,6 +3171,9 @@ def command_enter(ctx: CephadmContext) -> int:
         container_args=container_args,
     )
     command = c.exec_cmd(command)
+    if ctx.dry_run:
+        print(' '.join(shlex.quote(arg) for arg in command))
+        return 0
     return call_timeout(ctx, command, ctx.timeout)
 
 ##################################
@@ -3238,9 +3241,13 @@ def command_unit(ctx: CephadmContext) -> int:
     unit_name = lookup_unit_name_by_daemon_name(
         ctx, ident.fsid, ident.daemon_name
     )
+    command = ['systemctl', ctx.command, unit_name]
+    if ctx.dry_run:
+        print(' '.join(shlex.quote(arg) for arg in command))
+        return 0
     _, _, code = call(
         ctx,
-        ['systemctl', ctx.command, unit_name],
+        command,
         verbosity=CallVerbosity.VERBOSE,
         desc='',
     )
@@ -3260,6 +3267,9 @@ def command_logs(ctx: CephadmContext) -> None:
     if ctx.command:
         cmd.extend(ctx.command)
 
+    if ctx.dry_run:
+        print(' '.join(shlex.quote(arg) for arg in cmd))
+        return
     # call this directly, without our wrapper, so that we get an unmolested
     # stdout with logger prefixing.
     logger.debug('Running command: %s' % ' '.join(cmd))
@@ -4770,6 +4780,10 @@ def _get_parser():
         '--fsid',
         help='cluster FSID')
     _name_opts(parser_enter)
+    parser_enter.add_argument(
+        '--dry-run',
+        action='store_true',
+        help='print, but do not execute, the command to enter the container')
     parser_enter.add_argument(
         'command', nargs=argparse.REMAINDER,
         help='command')
@@ -4818,6 +4832,10 @@ def _get_parser():
     parser_unit.add_argument(
         '--fsid',
         help='cluster FSID')
+    parser_unit.add_argument(
+        '--dry-run',
+        action='store_true',
+        help='print, but do not execute, the unit command')
     _name_opts(parser_unit)
 
     parser_unit_install = subparsers.add_parser(
@@ -4835,6 +4853,10 @@ def _get_parser():
         '--fsid',
         help='cluster FSID')
     _name_opts(parser_logs)
+    parser_logs.add_argument(
+        '--dry-run',
+        action='store_true',
+        help='print, but do not execute, the command to show the logs')
     parser_logs.add_argument(
         'command', nargs='*',
         help='additional journalctl args')